Transforming image from react.js into tensor issue

11 views
Skip to first unread message

Sergy Youbi

unread,
Jul 16, 2022, 1:59:24 AM7/16/22
to Keras-users
Hi folks, i hope ya'll doing good ! 
I've trained a cnn model in python , then I saved it as a json model (model.json) to use it later in my Node.js  server ( i want to predict in server side ).  The image that I want to predict come from React.js (req.files) , but I'm having issue (error) transforming the image into tensor. How to do it propery ?  Please see attachement to look  code image. thanks !!!!

the code:

const image = req.files.image;
const tensor = tf.browser
.fromPixels(files)
.resizeNearestNeighbor([256, 256])
.mean(2)
.toFloat()
.div(tf.scalar(255.0))
.expandDims()
.expandDims(-1);
Screen Shot 2022-07-15 at 23.05.19.png
Screen Shot 2022-07-15 at 23.05.43.png

Lance Norskog

unread,
Jul 16, 2022, 8:20:03 PM7/16/22
to Sergy Youbi, Keras-users
There is a general forum that is probably a better place to find help: https://discuss.tensorflow.org/

The error is a bad image shape, so I would look at the shape of the output of each step in the above chain.

I don't know this library, but what is the purpose of "mean(2)" ?

--
You received this message because you are subscribed to the Google Groups "Keras-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to keras-users...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/keras-users/952f4ef0-d783-4959-b6c4-ce8b146ea709n%40googlegroups.com.


--
Lance Norskog
lance....@gmail.com
Redwood City, CA
Reply all
Reply to author
Forward
0 new messages