Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can implement subsample like keras in tensorflow?

What does the subsample do in this function of keras?

Convolution2D(nb_filter, nb_row, nb_col,
         subsample=subsample,
         activation=activation,
         border_mode=border_mode,
         W_regularizer=W_regularizer,
         b_regularizer=b_regularizer,
         dim_ordering=dim_ordering)(x)

How can implement this subsample in tensorflow?

like image 990
Tavakoli Avatar asked Jul 31 '16 06:07

Tavakoli


2 Answers

subsample in Keras is the same as strides in tensorflow. You can use the strides argument in the tensorflow tf.nn.conv2d() function to implement this.

Subsample / strides tells you how much to move the filter in each dimension as you perform the convolution. For instance with a stride of 1 in each direction you would shift the filter by one for each convolution and produce an output of the same size as the input (except for border padding effects). If strides was set to 2 the dimensions of the result would be half that of the original image.

like image 105
chasep255 Avatar answered Nov 16 '22 23:11

chasep255


There are different ways to do subsampling. You could do average pooling, where you take the average of a patch, or max pooling, the latter being the more popular. Use tf.nn.avg_pool() or tf.nn.max_pool(), the documentation for these functions could be found here

like image 30
jerpint Avatar answered Nov 16 '22 23:11

jerpint