0

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.

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Hi thank you very much your help is highly appreciated @TimVisser. I have updated the post and the size of the array is (1,1000) therefore I haven't posted complete data.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.