Comments (4)
I'm glad I helped
On a side note, I usually recommend also exporting the pre-processing steps inside the SavedModel.
This forces you to define everything using pure TensorFlow functions (e.g. tf.image.resize
and not pillow stuff) that's the only way to have the very same behavior in Python and in other languages. For example, the pillow resize produces a completely different representation (the pixel values!) of the OpenCV resize, and both produce a different value from the tf.image.resize
method. Portability is possible only by writing pure TensorFlow programs - otherwise, you end up in a rabbit hole I don't recommend (at work we analyzed thing thing and wrote an article about it https://blog.zuru.tech/blog/the-dangers-behind-image-resizing)
from tfgo.
Hi @alimoeeny
The image.Read*
functions automatically do these things:
- Read the file
- Decode using the correct codec (jpeg,png,gif, ...). Create a
H,W,D
tensor - Add the batch dimension. Create a
1, H, W, D
tensor. - Convert the image from dtype
uint8
to dtypefloat32
- Scales the image in the
[0,1]
range.
Are you sure your python code is doing the same preprocessing the Read
function is doing?
Moreover I guess the line batch := tg.Batchify(root, []tf.Output{img.Value()})
can be removed since img
should already be a tensor with a batch dimension of 1.
For answering your questions:
- I suggest first trying with Python code. Once you have your SavedModel, try to import it with tf.saved_model.load, and feed the model in the same way you'd do it in Go. You can specify with
tf.device
a context manager for the execution of the loaded model, and make it work on your CPU, to simulate what will happen by default in Go. I'd just print out the numbers (e.g the predictions or whatever the output is).
I do the same thing in Go and verify that I can get the same numbers. - "serve" is the default tag contained in an exported SavedModel. You can export the saved model with
saved_model_cli
(via cli) to analyze its content. A saved model can have multiple tags - by default, there's a single tag "serve" that contains your model. This tag can be used for versioning the model or for having multipel version of the same model inside the SavedModel (very rare scenario). You can find more info on the doc
from tfgo.
Thank you very much @galeone for you VERY FAST response.
I think you identified the problem.
In python I don't "Scale the image in the [0,1]
range" before passing it to the model. (if I am not mistaken the model I am working with has a preprocessing stage that normalizes the image and scales it and all.
- I modified the python code to normalize the image to
[0,1]
and got an answer close to what I get on the go side. - I modified the
tfgo
code to scale to[0,255]
range but the answer was NOT close to the python's original output.
I think I am going to train a simple model with scaled inputs and see if I can get the same answer on both python and tfgo side.
from tfgo.
Thank you very much, I am going to close this issue then :)
from tfgo.
Related Issues (20)
- tf.Variable support HOT 1
- windows installation error HOT 6
- loading model HOT 2
- cc1.exe: sorry, unimplemented: 64-bit mode not compiled in HOT 1
- Error: W tensorflow/core/framework/op_kernel.cc:1745] OP_REQUIRES failed at lookup_table_op.cc:929 : FAILED_PRECONDITION: Table not initialized. HOT 1
- SparseTensor support HOT 2
- Failed to go get tfgo HOT 3
- tensor example support HOT 6
- Potential memory leak on reloading model HOT 8
- libtensorflow.so: .dynsym local symbol at index 3 (>= sh_info of 3) HOT 2
- Matching between output tensor name and prediction HOT 7
- Thread safety HOT 2
- Panic vs Error HOT 2
- Error building "Getting Started" example: rebuild TensorFlow with the appropriate compiler flags HOT 5
- Can I use tfgo for tensorflow 2.11.x? HOT 2
- Convert opencv's `mat` to tfgo's `tensor` HOT 7
- Dark Souls level frustration with compilation project with this library HOT 1
- Discrepancy between python and go outputs HOT 2
- tfgo Object detection
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tfgo.