& lt; tf。张量'serialized_test:0' shape=(?, ?, ?, ?) dtype=float32>
Image numpy array:
{'test': array([[[[ 31, 24, 14],
[ 24, 20, 11],
[ 21, 21, 19],
...,
[ 12, 23, 29],
[ 14, 25, 31],
[ 17, 28, 34]],
[[ 12, 23, 27],
[ 10, 21, 23],
[ 20, 32, 32],
...,
[ 23, 45, 56],
[ 16, 40, 50],
[ 2, 31, 39]],
[[ 6, 33, 42],
[ 0, 21, 29],
[ 5, 25, 34],
...,
[ 28, 47, 64],
[ 13, 30, 48],
[ 0, 15, 34]],
...,
[[ 29, 46, 56],
[ 50, 68, 78],
[ 29, 46, 56],
...,
[ 84, 104, 111],
[ 91, 111, 118],
[ 69, 89, 96]],
[[ 90, 110, 119],
[ 96, 116, 125],
[ 95, 115, 124],
...,
[ 70, 85, 92],
[ 81, 98, 106],
[ 86, 103, 111]],
[[100, 118, 128],
[ 71, 89, 99],
[ 62, 80, 90],
...,
[ 7, 44, 71],
[ 14, 51, 77],
[ 7, 43, 65]]],
[[[ 6, 37, 57],
[ 23, 49, 64],
[ 20, 42, 53],
...,
[ 41, 40, 36],
[ 17, 8, 3],
[ 24, 0, 0]],
[[ 28, 29, 24],
[ 19, 21, 18],
[ 20, 22, 21],
...,
[ 33, 75, 91],
[ 34, 86, 110],
[ 21, 84, 119]],
[[ 12, 81, 120],
[ 5, 77, 117],
[ 16, 85, 124],
...,
[ 74, 96, 117],
[ 74, 99, 119],
[ 51, 78, 97]],
...,
[[ 14, 22, 33],
[ 27, 36, 45],
[ 11, 20, 29],
...,
[ 56, 63, 69],
[ 74, 81, 87],
[ 50, 59, 64]],
[[ 40, 51, 55],
[ 52, 63, 67],
[ 26, 40, 41],
...,
[ 13, 33, 44],
[ 7, 25, 37],
[ 34, 50, 63]],
[[ 10, 26, 39],
[ 10, 28, 38],
[ 39, 59, 68],
...,
[ 87, 110, 126],
[ 64, 87, 103],
[ 63, 86, 102]]]], dtype=uint8)}
所需输出:
{'test': array([[[[0.12156863, 0.09411765, 0.05490196],
[0.11372549, 0.09019608, 0.05098039],
[0.09803922, 0.08235294, 0.04313725],
...,
[0.1372549 , 0.03137255, 0.01960784],
[0.18823529, 0.03529412, 0.03921569],
[0.21568627, 0.03921569, 0.05098039]],
[[0.12156863, 0.09803922, 0.05882353],
[0.10980392, 0.09019608, 0.05490196],
[0.09411765, 0.08235294, 0.04705882],
...,
[0.13333333, 0.03529412, 0.02352941],
[0.18823529, 0.04313725, 0.04705882],
[0.21960784, 0.05098039, 0.05882353]],
[[0.11764706, 0.10196078, 0.06666667],
[0.10588235, 0.09411765, 0.05882353],
[0.09019608, 0.07843137, 0.05098039],
...,
[0.1254902 , 0.03921569, 0.02745098],
[0.18823529, 0.05490196, 0.05490196],
[0.22352941, 0.06666667, 0.07058824]],
...,
[[0.06666667, 0.07058824, 0.05098039],
[0.06666667, 0.07058824, 0.05490196],
[0.06666667, 0.06666667, 0.05882353],
...,
[0.10196078, 0.03921569, 0.02745098],
[0.14117647, 0.04705882, 0.04705882],
[0.16470588, 0.05098039, 0.05882353]],
[[0.04313725, 0.04705882, 0.02745098],
[0.04313725, 0.04705882, 0.02745098],
[0.04313725, 0.04705882, 0.03137255],
...,
[0.10588235, 0.03921569, 0.03137255],
[0.14509804, 0.04705882, 0.04705882],
[0.16862745, 0.05098039, 0.05882353]],
[[0.02745098, 0.03137255, 0.01176471],
[0.02745098, 0.03137255, 0.01176471],
[0.02745098, 0.03137255, 0.01176471],
...,
[0.10588235, 0.03921569, 0.03137255],
[0.14509804, 0.04705882, 0.04705882],
[0.16862745, 0.05098039, 0.05882353]]]])}
我不知道如何做到这一点,实际上,我正试图找到图像中存在的文本对象。有一些预处理技术可以实现这一点。
任何帮助都将是非常感激的。
编辑:
图片附在这里
我的推理代码
from tensorflow.contrib import predictor
from PIL import Image
import numpy as np
a = predictor.from_saved_model('my_model') # this is a tensorflow saved model not a frozenmodel
image_np = np.array(Image.open("car_1.jpg"))
image_resized = np.resize(image_np, (2,70,130,3))
a({'test':image_resized})
图片有3个组件->高度、宽度和通道。在您的例子中,所需的高度是70,宽度是130。至于频道,你无法控制它们。那就保持原样。对你来说是3。
来到[2,70,130,3]
的第一个值,2
代表batch_size
或者表示图像的数量。在您的情况下,由于您只有1
图像,因此无法在这里获得2
。如果你有2
图像,那么你就会得到这个
from PIL import Image
import requests
import numpy as np
import cv2
# reading your image
img = Image.open(requests.get('https://i.stack.imgur.com/qf5RE.jpg', stream=True).raw)
# You need to do this
new_img = cv2.resize(np.array(img), (70,130))
new_img = new_img / 255
new_img
是期望的输出。
更新:
假设你有一个图像列表。然后你可以这样做
def reshape_images(images):
new_images = []
for image in images:
new_img = cv2.resize(np.array(img), (70,130))
new_images.append(new_img)
new_images = np.stack(new_images, axis=0)
return new_images
new_images = reshape_images([img, img])