代码地址:https://github.com/CSAILVision/semantic-segmentation-pytorch
1.按照项目主页要求配置环境 2.利用预训练模型在单张图片或多张图片上进行测试
python3 -u test.py --imgs $PATH_IMG --gpu $GPU --cfg $CFG
$PATH_IMG:图片路径,此处注意:需将测试图片放在项目文件夹内 $GPU:采用的GPU,由于目前只有一块GPU,故设置为0 $CFG:配置文件,笔者要运行的是PSPNet,故设置为config/ade20k-resnet50dilated-ppm_deepsup.yaml
运行—>报错:AssertionError: checkpoint does not exitst! 检查config/ade20k-resnet50dilated-ppm_deepsup.yaml文件,将DIR的路径"ckpt/ade20k-resnet50dilated-ppm_deepsup"改为"/home/jessicachan/Documents/research/semantic-segmentation-pytorch/ade20k-resnet50dilated-ppm_deepsup"(测试第一步中下载训练模型)
再次运行,成功实现测试。
3.训练阶段
python3 train.py --gpus $GPUS --cfg $CFG
$GPUS , $CFG的设置同上(不需要修改DIR)
运行—>报错 File “/home/jessicachan/Documents/research/semantic-segmentation-pytorch/models/models.py”, line 34, in forward (pred, pred_deepsup) = self.decoder(self.encoder(feed_dict[‘img_data’], return_feature_maps=True)) TypeError: list indices must be integers or slices, not str 仔细看了项目的需求,训练需要在多个GPU上进行,然而笔者目前只有一个GPU。后来仔细阅读issues上的相关问题,找到了解决方案: To do the following to process the batch_data to get the training going:
batch_data = next(iterator)[0] for k in batch_data.keys(): batch_data[k] = batch_data[k].cuda()Without these fixes, the batch_data will be a length-one list and data in the dictionary will be on CPU instead of GPU (which causes error at conv1 layer). 再次运行,成功在ade20k上完成训练。
未完待续…