Skip to content

Unable to run to convert JPG to NDArray #629

Open
@jdluzen

Description

@jdluzen

Hello and thanks for this amazing project, I'm eagerly attempting to get something running.
I've attempted to read a JPG using the following tutorial and updated code snippet:
https://programmer.help/blogs/use-tensorflow.net-to-train-your-own-data-set-under-c.html

        private static NDArray ReadTensorFromImageFile(string file_name)
        {
            using (var graph = tf.Graph()/*.as_default()*/)
            {
                var jpg = tf.image.decode_jpeg(new IoApi().read_file(file_name));
                var casted = tf.cast(jpg, TF_DataType.TF_FLOAT);
                var dims_expander = tf.expand_dims(casted, 0);

                using (var sess = tf.Session(graph))
                    return sess.run(dims_expander);
                //return tf_with(tf.Session(graph), sess => sess.run(dims_expander));
            }
        }

As you can see, I've tried several variations of this to get it to work. It fails with a NullReferenceException because tensor.graph is null here

if (tensor.graph.Equals(this))

I could probably read an image and convert the individual pixels to an NDArray, but is there a proper way to read an image?

Metadata

Metadata

Assignees

Labels

help wantedExtra attention is needed

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions