【发布时间】:2020-12-01 10:16:22
【问题描述】:
我有以下代码在服务器端检索元组(字符串,数组),但是当我运行代码时,我检索到错误。
client.py
image_name, image = footage_socket.recv_jpg()
image = cv2.imdecode( np.frombuffer( image, dtype='uint8' ), -1 )
image = img_to_array(image)
image = image.reshape( (1, image.shape[0], image.shape[1], image.shape[2]) )
preds = model.predict( preprocess_input( image ) )
print(preds.shape) #(1,1000)
dest_socket.send_image('test',preds)
server.py
def main():
while True:
data=socket.recv_image()
image=tuple(x for x in data if x != 'test' )
#npimg = np.fromstring( image, dtype=np.uint8 )
image = image.reshape( (1, image.shape[0], image.shape[1], image.shape[2]) )
我正在检索以下错误
image = image.reshape( (1, image.shape[0], image.shape[1], image.shape[2]) )
AttributeError: 'tuple' object has no attribute 'reshape'
我还使用下面的代码将元组更改为数组我仍在检索错误但另一个错误类型
image_to_array=np.array(image)
image = image.reshape( (1, image_to_array.shape[0], image_to_array.shape[1],
image_to_array.shape[2]) )
我从客户端检索的数据格式
(array([[1.47521848e-06, 2.06672325e-06, 1.44596870e-05, 1.64947978e-05,
2.81127559e-05, 3.47975970e-06, 1.05807794e-05, 4.30030159e-05,
5.65078590e-05, 2.27573415e-04, 7.15208662e-05, 2.86311624e-05)
谢谢,非常感谢您的帮助。
【问题讨论】:
标签: python numpy opencv image-processing reshape