我刚开始使用tensorflow和python,并且稍微尝试了一下,但是无法弄清楚如何使用tf.contrib.image.rotate。例如,在tf.cast操作中,我可以将其用作张量。
也许有人能帮我弄清楚如何使用它?
Greetz
我刚开始使用tensorflow和python,并且稍微尝试了一下,但是无法弄清楚如何使用tf.contrib.image.rotate。例如,在tf.cast操作中,我可以将其用作张量。
也许有人能帮我弄清楚如何使用它?
Greetz
您正在混合两个不同的tensorflow函数。
tf.contrib.image.rotate
: 此函数用于旋转图像到任意角度。
X_img = # Your image or batch of images
degree_angle = 45 # In degrees
radian = degree_angle * math.pi / 180
tf_img = tf.contrib.image.rotate(X_img, radian)
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
rotated_img = sess.run(tf_img)
tf.cast
:用于将张量的数据类型从一种形式转换为另一种形式。以下是将数据转换成float32格式的示例:
casted_tensor = tf.cast(input_tensor, tf.float32)
对于那些仍在寻找答案的人,从TensorFlow 2.x开始,tf.contrib
已被弃用,因此tf.contrib.image.rotate
将不再起作用。
相反,您可以使用tensorflow_addons
库中的tfa.image.rotate
函数。该函数将图像逆时针旋转,并以弧度为输入接受角度。
img = ... #insert image(s) here
angle = 60 #in degrees
angle_radians = angle * math.pi / 180
rotated_img = tfa.image.rotate(img, angle_radians)
X_img
吗?尝试过:file_reader = tf.read_file(file_name, input_name) X_img = tf.image.decode_jpeg(file_reader, channels = 3, name='jpeg_reader')
但是 Python 崩溃了。 - QSpotmatplotlib.image.imread
函数来读取图像。 - Prasad