I recently started learning Tensorflow, in particular I want to use Convolutional Neural Networks for image classification. I have been looking at the android demo in the official repository, in particular this example: https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/android/src/org/tensorflow/demo/TensorFlowImageClassifier.java
On line 145, it creates a tensor with the input data of the image, as such:
inferenceInterface.feed(inputName, floatValues, 1, inputSize, inputSize, 3);
Now, I have been trying to understand what this is doing, and it ends up calling this method: Tensor.create. The thing I don't understand is why the shape of this tensor, given by the input parameters to this function (also called "dimensions"), is {1, inputSize, inputSize, 3}
. the second and third dimensions are the image width and height, and the fourth dimension is the RGB data of the image. But why does it have the first dimension as 1? Shouldn't the shape of this Tensor be {inputSize, inputSize, 3}
instead? I guess since the dimension is 1 it makes no difference, but I suppose there has to be a reason for this notation and I don't understand it.
Tensorflow works with batches of images. The model, thus, accepts a batch of images each with shape inputSize x inputSize x 3
.
The 1
is the batch size. Thus, in practice, you're feeding the network a batch with a single image that's a tensor with shape 1 x inputSize x inputSize x 3
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加