图像的面积"/>
tf 使用tfe 计算任意大小图像的面积
原文链接: tf 使用tfe 计算任意大小图像的面积
上一篇: tf 静态图 任意大小 灰度转换 导出为pb文件
下一篇: kaggle mnist 使用 tensorRT的lenet5的pb文件
可以使用tf的 size函数计算tensor中的数据量,但是在进行gram矩阵转换时,需要使用深度信息和面积
使用tfe函数包装可以解决这个问题
在tf1.12中会在运行结束之后报错,但对运行结果并不影响
Exception ignored in: <bound method GradientTape.__del__ of <tensorflow.python.eager.backprop.GradientTape object at 0x0000026932409550>>
Traceback (most recent call last):File "C:\ProgramData\Anaconda3\envs\tf12\lib\site-packages\tensorflow\python\eager\backprop.py", line 765, in __del__
AttributeError: 'NoneType' object has no attribute 'context'
测试代码,可以拿到面积和整个数据大小的信息
import tensorflow as tf
import numpy as npx = tf.placeholder(tf.float32, (1, None, None, 3))
print(tf.size(x)) # Tensor("Size:0", shape=(), dtype=int32)print(x.get_shape()) # (1, ?, ?, 3)y = x * 2def get_area(in_x):_, h, w, _ = in_x.get_shape()# 两种写法都可以a = h * w# a = h.value * w.valuereturn aarea = tf.contrib.eager.py_func(func=get_area, inp=[y], Tout=tf.int32)with tf.Session() as sess:c, ar = sess.run([tf.size(y), area], {x: np.random.random((1, 10, 10, 3))})print(c, ar) # 300 100
更多推荐
tf 使用tfe 计算任意大小图像的面积
发布评论