路径中的连接使用Unet进行深度学习



路径没有按照我的意愿编写。在我的TRAIN_PATH中,我有文件1、2、3、4,每个文件中都有两个文件,图像(包含图像tiff(和掩码(包含掩码png(。我不知道如何访问每个图像或掩码我将感谢您对社区的帮助

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'

如果您的图像路径类似于'.../dataset/train/1/images/1.tiff',请尝试将path变量更改为:

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

如果图像路径类似于'.../dataset/train/images/1.tiff',请尝试将path变量更改为:

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

最新更新