Python Forum
tensorflow, How get value from Tensor
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
tensorflow, How get value from Tensor
#1
I upload the data in BatchDataset using the image_dataset_from_directory method
seed = 64
images = tf.keras.utils.image_dataset_from_directory(
    '/content/drive/MyDrive/DATA_PYTHON/Recognize_Alphabet/Recognize_Alphabet', 
    validation_split=0.2, 
    image_size=(34, 34),
    color_mode='rgb',
    interpolation='nearest',
    subset='training',
    seed=seed)
I want to invert the colors for all the images that I uploaded. To do this, I try to write a method:
def invertColor(im, b):

  sess2 = tf2.Session()
  im = sess2.run(im)

  imI = PIL.ImageOps.invert(im)
  imIN = np.asarray(imI)
  imINC = cv2.cvtColor(imIN, cv2.COLOR_BGR2RGB)
  bI = Image.fromarray(imINC, 'RGB')
  return bI
When I call the map with this invertColor method
images2 = images.map(invertColor)
I'm getting this errors:
Error:
InvalidArgumentError: in user code: File "<ipython-input-19-1f1e09851e25>", line 5, in invertColor * sess2.run(im) InvalidArgumentError: Graph execution error: Detected at node 'args_0' defined at (most recent call last): File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main "__main__", mod_spec)
How can I get the value of im element in the invertColor method? (Or how to invert colors in the BatchDataset?)
Reply
#2
I'm guessing you are using tensorflow 2.
Given the error message would refer you to https://www.roseindia.net/tensorflow/ten...-run.shtml explaining how tf 2 does not support session
Oleksnadr likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Realization of a tensor with for loops Elda46 5 2,292 May-07-2021, 03:53 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020