提问人:Axciom 提问时间:11/5/2023 最后编辑:Christoph RackwitzAxciom 更新时间:11/5/2023 访问量:32
通过 U-Net 进行图像分割时出现形状错误:ValueError:无法将输入数组从形状 (128,128) 广播到形状 (128,128,3)
Shape error in image segmentation via U-Net: ValueError: could not broadcast input array from shape (128,128) into shape (128,128,3)
问:
我正在尝试使用 U-Net 开发皮肤分割。我在下面的代码块中遇到了一个错误,无法解决它。我到底在哪里犯了错误? 守则,
for n, id_ in tqdm(enumerate(os.listdir(TRAIN_PATH)), total=len(os.listdir(TRAIN_PATH))):
path = TRAIN_PATH
img = imread(path + id_)[:, :, :IMG_CHANNELS]
img = resize(img, (IMG_HEIGHT, IMG_WIDTH), mode='constant', preserve_range=True)
X_train[n] = img
mask = np.zeros((IMG_HEIGHT, IMG_WIDTH, 1), dtype=np.bool_)
for root, dirs, files in os.walk(path + '/masks/'):
for mask_file in files:
mask_ = imread(os.path.join(root, 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
错误,
Traceback (most recent call last):
File "..\main.py", line 58, in <module>
X_test[n] = img
ValueError: could not broadcast input array from shape (128,128) into shape (128,128,3)
答: 暂无答案
评论
X_test[n].shape
img.shape
X_train
被定义为拍摄彩色图像(3 形状)。但是您加载了黑白图像。