Friday 12 March 2021

Convert tf.Tensor to numpy array and than save it as image in without eager_execution

My OC is big sur for apple M1, therefore my tensorflow version is 2.4 which has been installed from official apple github repo(https://github.com/apple/tensorflow_macos). When i use code bellow, i get tensor(<tf.Tensor 'StatefulPartitionedCall:0' shape=(1, 2880, 4320, 3) dtype=float32>)

import tensorflow as tf
import tensorflow_hub as hub
from PIL import Image
import numpy as np

from tensorflow.python.compiler.mlcompute import mlcompute
from tensorflow.python.framework.ops import disable_eager_execution
disable_eager_execution()
mlcompute.set_mlc_device(device_name='gpu') # Available options are 'cpu', 'gpu', and 'any'.
tf.config.run_functions_eagerly(False)
print(tf.executing_eagerly())

image = np.asarray(Image.open('/Users/alex26/Downloads/face.jpg'))
image = tf.cast(image, tf.float32)
image = tf.expand_dims(image, 0)

model = hub.load("https://tfhub.dev/captain-pool/esrgan-tf2/1")
sr = model(image) #<tf.Tensor 'StatefulPartitionedCall:0' shape=(1, 2880, 4320, 3)dtype=float32>

How to get image from sr Tensor?



from Convert tf.Tensor to numpy array and than save it as image in without eager_execution

No comments:

Post a Comment