0

This should be working as i have seen it work on anothers however this is not working for me. I am doing a test/train model and trying to train the image

This is all that i have tried. Data saved on google drive

train_image = []
for i in tqdm(range(train.shape[0])):
    img = image.load_img('/content/drive/My Drive/Colab Notebooks/data/train/'+train['file_id'][i], target_size=(128,173,1), color_mode='grayscale')
    img = image.img_to_array(img)
    img = img/255
    train_image.append(img)
x_train = np.array(train_image)

      0%|          | 0/5377 [00:00<?, ?it/s]
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-5-ef9f3fb90a16> in <module>()
      1 train_image = []
      2 for i in tqdm(range(train.shape[0])):
----> 3     img = image.load_img('/content/drive/My Drive/Colab Notebooks/data/train/'+train['file_id'][i], target_size=(128,173,1), color_mode='grayscale')
      4     img = image.img_to_array(img)
      5     img = img/255

TypeError: must be str, not numpy.int64
  • TypeError: must be str, not numpy.int64 – Paul Kalathas Sep 02 '19 at 16:19
  • Can you paste the entire error you're getting? Which line is the error happening on? – Erty Seidohl Sep 02 '19 at 16:43
  • @ErtySeidohl are you able to see why it is going into TypeError. – Paul Kalathas Sep 02 '19 at 19:29
  • I have a feeling that it has to do with your use of target_size, since it only takes two parts to the tuple (width, height) and you are passing three (128,173,1) – Erty Seidohl Sep 03 '19 at 02:58
  • @ErtySeidohl changing the target size makes no impact/changes. Still get the same error. If it were issue with tuple TypeError would be different. The error i am getting has something to do with line 3 of code where it is assuming that there is int where it should be str. – Paul Kalathas Sep 03 '19 at 06:52
  • Sorry, I don't have enough information. Can you edit your question to contain a [mcve]? – Erty Seidohl Sep 03 '19 at 20:11

1 Answers1

0

Check whether the parameters passed in load_img and img_to_array is correct or not. I had the same error with my code. It was because I was calling a method to get a particular parameter for creating the path which returned a character (typing error) and affected it.