<s> '''<STR_LIT>''' <EOL> from sets import Set <EOL> import numpy as np <EOL> from google . protobuf import text_format <EOL> from nideep . proto . proto_utils import Parser <EOL> def merge_indep_net_spec ( net_specs , suffix_fmt = '<STR_LIT>' ) : <EOL> data_tops = [ l . top for n in net_specs for l in n . layer if l . type . lower ( ) == '<STR_LIT:data>' ] <EOL> data_tops = Set ( [ item for sublist in data_tops for item in sublist ] ) <EOL> for idx , n in enumerate ( net_specs ) : <EOL> suffix = suffix_fmt % idx <EOL> throw_away = [ ] <EOL> for l in n . layer : <EOL> if l . type . lower ( ) != '<STR_LIT:data>' : <EOL> l . name += suffix <EOL> if np . prod ( [ p . lr_mult for p in l . param ] ) == <NUM_LIT:0> : <EOL> print "<STR_LIT>" <EOL> for b in list ( l . bottom ) : <EOL> l . bottom . remove ( b ) <EOL> if b not in data_tops : <EOL> l . bottom . append ( unicode ( b + suffix ) ) <EOL> else : <EOL> l . bottom . append ( unicode ( b ) ) <EOL> for b in list ( l . top ) : <EOL> l . top . remove ( b ) <EOL> if b not in data_tops : <EOL> l . top . append ( unicode ( b + suffix ) ) <EOL> else : <EOL> l . top . append ( unicode ( b ) ) <EOL> elif idx > <NUM_LIT:0> : <EOL> throw_away . append ( l ) <EOL> for l in throw_away : <EOL> n . layer . remove ( l ) <EOL> proto_str = '<STR_LIT>' <EOL> for idx , n in enumerate ( net_specs ) : <EOL> s = text_format . MessageToString ( n ) <EOL> if idx > <NUM_LIT:0> and s . startswith ( "<STR_LIT>" ) : <EOL> _ , s = s . split ( '<STR_LIT:\n>' , <NUM_LIT:1> ) <EOL> proto_str += s <EOL> return proto_str <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> fpath_net_1 = '<STR_LIT>' <EOL> fpath_net_2 = '<STR_LIT>' <EOL> n1 = Parser ( ) . from_net_params_file ( fpath_net_1 ) <EOL> n2 = Parser ( ) . from_net_params_file ( fpath_net_2 ) <EOL> n_str = merge_indep_net_spec ( [ n1 , n2 ] ) <EOL> fpath_dst = "<STR_LIT>" <EOL> with open ( fpath_dst , '<STR_LIT:w>' ) as f : <EOL> f . write ( n_str ) <EOL> import caffe <EOL> n = caffe . Net ( "<STR_LIT>" , caffe . TRAIN ) <EOL> n = caffe . Net ( "<STR_LIT>" , caffe . TEST ) <EOL> pass </s>
