#NEWLINE# def load_caffe( model_desc , model_file ) : #NEWLINE# #INDENT# '\n    return a dict of params\n    ' #NEWLINE# param_dict = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# param_processors = get_processor ( ) #NEWLINE# with change_env ( 'GLOG_minloglevel' , '2' ) : #NEWLINE# #INDENT# import caffe #NEWLINE# caffe . set_mode_cpu ( ) #NEWLINE# net = caffe . Net ( model_desc , model_file , caffe . TEST ) #NEWLINE# #UNINDENT# layer_names = net . _layer_names #NEWLINE# blob_names = net . blobs . keys ( ) #NEWLINE# for ( layername , layer ) in zip ( layer_names , net . layers ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# prev_blob_name = blob_names [ ( blob_names . index ( layername ) - 1 ) ] #NEWLINE# prev_data_shape = net . blobs [ prev_blob_name ] . data . shape [ 1 : ] #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# prev_data_shape = None #NEWLINE# #UNINDENT# if ( layer . type in param_processors ) : #NEWLINE# #INDENT# param_dict . update ( param_processors [ layer . type ] ( layername , layer . blobs , prev_data_shape ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# assert ( len ( layer . blobs ) == 0 ) , len ( layer . blobs ) #NEWLINE# #UNINDENT# #UNINDENT# logger . info ( ( 'Model loaded from caffe. Params: ' + ' ' . join ( sorted ( param_dict . keys ( ) ) ) ) ) #NEWLINE# return param_dict