tf 使用tfe 计算任意大小图像的面积

编程入门 行业动态 更新时间:2024-10-27 02:23:59

tf 使用tfe 计算任意大小<a href=https://www.elefans.com/category/jswz/34/1771430.html style=图像的面积"/>

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 计算任意大小图像的面积

本文发布于:2024-03-08 01:16:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1719461.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图像   大小   面积   tf   tfe

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!