1
$\begingroup$

I have a question regarding CNN. I do understand how they work on the surface. Very simply put, they are D-NN for images.

I'll use this example as a reference for this question. In the example, they are not initializing weights and biases anywhere. They are using tf.layers.conv2d() function in the example.

Let's focus only on 2 of the function's arguments:

  • filters: specify the number of filters to apply
  • kernel_size: specifies the size of each filter

Questions:

  1. We are not defining these filters. Does tensorflow define them for us or in general if I were to use this for a different set of images how does this work?

  2. Does this filter include both weights and biases? If not, then what exactly does the GradientDescentOptimizer() defined in the above example update after each training step?

I understood the code and understand how the entire process works. I also understand convolution and how it works. But, I'm trying to apply these concepts and implement my own code using tensorflow and CNN and I'm kind of stuck here.

$\endgroup$
1
  • 1
    $\begingroup$ @stephen Thank you for the edit. The question does look a lot better then what it used to. $\endgroup$
    – user43771
    Dec 27, 2017 at 0:49

1 Answer 1

0
$\begingroup$

If you do not specify them, as it is clear in the signature of the functions you are referring to, the function will use the default value for them. For instance, you can see that the default value for stride is (2, 2) which means if you don't define the value of stride the method will use the mentioned value as the default value for the stride. Consequently, if you don't specify it, it does not mean there isn't such thing. In programming this approach helps programmers not to define many different overloads of a typical function.

As the response for the second question, again, if you don't specify the initial weights, TensorFlow itself will use Glorot method for initialization. So, definitely the filters will have values called weights in order to operations like convolution, actually cross correlation, be applicable.

As a recommendation, I highly suggest you taking a look at here and here.

$\endgroup$
4
  • $\begingroup$ Yes I understand that there must be some predefined values for those convolutional filter weights. Let me go through the 2 provided links. I'll update once I do. If you look at both the conv2d() methods provided by tensorflow, they both don't let you pass a user-defined value for the filter. The other method(tr.layers.conv2d()) let's you pass a filter initializer but not the actual values. Hence my question. $\endgroup$
    – user43771
    Dec 26, 2017 at 17:36
  • $\begingroup$ @Nachiket you mean you want to initialize them yourself? $\endgroup$ Dec 26, 2017 at 17:52
  • $\begingroup$ I don't think that it would be required. I went through the documentation and the method tf.layers.conv2d() provide several ways to initialize these weights so I hope that'll solve my problem. I got a bit confused since the weights and the biases are not explicitly defined in the code. I'm hoping the 2nd link will prove to be useful. I didn't go through it. Will update once I do. Thanks! :) $\endgroup$
    – user43771
    Dec 26, 2017 at 17:57
  • $\begingroup$ Yes, that's very true! :) The 2nd link was indeed helpful. Thank you. I think I still need to read more to get a better understanding of how to use tensorflow to implement CNNs in general. Like I said I understand the theory of CNN but I'm new to tensorflow. So I guess this will take some time getting used to. $\endgroup$
    – user43771
    Dec 27, 2017 at 0:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.