0

I am having trouble getting google collab to accept a path I specified for a folder.

data_dir = "/content/drive/MyDrive/Traffic_sign/TSF/Traffic_sign_classification"
!ls
train_path = 'Train'
test_path = 'Test'
# Resizing the images to 30x30x3
IMG_HEIGHT = 30
IMG_WIDTH = 30
channels = 3

this is the output:

Meta  Meta.csv  output  Test  Test.csv  Train  Train.csv

so it is clearly getting the contents in the directory, but when I run this

NUM_CATEGORIES = len(os.listdir(train_path))
NUM_CATEGORIES

I get this error

NotADirectoryError                        Traceback (most recent call last)
<ipython-input-55-215493947f82> in <module>()
----> 1 NUM_CATEGORIES = len(os.listdir(train_path))
      2 NUM_CATEGORIES

NotADirectoryError: [Errno 20] Not a directory: 'Train'

I have no clue why I am getting this problem as Train is a folder in Traffic_sign_classification. Does anyone know how to fix it?

Killerbee
  • 1
  • 2
  • Unless the working directory is already set (i.e. it's not in the code you've provided) then !ls is outputting from the location where the drive was mounted (solution: os.chdir("/content/drive/MyDrive/Traffic_sign/TSF/Traffic_sign_classification/"); also, the path should include a final "/" to set the current working directory WITHIN the final folder of that path (i.e. "/content/drive/MyDrive/Traffic_sign/TSF/Traffic_sign_classification/"). – Ori Yarden PhD Nov 26 '21 at 17:40
  • it still gave me the same error when i placed the /, and yes I did do os.chdir("/content/drive/MyDrive/Traffic_sign/TSF/Traffic_sign_classification/") earlier in the code. – Killerbee Nov 26 '21 at 18:27
  • If you haven't altered the initial root path to your Google Colab folder, then try using this "/content/drive/My Drive/Colab Notebooks/Traffic_sign/TSF/Traffic_sign_classification/" (i.e. there's a space in "My Drive" and at least for me, everything is within the main "Colab Notebooks" folder). – Ori Yarden PhD Nov 26 '21 at 19:51

0 Answers0