小编Ymk*_*mka的帖子

将 tf.Tensor 转换为 numpy 数组,然后将其另存为图像而不需要eager_execution

我的 OC 很适合苹果 M1,因此我的 tensorflow 版本是 2.4,它是从官方苹果 github 仓库(https://github.com/apple/tensorflow_macos)安装的。当我使用下面的代码时,我得到 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>
Run Code Online (Sandbox Code Playgroud)

如何从 sr Tensor …

python keras tensorflow

5
推荐指数
1
解决办法
673
查看次数

标签 统计

keras ×1

python ×1

tensorflow ×1