Home > Embedded Computing > Forums > Accelerated Computing > Jetson & Embedded Systems > Jetson TX2 > View Topic

GET STARTED

GET INVOLVED

Authorization Required

Not a member? Register Now

I'm using DIGITS to train my tensorflow models, currently a LeNet network with gray[28x28] input using my own classified images.

I prepare a dataset with two labels, 0 and 1 that stands for :

- 0 => not a ball (~ 6000 images)

- 1 => a ball (~ 1000 images)

When I train it using DIGITS, I get a model with an accuracy of ~94% and a loss of 0.27.

When I classify one image using DIGITS, it classifies it well, as you can see below :

Very well, so now I want to use this model in one of my Python script. So I define the model, derived from the network.py provided with DIGITS :

Except the latest softmax, this is the same network as the one that has been trained by DIGITS.

I use this model by shaping and providing a Tensor obtained from the same JPG image as I use in DIGITS :

And I am not able to have the same results. Executing this script, I get this result :

Neither the score nor the classification are right. But I can't understand what I am doing wrong. I take a look at the DIGITS source code and I can't find significant differences with my code. Does anybody encounter this problem ?

You can download the full use case here : http://vps166675.ovh.net/digits-issue.tar.gz

Thank you in advance.

Damien.

Guess that there is something different in the image preprocessing.

Could you check if your workflow is identical to the DIGITs inference here:

https://github.com/NVIDIA/DIGITS/blob/master/digits/model/tasks/tensorflow_train.py#L513

Thanks.

The processing steps that I can identify on the DIGITS source code are :

https://github.com/NVIDIA/DIGITS/blob/master/digits/model/tasks/tensorflow_train.py#L539

This is a no-op processing, from the image point-of-view

https://github.com/NVIDIA/DIGITS/blob/master/digits/tools/tensorflow/main.py#L510

The dataloader is instantiated. It is a TFRecordsLoader :

https://github.com/NVIDIA/DIGITS/blob/master/digits/tools/tensorflow/tf_data.py#L310

The interresting parameters are :

https://github.com/NVIDIA/DIGITS/blob/master/digits/tools/tensorflow/tf_data.py#L634

So it does :

https://github.com/NVIDIA/DIGITS/blob/master/digits/tools/tensorflow/tf_data.py#L278

Then

https://github.com/NVIDIA/DIGITS/blob/master/digits/tools/tensorflow/tf_data.py#L693

It returns a FIxedLenFeature :

https://github.com/NVIDIA/DIGITS/blob/master/digits/tools/tensorflow/tf_data.py#L704

Then :

https://github.com/NVIDIA/DIGITS/blob/master/digits/tools/tensorflow/tf_data.py#L310

that does :

It adds :

https://github.com/NVIDIA/DIGITS/blob/master/digits/tools/tensorflow/tf_data.py#L334

And to finish, it creates a batch and launch it :

So there is some differences :

- The image doesn't seem to be converted to grayscale using DIGITS inference tool

- The resize is done by resize_image_with_crop_or_pad where I use a resize_bicubic

So my questions are :

- Where does the image is converted to grayscale ? Does DIGITS take only the first channel while a reshape ?

- The resize using resize_image_with_crop_or_pad only crops/pads (according to https://www.tensorflow.org/api_docs/python/tf/image/resize_image_with_crop_or_pad), but I train my model using the Squash resize transformation, so I guess that it is more a bicubic resize than a crop/pad.

I will adapt my sample to use reshape and crop_pad and give it a try, but it seems to me that it is counterintuitive. So I guess that I miss a step done by DIGITS...

The result is :

So it didn't change anything...

this image is the out image of resize_image_with_crop_or_padInstead of :

The DIGITS pre-processing steps are not really obvious to me...

Here is the control of crop function:

https://github.com/NVIDIA/DIGITS/blob/master/digits/model/tasks/tensorflow_train.py#L571

Thanks.

But what if I don't choose to crop images, but to squash them ? I can't find where DIGITS does the "squash" in the case of a "classify one image".

In the inference.py tools, I can see that the resize is done by :

https://github.com/NVIDIA/DIGITS/blob/master/digits/tools/inference.py#L131

That leads to :

https://github.com/NVIDIA/DIGITS/blob/master/digits/utils/image.py#L223

(The doc doesn't explain what is the used resize algorithm : https://docs.scipy.org/doc/scipy/reference/generated/scipy.misc.imresize.html)

But it seems that this tool is used by the REST API, not the "classify one image".

I will try with the REST API to see the result in this case.

Have you tried the REST API? If yes, does it fix this issue?

Any feedback will be appreciated.

Thanks.

I haven't had time yet to test the REST API, but I will get you involved when I will do.

In fact, I would like to install Digits outside of docker to add some logs.

Thank you.

Thanks for your feedback.

Feel free to let us know if you need help.

Thanks.

Using the REST API, I get the same result :

Here is some relevant logs from this classification :

Particularly :

Could "Loading" this mean tensor change the result ?

For '

Loading mean tensor...', it's a preprocessing step to subtract images with a given binaryproto file.Is your issue solved after applying REST API?

Thanks.

Given

- A = [[1,1,1],[0,1,0],[1,0,0]] the image I want to classify,

- B = [[1,0,0],[0,1,0],[0,0,0]] the image described by mean.binaryproto file,

The classify step of Digits does :

- a substraction C = A-B = [[0,1,1],[0,0,0],[1,0,0]]

- then feeds the C matrix as the input of the TensorFlow network

Is this what Digits actually do ? If so, I can do the same but I'm not sure to understand how it is relevant to do that to classify. In fact, I'm pretty sure to understand how it can pollute the results...

My issue is not resolved because I try to classify images with a Digits trained TensorFlow network using custom Python code (Python in a first phase, C++ will be used later) and i'm not able to do. I think that using TensorRT would resolve these problems but I really need to understand why I can't classify as Digits do before going further.

Currently I am training networks using tf-learn and I can predict results properly. But Digits adds some interesting stuff, so I will not surrender :)

You can set different mean-subtraction approach on DIGITs.

> Data Transformations > Subtract Mean

- None

- Image

- Pixel

This setting will lead to different preprocess handling.

For using TensorRT on TX2, there are two things want to share with you first:

1.Python API is not available on Jetson. You need to export Tensorflow model to UFF on x86-machine and inference it via C++ interface on Jetson.2.Currently, we don't have an interface for a TensorFlow/UFF user to set their custom layer implementation.Let us know if you need help.

Thanks.