Closed clelouch closed 2 years ago
Hi!
If you already have the image as a cppflow::tensor
you can resize it with cppflow::resize_bicubic
(defined here).
You can check the TensorFlow raw operations. Most of them should work in cppflow. The file with all of implemented functions is here.
Very rusty with c++, I have a 224x224 that I am trying to resize to 128x128. Currently I have:
auto input = cppflow::decode_jpeg(cppflow::read_file(std::string(filename)));
auto resized = cppflow::resize_bicubic(input,tensor({128,128}),true);
resized = cppflow::cast(resized, TF_UINT8, TF_FLOAT);
resized = input / 255.f;
resized = cppflow::expand_dims(input, 0);
However, I get the error:
libc++abi.dylib: terminating with uncaught exception of type std::runtime_error: input must be 4-dimensional[224,224,3]
Not sure how to turn this into a 4 dimensional array. It expects: ''images: 4-D with shape [batch, height, width, channels].''
Any help much appreciated.
How about to call expand_dims
before the resize operation?
auto input = cppflow::decode_jpeg(cppflow::read_file(std::string(filename)));
input = cppflow::expand_dims(input, 0);
auto resized = cppflow::resize_bicubic(input, tensor({128,128}),true);
resized = cppflow::cast(resized, TF_UINT8, TF_FLOAT);
resized = input / 255.f;
Awesome that compiled and ran. Now I need to figure out how to save the image to see what it looks like to make sure the resize works. Thanks!
This looks fixed.
Thanks for your great work. I implement a model, which takes a 128 * 128 image as input. However, I do not know how to resize the image. Could you please help me?