Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 无法将输入数组从形状(128128,4)广播到形状(128128,1)_Python - Fatal编程技术网

Python 无法将输入数组从形状(128128,4)广播到形状(128128,1)

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,

我想阅读我的口罩,将其用作培训过程的输入 我的蒙版位于名为“蒙版”(我的图像形状(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, 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形状