def cleanedUpClassificationNetwork(original_network, num_categories):
 network = caffe_pb2.NetParameter()
 network.CopyFrom(original_network)
 for (i, layer) in enumerate(network.layer):
  if ('Data' in layer.type):
   assert (layer.type in ['Data', 'HDF5Data']), ('Unsupported data layer type %s' % layer.type)
  elif (layer.type == 'Input'):
   del network.layer[i]
  elif (layer.type == 'Accuracy'):
   if (layer.accuracy_param.HasField('top_k') and (layer.accuracy_param.top_k > num_categories)):
    del network.layer[i]
  elif (layer.type == 'InnerProduct'):
   if (not layer.inner_product_param.HasField('num_output')):
    layer.inner_product_param.num_output = num_categories
 return network

def cleanedUpClassificationNetwork ( original_network , num_categories ) : network = caffe_pb2 . NetParameter ( ) network . CopyFrom ( original_network ) for ( i , layer ) in enumerate ( network . layer ) : if ( 'Data' in layer . type ) : assert ( layer . type in [ 'Data' , 'HDF5Data' ] ) , ( 'Unsupported data layer type %s' % layer . type ) elif ( layer . type == 'Input' ) : del network . layer [ i ] elif ( layer . type == 'Accuracy' ) : if ( layer . accuracy_param . HasField ( 'top_k' ) and ( layer . accuracy_param . top_k > num_categories ) ) : del network . layer [ i ] elif ( layer . type == 'InnerProduct' ) : if ( not layer . inner_product_param . HasField ( 'num_output' ) ) : layer . inner_product_param . num_output = num_categories return network
perform a few cleanup routines on a classification network returns a new netparameter .