英文:
What should I do when encountering 'IndexError: index 0 is out of bounds for axis 0 with size 0' during training of a skin detection model on Colab?
问题
我是这个领域的新手。
最近我在Colab上训练了一个皮肤检测模型,并出现了这个错误
IndexError: 索引0超出0轴的大小
与此相关的代码如下:
def load_data(input_size=(100,100)):
images=[]
images2=[]
train_df,test_df=data_dictionary()
for i in train_df['image_path']:
img=cv2.imread(i)
img=cv2.resize(img,input_size)
images.append(img)
y_train=np.asarray(train_df['target'])
x_train=np.asarray(images)
for i in test_df['image_path']:
img=cv2.imread(i)
img=cv2.resize(img,input_size)
images2.append(img)
y_test=np.asarray(test_df['target'])
x_test=np.asarray(images2)
return x_train,x_test,y_train,y_test
x_train,x_test,y_train,y_test=load_data(input_size=(100,100))
train_img=preprocess_input(x_train)
test_img=preprocess_input(x_test)
我对StackOverflow还很陌生,如果我说错了什么请原谅。
def data_dictionary():
path_train="../input/dermnet/train/"
path_test="../input/dermnet/test/"
list_train=train_list_mod
train_dictionary={"image_path":[],"target":[]}
test_dictionary={"image_path":[],"target":[]}
k=0
for i in list_train:
path_disease_train=path_train+i
path_disease_test=path_test+i
image_list_train=os.listdir(path_disease_train)
for j in image_list_train:
img_path_train=path_disease_train+"/"+j
train_dictionary["image_path"].append(img_path_train)
train_dictionary['target'].append(k)
英文:
I'm a newcomer in this field.
Recently i was training a skin detection model on Colab, and this error occurred
IndexError Traceback (most recent call last)
<ipython-input-68-bb8326040b37> in <cell line: 1>()
----> 1 train_img=preprocess_input(x_train)
2 test_img=preprocess_input(x_test)
2 frames
/usr/local/lib/python3.10/dist-packages/keras/applications/imagenet_utils.py in _preprocess_numpy_input(x, data_format, mode)
238 x[:, 2, :, :] /= std[2]
239 else:
--> 240 x[..., 0] -= mean[0]
241 x[..., 1] -= mean[1]
242 x[..., 2] -= mean[2]
IndexError: index 0 is out of bounds for axis 0 with size 0
this is the code relevant to it:
def load_data(input_size=(100,100)):
images=[]
images2=[]
train_df,test_df=data_dictionary()
for i in train_df['image_path']:
img=cv2.imread(i)
img=cv2.resize(img,input_size)
images.append(img)
y_train=np.asarray(train_df['target'])
x_train=np.asarray(images)
for i in test_df['image_path']:
img=cv2.imread(i)
img=cv2.resize(img,input_size)
images2.append(img)
y_test=np.asarray(test_df['target'])
x_test=np.asarray(images2)
return x_train,x_test,y_train,y_test
x_train,x_test,y_train,y_test=load_data(input_size=(100,100))
train_img=preprocess_input(x_train)
test_img=preprocess_input(x_test)
i'm pretty new to stackoverflow so forgive me if i say something misunderstanding.
def data_dictionary():
path_train="../input/dermnet/train/"
path_test="../input/dermnet/test/"
list_train=train_list_mod#os.listdir(path_train)
train_dictionary={"image_path":[],"target":[]}
test_dictionary={"image_path":[],"target":[]}
k=0
for i in list_train:
path_disease_train=path_train+i
path_disease_test=path_test+i
image_list_train=os.listdir(path_disease_train)
for j in image_list_train:
img_path_train=path_disease_train+"/"+j
train_dictionary["image_path"].append(img_path_train)
train_dictionary['target'].append(k)
答案1
得分: 0
这种类型的错误会在数组为空 [] 时发生。可能的问题在于 x_train
数组的为空。
x = np.array([])
x[0]
IndexError: 索引 0 超出了大小为 0 的轴 0 的边界
英文:
Such type of error occur when your array is empty [].<br/>
Maybe problem here - emptiness of x_train
array.
x = np.array([])
x[0]
> IndexError: index 0 is out of bounds for axis 0 with size 0
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论