show-attend-and-tell icon indicating copy to clipboard operation
show-attend-and-tell copied to clipboard

TyperError with prepro.py, "float() argument must be a string or number, not 'map' "

Open alexandercameronh opened this issue 7 years ago • 2 comments

Hi there,

While running prepro.py, I have the following error in regards to this block of code:

            for start, end in zip(range(0, n_examples, batch_size),
                                  range(batch_size, n_examples + batch_size, batch_size)):
                image_batch_file = image_path[start:end]
                image_batch = np.array(map(lambda x: ndimage.imread(x, mode='RGB'), image_batch_file)).astype(
                    np.float32)
                feats = sess.run(vggnet.features, feed_dict={vggnet.images: image_batch})
                all_feats[start:end, :] = feats
                print ("Processed {} {}  features..".format(end, split))

Error traceback:

Traceback (most recent call last):
  File "prepro.py", line 212, in <module>
    main()
  File "prepro.py", line 201, in main
    np.float32)
TypeError: float() argument must be a string or a number, not 'map'

I am running all the code using Python 3.5.x and TensorFlow 1.2.1. I have tried to update most of the code in order for this to run problem-free.

Any thoughts on how I can fix this? I am assuming this may be an error since I am using a more recent version of Python + TF. Thanks!

alexandercameronh avatar Oct 30 '17 20:10 alexandercameronh

Change the line : image_batch = np.array(map(lambda x: ndimage.imread(x, mode='RGB'), image_batch_file)).astype(np.float32) to image_batch = np.array(list(map(lambda x: ndimage.imread(x, mode='RGB'), image_batch_file))).astype( np.float32)

sanatanSharma avatar Dec 23 '17 20:12 sanatanSharma

i used: image_batch = np.array(list(map(lambda x: imageio.imread(x,pilmode='RGB'), image_batch_file)),dtype=object).astype( np.float32)

Aelderian avatar Jan 19 '23 16:01 Aelderian