'Resize image in cppflow tensorflow c++
Using cppflow, I have a 224x224 jpeg that I am trying to resize to 128x128.
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].'' see documentation here.
I might be open to another method or solution if this is too unwieldy.
Solution 1:[1]
Turns out expand dims needs to be called earlier:
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 = resized / 255.f;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | YScharf |