2020-08-26晚上记录
对原来的unet-nested-multi-class分类函数的images数据集换背景,然后函数修改了一下,修改如下,然后重新训练。
change_background.py 函数修改:
第一加入排序 sort函数
第二将反序去掉。
保存为“change_background_V2.py”
这样只要对images做处理,将背景变为黑色即可,masks数据集依旧是对应的,不用修改。
在Windows电脑上,先测试了一下,unet-nested中data,images_test生成的images_test_out. 对应于maskss_test文件夹。
测试没问题。
所以,将data中的整个images做换背景处理,1500张,生成的数据集为images_changed_background文件夹。
将train.py copy了一份为“train_V2_changes.py”,将数据集进行修改,如下:
- 保存参数命名为“epoch_MXL_changed”
在config.py中修改的:
- epoch从100改为50。
- self.images_dir = ‘./data/images_changed_background’ 修改了输入图像的路径。
- self.checkpoints_dir = ‘./data/checkpoints_changed_background’修改了保存参数的路径。(新建的文件夹)
运行后发现,在utils.dataset.py中,只遍历了imgs_name,所以我的images数据集和masks数据集必须是对应的一样的名字。
所以可以写一个“对masks数据集进行批量重命名的操作”;
或者在dataset.py中再加入一个变量,叫做“masks_name”
【解决】采用了第二种方法,在dataset.py中加了2行,又改了一行。
在dataset.py中加了注释“2020-08-26 added/modified by MXL for black background”
然后开始运行,train_V2_changed.py。正常训练。
保存了一开始的参数在txt文件中,unet-nested的目录下的train_output_changed_background.py。
(2020-08-26 晚上7:45开始训练)
** 修改所使用的模型网络,也是在config中修改的。**
训练一开始的显示:
(pytorch_py37) F:\MXL\DeepLearning\unet-nested-multiple-classification-master>python train_V2_changed.py
INFO: Using device cuda
INFO: Network:
NestedUNet model
3 input channels
3 output channels (classes)
Bilinear upscaling
INFO: Creating dataset with 1500 examples
INFO: Starting training:
Epochs: 50
Batch size: 2
Learning rate: 0.0001
Optimizer: SGD
Training size: 1350
Validation size: 150
Checkpoints: True
Device: cuda
Images scaling: 1
Epoch 1/50: 0%| | 0/1350 [00:15<?, ?img/s, loss (batch)=0.689][W ..\aten\src\ATen\native\TensorIterator.cpp:924] Warning: Mixed memory format inputs detected while calling the operator. The operator will output channels_last tensor even if some of the inputs are not in channels_last format. (function operator ())
Epoch 1/50: 0%|▏ | 4/1350 [00:15<2:01:34, 5.42s/img, loss (batch)=0.674]
Epoch 1/50: 0%|▏ | 4/1350 [00:15<2:01:34, 5.42s/img, loss (batch)=0.697]
Epoch 1/50: 0%|▏ | 6/1350 [00:15<1:25:32, 3.82s/img, loss (batch)=0.697]
Epoch 1/50: 0%|▏ | 6/1350 [00:15<1:25:32, 3.82s/img, loss (batch)=0.67]
Epoch 1/50: 1%|▎ | 8/1350 [00:15<1:00:11, 2.69s/img, loss (batch)=0.67]
2020-08-27 更新
早上来,50个epoch已完成,最后的terminal输出为:
Validation round: 99%|████████████████████████████████████████████████
Validation round: 100%|████████████████████████████████████████████████INFO: Validation cross entropy: 1.0672507084409395
Epoch 50/50: 89%|███████████████████████████████████████ | 1200/1350 [07:10<Epoch 50/50: 89%|███████████████████████████████████████▏ | 1202/1350 [07:10Epoch 50/50: 89%|███████████████████████████████████████▏ | 1202/1350 [07:10Epoch 50/50: 89%|███████████████████████████████████████▏ | 1204/1350 [07:10Epoch 50/50: 89%|███████████████████████████████████████▏ | 1204/1350 [07:11Epoch 50/50: 89%|███████████████████████████████████████▎ | 1206/1350 [07:11Epoch 50/50: 89%|████████████████████████████████████████▏ | 1206/1350 [07:Epoch 50/50: 89%|████████████████████████████████████████▎ | 1208/1350 [07:Epoch 50/50: 89%|███████████████████████████████████████▎ | 1208/1350 [07:12Epoch 50/50: 90%|███████████████████████████████████████▍ | 1210/1350 [07:12Epoch 50/50: 90%|███████████████████████████████████████▍ | 1210/1350 [07:12Epoch 50/50: 90%|███████████████████████████████████████▌ | 1212/1350 [07:12Epoch 50/50: 90%|███████████████████████████████████████▌ | 1212/1350 [07:12Epoch 50/50: 90%|███████████████████████████████████████▌ | 1214/1350 [07:12Epoch 50/50: 90%|███████████████████████████████████████▌ | 1214/1350 [07:13Epoch 50/50: 90%|███████████████████████████████████████▋ | 1216/1350 [07:13Epoch 50/50: 90%|███████████████████████████████████████▋ | 1216/1350 [07:13Epoch 50/50: 90%|███████████████████████████████████████▋ | 1218/1350 [07:13Epoch 50/50: 90%|███████████████████████████████████████▋ | 1218/1350 [07:14Epoch 50/50: 90%|███████████████████████████████████████▊