PaddleSeg
PaddleSeg copied to clipboard
出现IndexError: too many indices for array: array is 0-dimensional, but 1 were indexed 的原因
问题确认 Search before asking
- [X] 我已经搜索过问题,但是没有找到解答。I have searched the question and found no related answer.
请提出你的问题 Please ask your question
IndexError: too many indices for array: array is 0-dimensional, but 1 were indexed
配置文件:
train_dataset: #训练数据设置 type: Dataset #指定加载数据集的类。数据集类的代码在
PaddleSeg/paddleseg/datasets`目录下。
dataset_root: water_ponding_dataset #数据集路径
train_path: water_ponding_dataset/train.txt #数据集中用于训练的标识文件
num_classes: 2 #指定类别个数(背景也算为一类)
mode: train #表示用于训练
transforms: #模型训练的数据预处理方式。
- type: ResizeStepScaling #将原始图像和标注图像随机缩放为0.5~2.0倍
min_scale_factor: 0.5
max_scale_factor: 2.0
scale_step_size: 0.25
- type: RandomPaddingCrop #从原始图像和标注图像中随机裁剪512x512大小
crop_size: [1024, 512]
- type: RandomHorizontalFlip #对原始图像和标注图像随机进行水平反转
- type: RandomDistort #对原始图像进行亮度、对比度、饱和度随机变动,标注图像不变
brightness_range: 0.4
contrast_range: 0.4
saturation_range: 0.4
- type: Normalize #对原始图像进行归一化,标注图像保持不变
val_dataset: #验证数据设置
type: Dataset #指定加载数据集的类。数据集类的代码在PaddleSeg/paddleseg/datasets
目录下。
dataset_root: water_ponding_dataset #数据集路径
val_path: water_ponding_dataset/val.txt #数据集中用于验证的标识文件
num_classes: 2 #指定类别个数(背景也算为一类)
mode: val #表示用于验证
transforms: #模型验证的数据预处理的方式
- type: Normalize #对原始图像进行归一化,标注图像保持不变
batch_size: 2 #设定batch_size的值即为迭代一次送入网络的图片数量,一般显卡显存越大,batch_size的值可以越大。如果使用多卡训练,总得batch size等于该batch size乘以卡数。 iters: 160000 #模型训练迭代的轮数
model: type: OCRNet backbone: type: HRNet_W18 pretrained: https://bj.bcebos.com/paddleseg/dygraph/hrnet_w18_ssld.tar.gz backbone_indices: [0]
optimizer: type: SGD
lr_scheduler: type: PolynomialDecay learning_rate: 0.00125 power: 0.9
loss:
types:
- type: MixedLoss
losses:
- type: CrossEntropyLoss
- type: LovaszSoftmaxLoss
coef: [0.8, 0.2]
- type: MixedLoss
losses:
- type: CrossEntropyLoss
- type: LovaszSoftmaxLoss
coef: [0.8, 0.2]
coef: [1, 0.4]
训练命令:
export CUDA_VISIBLE_DEVICES=0,1,2
python -m paddle.distributed.launch tools/train.py
--config configs/ocrnet/ocrnet_hrnetw18_water_1024x512_160k_lovasz_softmax.yml
--do_eval
--use_vdl
--save_interval 500
--save_dir output`
环境:
paddlepaddle 2.6.0.post112
paddleseg 2.8
出现这个报错是我自定义数据的原因还是cudnn的原因?
Remove [0] in train.py
可以换成 paddleseg 2.9试一下
Remove [0] in train.py
Tha's it! Thank you a lot!!!!
您发给我的邮件我已经收到!
Remove [0] in train.py
请问这是什么意思呀?
您发给我的邮件我已经收到!
胡涛涛 @.***
你好! 之前的回答被close了,我也忘记详细的代码了。 应该是paddleseg文件夹里面有个core的文件夹, 然后里面的train.py,有一句代码是loss.data.....什么的,后面有个numpy()[0], 需要把这里的[0]给删了,就可以了。 这个报错是paddleseg的源代码问题,各个版本之间不兼容。你可以这样修改看看,我只是依稀记得是这样搞定的,如果不对的话,你发详细的代码过来我可以帮你看看。
Original Email
Sender:"X-MingYang"< @.*** >;
Sent Time:2024/3/16 19:34
To:"PaddlePaddle/PaddleSeg"< @.*** >;
Cc recipient:"hutaotao1"< @.*** >;"Comment"< @.*** >;
Subject:Re: [PaddlePaddle/PaddleSeg] 出现IndexError: too many indices for array: array is 0-dimensional, but 1 were indexed 的原因 (Issue #3616)
Remove [0] in train.py
请问这是什么意思呀?
— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>
胡涛涛 @.*** 你好! 之前的回答被close了,我也忘记详细的代码了。 应该是paddleseg文件夹里面有个core的文件夹, 然后里面的train.py,有一句代码是loss.data.....什么的,后面有个numpy()[0], 需要把这里的[0]给删了,就可以了。 这个报错是paddleseg的源代码问题,各个版本之间不兼容。你可以这样修改看看,我只是依稀记得是这样搞定的,如果不对的话,你发详细的代码过来我可以帮你看看。 Original Email Sender:"X-MingYang"< @.*** >; Sent Time:2024/3/16 19:34 To:"PaddlePaddle/PaddleSeg"< @.*** >; Cc recipient:"hutaotao1"< @.*** >;"Comment"< @.*** >; Subject:Re: [PaddlePaddle/PaddleSeg] 出现IndexError: too many indices for array: array is 0-dimensional, but 1 were indexed 的原因 (Issue #3616) Remove [0] in train.py 请问这是什么意思呀? — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>
谢谢您!我是在百度的AI studio上做的,我发现将项目的版本由2.6.0切换至2.3.2后就没事了。再次感谢!
不客气。
胡涛涛 @.***
Original Email
Sender:"X-MingYang"< @.*** >;
Sent Time:2024/3/16 21:19
To:"PaddlePaddle/PaddleSeg"< @.*** >;
Cc recipient:"hutaotao1"< @.*** >;"Comment"< @.*** >;
Subject:Re: [PaddlePaddle/PaddleSeg] 出现IndexError: too many indices for array: array is 0-dimensional, but 1 were indexed 的原因 (Issue #3616)
胡涛涛 @.*** 你好! 之前的回答被close了,我也忘记详细的代码了。 应该是paddleseg文件夹里面有个core的文件夹, 然后里面的train.py,有一句代码是loss.data.....什么的,后面有个numpy()[0], 需要把这里的[0]给删了,就可以了。 这个报错是paddleseg的源代码问题,各个版本之间不兼容。你可以这样修改看看,我只是依稀记得是这样搞定的,如果不对的话,你发详细的代码过来我可以帮你看看。 Original Email Sender:"X-MingYang"< @.*** >; Sent Time:2024/3/16 19:34 To:"PaddlePaddle/PaddleSeg"< @.*** >; Cc recipient:"hutaotao1"< @.*** >;"Comment"< @.*** >; Subject:Re: [PaddlePaddle/PaddleSeg] 出现IndexError: too many indices for array: array is 0-dimensional, but 1 were indexed 的原因 (Issue #3616) Remove [0] in train.py 请问这是什么意思呀? — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>
谢谢您!我是在百度的AI studio上做的,我发现将项目的版本由2.6.0切换至2.3.2后就没事了。再次感谢!
— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>
胡涛涛 @.*** 你好! 之前的回答被close了,我也忘记详细的代码了。 应该是paddleseg文件夹里面有个core的文件夹, 然后里面的train.py,有一句代码是loss.data.....什么的,后面有个numpy()[0], 需要把这里的[0]给删了,就可以了。 这个报错是paddleseg的源代码问题,各个版本之间不兼容。你可以这样修改看看,我只是依稀记得是这样搞定的,如果不对的话,你发详细的代码过来我可以帮你看看。 Original Email Sender:"X-MingYang"< @.*** >; Sent Time:2024/3/16 19:34 To:"PaddlePaddle/PaddleSeg"< @.*** >; Cc recipient:"hutaotao1"< @.*** >;"Comment"< @.*** >; Subject:Re: [PaddlePaddle/PaddleSeg] 出现IndexError: too many indices for array: array is 0-dimensional, but 1 were indexed 的原因 (Issue #3616) Remove [0] in train.py 请问这是什么意思呀? — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>
谢谢您!我是在百度的AI studio上做的,我发现将项目的版本由2.6.0切换至2.3.2后就没事了。再次感谢!
另外,我在AI studio上进入了【/home/aistudio/PaddleSeg/paddleseg/core/train.py】之后,将其中avg_loss_list = [l[0]/ log_iters for l in avg_loss_list]
修改为avg_loss_list = [l/ log_iters for l in avg_loss_list]
之后,重新启动项目也还会报一样的错=错误(就像您给出的图片中所显示的那样)
这个除了修改这里还要修改: 1./home/aistudio/PaddleSeg/paddleseg/core/train.py 文件内'avg_loss += loss.numpy()[0]'改成‘avg_loss += loss.numpy()’2.‘avg_loss_list = [l[0] / log_iters for l in avg_loss_list]’也是要改成‘avg_loss_list = [l / log_iters for l in avg_loss_list]’。 3.metrics.py文件里的‘pred_area.append(paddle.sum(paddle.cast(pred_i, "int32")))’也要改成‘pred_area.append(paddle.sum(paddle.cast(pred_i, "int32")).unsqueeze(0))’ 这样才能正常运行。 ———————————————— 原文链接:https://blog.csdn.net/m0_64719223/article/details/132903647
胡涛涛 @.***
Original Email
Sender:"X-MingYang"< @.*** >;
Sent Time:2024/3/16 21:24
To:"PaddlePaddle/PaddleSeg"< @.*** >;
Cc recipient:"hutaotao1"< @.*** >;"Comment"< @.*** >;
Subject:Re: [PaddlePaddle/PaddleSeg] 出现IndexError: too many indices for array: array is 0-dimensional, but 1 were indexed 的原因 (Issue #3616)
胡涛涛 @.*** 你好! 之前的回答被close了,我也忘记详细的代码了。 应该是paddleseg文件夹里面有个core的文件夹, 然后里面的train.py,有一句代码是loss.data.....什么的,后面有个numpy()[0], 需要把这里的[0]给删了,就可以了。 这个报错是paddleseg的源代码问题,各个版本之间不兼容。你可以这样修改看看,我只是依稀记得是这样搞定的,如果不对的话,你发详细的代码过来我可以帮你看看。 Original Email Sender:"X-MingYang"< @.*** >; Sent Time:2024/3/16 19:34 To:"PaddlePaddle/PaddleSeg"< @.*** >; Cc recipient:"hutaotao1"< @.*** >;"Comment"< @.*** >; Subject:Re: [PaddlePaddle/PaddleSeg] 出现IndexError: too many indices for array: array is 0-dimensional, but 1 were indexed 的原因 (Issue #3616) Remove [0] in train.py 请问这是什么意思呀? — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>
谢谢您!我是在百度的AI studio上做的,我发现将项目的版本由2.6.0切换至2.3.2后就没事了。再次感谢!
另外,我在AI studio上进入了【/home/aistudio/PaddleSeg/paddleseg/core/train.py】之后,将其中avg_loss_list = [l[0]/ log_iters for l in avg_loss_list]修改为avg_loss_list = [l/ log_iters for l in avg_loss_list]之后,重新启动项目也还会报一样的错=错误(就像您给出的图片中所显示的那样)
— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>
这个除了修改这里还要修改: 1./home/aistudio/PaddleSeg/paddleseg/core/train.py 文件内'avg_loss += loss.numpy()[0]'改成‘avg_loss += loss.numpy()’2.‘avg_loss_list = [l[0] / log_iters for l in avg_loss_list]’也是要改成‘avg_loss_list = [l / log_iters for l in avg_loss_list]’。 3.metrics.py文件里的‘pred_area.append(paddle.sum(paddle.cast(pred_i, "int32")))’也要改成‘pred_area.append(paddle.sum(paddle.cast(pred_i, "int32")).unsqueeze(0))’ 这样才能正常运行。 ———————————————— 原文链接:https://blog.csdn.net/m0_64719223/article/details/132903647 胡涛涛 @.*** Original Email Sender:"X-MingYang"< @.*** >; Sent Time:2024/3/16 21:24 To:"PaddlePaddle/PaddleSeg"< @.*** >; Cc recipient:"hutaotao1"< @.*** >;"Comment"< @.*** >; Subject:Re: [PaddlePaddle/PaddleSeg] 出现IndexError: too many indices for array: array is 0-dimensional, but 1 were indexed 的原因 (Issue #3616) 胡涛涛 @.*** 你好! 之前的回答被close了,我也忘记详细的代码了。 应该是paddleseg文件夹里面有个core的文件夹, 然后里面的train.py,有一句代码是loss.data.....什么的,后面有个numpy()[0], 需要把这里的[0]给删了,就可以了。 这个报错是paddleseg的源代码问题,各个版本之间不兼容。你可以这样修改看看,我只是依稀记得是这样搞定的,如果不对的话,你发详细的代码过来我可以帮你看看。 Original Email Sender:"X-MingYang"< @.*** >; Sent Time:2024/3/16 19:34 To:"PaddlePaddle/PaddleSeg"< @.*** >; Cc recipient:"hutaotao1"< @.*** >;"Comment"< @.*** >; Subject:Re: [PaddlePaddle/PaddleSeg] 出现IndexError: too many indices for array: array is 0-dimensional, but 1 were indexed 的原因 (Issue #3616) Remove [0] in train.py 请问这是什么意思呀? — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.> 谢谢您!我是在百度的AI studio上做的,我发现将项目的版本由2.6.0切换至2.3.2后就没事了。再次感谢! 另外,我在AI studio上进入了【/home/aistudio/PaddleSeg/paddleseg/core/train.py】之后,将其中avg_loss_list = [l[0]/ log_iters for l in avg_loss_list]修改为avg_loss_list = [l/ log_iters for l in avg_loss_list]之后,重新启动项目也还会报一样的错=错误(就像您给出的图片中所显示的那样) — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.>
好的,谢谢您!请问【1./home/aistudio/PaddleSeg/paddleseg/core/train.py 文件内'avg_loss += loss.numpy()[0]'改成‘avg_loss += loss.numpy()’】是您笔误了吗。 我明天早上再试一试(今天的算力已经用完了),祝您晚安!
不是,我记得就是要这样改的。
胡涛涛 @.***
Original Email
Sender:"X-MingYang"< @.*** >;
Sent Time:2024/3/16 22:39
To:"PaddlePaddle/PaddleSeg"< @.*** >;
Cc recipient:"hutaotao1"< @.*** >;"Comment"< @.*** >;
Subject:Re: [PaddlePaddle/PaddleSeg] 出现IndexError: too many indices for array: array is 0-dimensional, but 1 were indexed 的原因 (Issue #3616)
这个除了修改这里还要修改: 1./home/aistudio/PaddleSeg/paddleseg/core/train.py 文件内'avg_loss += loss.numpy()[0]'改成‘avg_loss += loss.numpy()’2.‘avg_loss_list = [l[0] / log_iters for l in avg_loss_list]’也是要改成‘avg_loss_list = [l / log_iters for l in avg_loss_list]’。 3.metrics.py文件里的‘pred_area.append(paddle.sum(paddle.cast(pred_i, "int32")))’也要改成‘pred_area.append(paddle.sum(paddle.cast(pred_i, "int32")).unsqueeze(0))’ 这样才能正常运行。 ———————————————— 原文链接:https://blog.csdn.net/m0_64719223/article/details/132903647 胡涛涛 @.*** Original Email Sender:"X-MingYang"< @.*** >; Sent Time:2024/3/16 21:24 To:"PaddlePaddle/PaddleSeg"< @.*** >; Cc recipient:"hutaotao1"< @.*** >;"Comment"< @.*** >; Subject:Re: [PaddlePaddle/PaddleSeg] 出现IndexError: too many indices for array: array is 0-dimensional, but 1 were indexed 的原因 (Issue #3616) 胡涛涛 @.*** 你好! 之前的回答被close了,我也忘记详细的代码了。 应该是paddleseg文件夹里面有个core的文件夹, 然后里面的train.py,有一句代码是loss.data.....什么的,后面有个numpy()[0], 需要把这里的[0]给删了,就可以了。 这个报错是paddleseg的源代码问题,各个版本之间不兼容。你可以这样修改看看,我只是依稀记得是这样搞定的,如果不对的话,你发详细的代码过来我可以帮你看看。 Original Email Sender:"X-MingYang"< @.*** >; Sent Time:2024/3/16 19:34 To:"PaddlePaddle/PaddleSeg"< @.*** >; Cc recipient:"hutaotao1"< @.*** >;"Comment"< @.*** >; Subject:Re: [PaddlePaddle/PaddleSeg] 出现IndexError: too many indices for array: array is 0-dimensional, but 1 were indexed 的原因 (Issue #3616) Remove [0] in train.py 请问这是什么意思呀? — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.> 谢谢您!我是在百度的AI studio上做的,我发现将项目的版本由2.6.0切换至2.3.2后就没事了。再次感谢! 另外,我在AI studio上进入了【/home/aistudio/PaddleSeg/paddleseg/core/train.py】之后,将其中avg_loss_list = [l[0]/ log_iters for l in avg_loss_list]修改为avg_loss_list = [l/ log_iters for l in avg_loss_list]之后,重新启动项目也还会报一样的错=错误(就像您给出的图片中所显示的那样) — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.>
好的,谢谢您!请问【1./home/aistudio/PaddleSeg/paddleseg/core/train.py 文件内'avg_loss += loss.numpy()[0]'改成‘avg_loss += loss.numpy()’】是您笔误了吗。 我明天早上再试一试(今天的算力已经用完了),祝您晚安!
— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>
paddleseg/core/train.py
:
-
avg_loss_list = [l[0] / log_iters for l in avg_loss_list]
-->avg_loss_list = [l / log_iters for l in avg_loss_list]
您发给我的邮件我已经收到!
可以换成 paddleseg 2.9试一下
2.9的问题更多,我都没有跑到这里来
您发给我的邮件我已经收到!