Reputation: 175
I have the following code retrieving a tuple (string, array) on the server-side, but when I run the code I retrieve error.
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]) )
I am retrieving below error
image = image.reshape( (1, image.shape[0], image.shape[1], image.shape[2]) )
AttributeError: 'tuple' object has no attribute 'reshape'
I also used the below code to change the tuple to the array I am still retrieving error but another error type
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]) )
My data format retrieving from client
(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)
Thanks, help is highly appreciated.
Upvotes: 0
Views: 567
Reputation: 11
When recreating the second example based on the data you share looks to have shape (1,12). (The data snippet seems incomplete, please take a look at this). Therefore:
image_to_array.shape[0] = 1
image_to_array.shape[1] = 12
image_to_array.shape[2] does not exist and therefore gives you the error.
You should carefully determine the data you retrieve from your client and which format it is in. In this case I do not see 3 arrays, which is expected with image data. Either you have sent the wrong data in the snippet or you are retrieving the wrong data.
Upvotes: 1