Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Question]: Tensorflow.RuntimeError : 'Attempting to capture an EagerTensor without building a function.' #1040

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Cilouche opened this issue Apr 27, 2023 · 2 comments
Labels
enhancement New feature or request tf image

Comments

@Cilouche
Copy link

Cilouche commented Apr 27, 2023

Description

Hi, I'm working on this "crop_to_bounding_box()" function in order to Crop an image to a specified bounding box.
But I get this error in "crop_to_bounding_box()" function

Tensorflow.RuntimeError: 'Attempting to capture an EagerTensor without building a function.'
any suggestion, please

the code :

var image = tf.image.decode_jpeg(tf.io.read_file(filname),1);
// Set the variable values here
//Offset variables values
var offset_height = 20;
var offset_width = 20;
// Target variables values
var target_height = 20;
var target_width = 20;
var graph = tf.Graph().as_default();
var ts = tf.image.crop_to_bounding_box(image, offset_height, offset_width, target_height, target_width);

Alternatives

No response

@AsakusaRinne
Copy link
Collaborator

Hi, this error is because the tf.image has not been updated for a long time and many implementations still stay in tf1.x. I've submit a partial fix for ir in #1043 . However with that, you need to specify the image shape yourself, which may lead to some inconvenience. Here's the example code:

        var graph = tf.Graph().as_default(); // Make sure the graph mode is on before reading the image
        var image = tf.image.decode_jpeg(tf.io.read_file("xxx"), 1);
        // Set the variable values here
        //Offset variables values
        var offset_height = 20;
        var offset_width = 20;
        // Target variables values
        var target_height = 20;
        var target_width = 20;
        image.shape = (400, 500, 1); // need to specify the image shape
        var ts = tf.image.crop_to_bounding_box(image, offset_height, offset_width, target_height, target_width);
        graph.Exit();

If you don't want to specify the image shape manually, you can read the image under eager mode first and get the shape before jumping into the code above, though that will sacrifice some performance.

I'll update the whole tf.image module next month, which will completely fix this issue. It's a work that costs time so now I can only give a quick but not so good fix for it. Thank you for reporting us this issue. :)

Besides, we'll publish a new library Tensorflow.NET.OpencvAdapter soon, which enables using Tensorflow.NET with OpencvSharp. It may also be an alternative. Besides, SharpCV may works but I'm not sure for that.

@AsakusaRinne AsakusaRinne added tf image enhancement New feature or request labels Apr 27, 2023
@Cilouche
Copy link
Author

thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request tf image
Projects
None yet
Development

No branches or pull requests

2 participants