caffe: model definition: write same layer with different phase using caffe.NetSpec()

I assume you mean how to define phase when writing a prototxt using caffe.NetSpec? from caffe import layers as L, params as P, to_proto import caffe ns = caffe.NetSpec() = L.Data(name=”data”, data_param={‘source’:’/path/to/lmdb’,’batch_size’:32}, include={‘phase’:caffe.TEST}) If you want to have BOTH train and test layers in the same prototxt, what I usually do is making one … Read more

How to count total number of trainable parameters in a tensorflow model?

Loop over the shape of every variable in tf.trainable_variables(). total_parameters = 0 for variable in tf.trainable_variables(): # shape is an array of tf.Dimension shape = variable.get_shape() print(shape) print(len(shape)) variable_parameters = 1 for dim in shape: print(dim) variable_parameters *= dim.value print(variable_parameters) total_parameters += variable_parameters print(total_parameters) Update: I wrote an article to clarify the dynamic/static shapes in … Read more

What is the purpose of the add_loss function in Keras?

I’ll try to answer the original question of why model.add_loss() is being used instead of specifying a custom loss function to model.compile(loss=…). All loss functions in Keras always take two parameters y_true and y_pred. Have a look at the definition of the various standard loss functions available in Keras, they all have these two parameters. … Read more

caffe data layer example step by step

You can use a “Python” layer: a layer implemented in python to feed data into your net. (See an example for adding a type: “Python” layer here). import sys, os sys.path.insert(0, os.environ[‘CAFFE_ROOT’]+’/python’) import caffe class myInputLayer(caffe.Layer): def setup(self,bottom,top): # read parameters from `self.param_str` … def reshape(self,bottom,top): # no “bottom”s for input layer if len(bottom)>0: raise … Read more

How to calculate the number of parameters for convolutional neural network?

Let’s first look at how the number of learnable parameters is calculated for each individual type of layer you have, and then calculate the number of parameters in your example. Input layer: All the input layer does is read the input image, so there are no parameters you could learn here. Convolutional layers: Consider a … Read more