Python 无法将输入数组从形状(128128,4)广播到形状(128128,1)
我想阅读我的口罩,将其用作培训过程的输入 我的蒙版位于名为“蒙版”(我的图像形状(128128,4))的文件夹中 我用了这个密码Python 无法将输入数组从形状(128128,4)广播到形状(128128,1),python,Python,我想阅读我的口罩,将其用作培训过程的输入 我的蒙版位于名为“蒙版”(我的图像形状(128128,4))的文件夹中 我用了这个密码 path_folder = "" # the path to the folder containing masks mask_path= path_folder + '/masks/' mask_file = os.listdir(mask_path) y_train = np.zeros((len(mask_file), 128, 128,
path_folder = "" # the path to the folder containing masks
mask_path= path_folder + '/masks/'
mask_file = os.listdir(mask_path)
y_train = np.zeros((len(mask_file), 128, 128, 1), dtype=np.bool)# this is the nump array where Iwant to put my masks
ctr =0
for n, id_ in tqdm(enumerate(mask_file), total=len(mask_file)):
mask = imread(mask_path + mask_file[n])
y_train[ctr] = mask
ctr = ctr +1
我犯了这个错误
ValueError:无法将输入数组从形状(128128,4)广播到形状(128128,1)
你知道我该怎么做吗?我想问题可能在这里:
mask = imread(mask_path + mask_file[n])
尝试将图像加载为grasycale(我假设您使用的是OpenCV)。这将为您提供一个具有形状(128128)的图像,然后使用unsqueze
添加一个新尺寸
mask = imread(mask_path + mask_file[n], 0)
我认为问题可能在这里:
mask = imread(mask_path + mask_file[n])
尝试将图像加载为grasycale(我假设您使用的是OpenCV)。这将为您提供一个具有形状(128128)的图像,然后使用unsqueze
添加一个新尺寸
mask = imread(mask_path + mask_file[n], 0)
问题是,您试图在曲面中拟合立方体,或者仅使用最后一个维度(共3个)中的一个层,或者将图像转换为灰度 使用opencv的一种方法是
y_train[ctr] = cv2.imread('file_path',0)
此函数用于读取ur图像并将其转换为124124,1形状。问题在于,您试图在曲面中拟合立方体,或者仅使用最后一个维度(共3个)的一层,或者将图像转换为灰度 使用opencv的一种方法是
y_train[ctr] = cv2.imread('file_path',0)
此函数用于读取ur图像并将其转换为124124,1形状