繁体   English   中英

如何改变图像张量的形状? 这可行吗?

[英]how to change the shape of the image tensor? is it doable?

这是我的代码

with tf.Session(config=tf_config) as sess:
    image_tensor = sess.graph.get_tensor_by_name('image_tensor:0')

    detection_boxes = sess.graph.get_tensor_by_name('detection_boxes:0')
    detection_scores = sess.graph.get_tensor_by_name('detection_scores:0')
    detection_classes = sess.graph.get_tensor_by_name('detection_classes:0')
    num_detections = sess.graph.get_tensor_by_name('num_detections:0')

    (boxes, scores, classes, num) = sess.run( [detection_boxes, detection_scores, detection_classes, num_detections],feed_dict={image_tensor: img[None, ...]})

我想在灰色框中运行对象检测以减少检测时间,为此,我需要将image_tensor的形状更改为(1,?,?,1),其形状为(1,?,?, 3)。 有可能改变形状,我问的是正确的问题吗?

如果它们具有相同的尺寸大小,则完全有可能将Tensor重塑为任何形状。

例如,您具有image_tensor形状(1,A,B,1)。

现在,您想将其重塑为(1,C,D,3)。

为此,您必须在两个不同的张量之间设置大小。

如果1 * A * B * 1和1 * C * D * 3的大小相同,则可以更改张量形状。

a = torch.Tensor(1, 3, 3, 1)

b = a.reshape(1,3,1,3)

现在张量b的形状为(1、3、1、3)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM