Git Product home page Git Product logo

Comments (7)

galeone avatar galeone commented on July 22, 2024

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.

modanesh avatar modanesh commented on July 22, 2024

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_imgs 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.

galeone avatar galeone commented on July 22, 2024

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.

modanesh avatar modanesh commented on July 22, 2024

Great. Thanks for the help.

from tfgo.

modanesh avatar modanesh commented on July 22, 2024

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.

modanesh avatar modanesh commented on July 22, 2024

Hey @galeone :)
Any idea about the above error?

from tfgo.

modanesh avatar modanesh commented on July 22, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.