Comments (7)
Hi, I'm not familiar with gocv, but I guess you just need a way to extract the raw byte representation from the gocv.Mat
type, and create the new tensor. Be careful, that you want to extract not the RGB representation, but a compressed representation (e.g. the PNG image, thus the png headers + the png content).
Anyway, I do recommend to user the TensorFlow primitives instead of mixing gocv with tfgo.
from tfgo.
Thanks. gocv
is basically the OpenCV in Go. I have the following preprocessing steps using gocv
in Go and cv2
in python. Doing these, the r_img
s in both cases are exactly the same. Are these steps reproducible using tfgo? For example, I couldn't find how to save the image to file.
img := gocv.IMRead(filename, gocv.IMReadColor)
defer img.Close()
c_img := gocv.NewMat()
defer c_img.Close()
gocv.CvtColor(img, &c_img, gocv.ColorBGRToRGB)
r_img := gocv.NewMat()
defer r_img.Close()
gocv.Resize(c_img, &r_img, image.Point{112, 112}, 0, 0, gocv.InterpolationLinear)
gocv.IMWrite("./resized.png", r_img)
and the python equivalent:
img = cv2.imread(filename)
c_img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
r_img = cv2.resize(c_img, (112, 112))
cv2.imwrite(f"./resized.png", r_img)
from tfgo.
Yes, have a look at the example code in the README.
Using the "github.com/galeone/tfgo/image" package, you can read the image, resize it, get a tensor out of it, and save it.
https://github.com/galeone/tfgo/blob/master/image/image.go
from tfgo.
Great. Thanks for the help.
from tfgo.
Using the Value()
from the galeone/tfgo/image
package, I'm getting the following error:
Cannot use 'r_img.Value()' (type tf.Output) as the type *tf.Tensor
This is how I feed the image to the model:
root := tg.NewRoot()
img := image.Read(root, filename, 3)
r_img := img.CropAndResize(image.Box{Start: image.Point{X: 0.0, Y: 0.0},
End: image.Point{X: 1.0, Y: 1.0}},
image.Size{Height: 112, Width: 112})
model := tg.LoadModel("./model_pb", []string{"serve"}, nil)
qmf_results := model.Exec([]tf.Output{
model.Op("PartitionedCall", 0),
}, map[tf.Output]*tf.Tensor{
qmf_model.Op("serving_default_input.1", 0): r_img.Value(),
})
Any idea on how to resolve this?
from tfgo.
Hey @galeone :)
Any idea about the above error?
from tfgo.
The Cannot use 'r_img.Value()' (type tf.Output) as the type *tf.Tensor
has already been discussed in #27, so closing this one.
from tfgo.
Related Issues (20)
- 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
- Reading jpg image from disk and passing as input to a pretrained model loaded from disk HOT 4
- 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
- Dark Souls level frustration with compilation project with this library HOT 1
- Discrepancy between python and go outputs HOT 2
- tfgo Object detection
- Choose output layer of model . HOT 1
- Panic when loading a keras LSTM Model HOT 2
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.