Concatenation in path Deep learning with Unet

Viewed 92

The path is not written as I want. In my TRAIN_PATH, I have files 1, 2, 3, 4 inside each one I have two files, images (contain image tiff) and masks (contain mask png). I don't know how to get access to each image or mask I would be grateful for your help community

TRAIN_PATH = '/content/drive/MyDrive/PFE_MOHTICH/dataset/train'
TEST_PATH = '/content/drive/MyDrive/PFE_MOHTICH/dataset/test'

train_ids = next(os.walk(TRAIN_PATH))[1]
test_ids = next(os.walk(TEST_PATH))[1]

X_train = np.zeros((len(train_ids), IMG_HEIGHT, IMG_WIDTH, IMG_CHANNELS), dtype=np.uint8)
Y_train = np.zeros((len(train_ids), IMG_HEIGHT, IMG_WIDTH, 1), dtype=np.bool)

print('Resizing training images and masks')
for n, i in tqdm(enumerate(train_ids), total=len(train_ids)):   
    path = TRAIN_PATH + i
    img = imread(path + '/images/' + i + '.tiff')[:,:,:IMG_CHANNELS]  
    img = resize(img, (IMG_HEIGHT, IMG_WIDTH), mode='constant', preserve_range=True)
    X_train[n] = img  #Fill empty X_train with values from img
    mask = np.zeros((IMG_HEIGHT, IMG_WIDTH, 1), dtype=np.bool)
    for mask_file in next(os.walk(path + '/masks/'))[2]:
        mask_ = imread(path + '/masks/' + mask_file)
        mask_ = np.expand_dims(resize(mask_, (IMG_HEIGHT, IMG_WIDTH), mode='constant',  
                                      preserve_range=True), axis=-1)
        mask = np.maximum(mask, mask_)  
            
    Y_train[n] = mask  
***************************ERROR**********************
0%|          | 0/4 [00:00<?, ?it/s]Resizing training images and masks

---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
<ipython-input-12-2ea116d05bcb> in <module>()
     11 for n, i in tqdm(enumerate(train_ids), total=len(train_ids)):
     12     path = TRAIN_PATH + i
---> 13     img = imread(path + '/images/' + i + '.tiff')[:,:,:IMG_CHANNELS]
     14     img = resize(img, (IMG_HEIGHT, IMG_WIDTH), mode='constant', preserve_range=True)
     15     X_train[n] = img  #Fill empty X_train with values from img

5 frames
/usr/local/lib/python3.7/dist-packages/tifffile/tifffile.py in open(self)
   9457             self._file = os.path.realpath(self._file)
   9458             self._dir, self._name = os.path.split(self._file)
-> 9459             self._fh = open(self._file, self._mode)
   9460             self._close = True
   9461             if self._offset is None:

FileNotFoundError: [Errno 2] No such file or directory: '/content/drive/MyDrive/PFE_MOHTICH/dataset/train1/images/1.tiff'
1 Answers

If your image path is something like '.../dataset/train/1/images/1.tiff', try changing the path var to:

# for ...
    path = TRAIN_PATH + '/' + i
#...

If instead the image path is something like '.../dataset/train/images/1.tiff', try changing the path var to:

# for ...
    path = TRAIN_PATH
#...
Related