Skip to content

How to use tf.image.random_flip_left_right and tf.image.random_brightness? #628

Open
@pardont

Description

@pardont

Hi, I want to preprocess the images, flip or change brightness. I took a try but failed

  1. tf.image.random_brightness: throw System.NullReferenceException
  2. tf.image.random_flip_left_right: throw System.IndexOutOfRangeException

My Code:

    private void Test()
    {
        var tempPath = @"D:\Temp";
        string image_file = "cat.jpg";
        var file_contents = tf.io.read_file(image_file);
        var image = tf.image.decode_image(file_contents, 3);
        var init = tf.global_variables_initializer();

        using (var sess = tf.Session())
        {
            sess.run(init);

            //throw System.NullReferenceException 
            //NumSharp.NDArray nd = sess.run(tf.image.random_brightness(image, 0.3f));

            //throw System.IndexOutOfRangeException
            NumSharp.NDArray nd2 = sess.run(tf.image.random_flip_left_right(image));

            Bitmap bmp = nd2.ToBitmap();
            bmp.Save(Path.Combine(tempPath, DateTime.Now.ToString("yyyyMMddHHmmss_"), ".jpg"), ImageFormat.Jpeg);
        }
    }

Metadata

Metadata

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions