| @@ -1,10 +1,7 @@ | |||||
| # Deeplab-V3 Example | # Deeplab-V3 Example | ||||
| ## Description | ## Description | ||||
| - This is an example of training DeepLabv3 with PASCAL VOC 2012 dataset in MindSpore. | |||||
| - Paper Rethinking Atrous Convolution for Semantic Image Segmentation | |||||
| Liang-Chieh Chen, George Papandreou, Florian Schroff, Hartwig Adam | |||||
| This is an example of training DeepLabv3 with PASCAL VOC 2012 dataset in MindSpore. | |||||
| ## Requirements | ## Requirements | ||||
| - Install [MindSpore](https://www.mindspore.cn/install/en). | - Install [MindSpore](https://www.mindspore.cn/install/en). | ||||
| @@ -50,7 +50,7 @@ class OhemLoss(nn.Cell): | |||||
| losses = self.cross_entropy(logits, one_hot_labels)[0] | losses = self.cross_entropy(logits, one_hot_labels)[0] | ||||
| weights = self.cast(self.not_equal(labels, self.ignore_label), mstype.float32) * self.loss_weight | weights = self.cast(self.not_equal(labels, self.ignore_label), mstype.float32) * self.loss_weight | ||||
| weighted_losses = self.mul(losses, weights) | weighted_losses = self.mul(losses, weights) | ||||
| loss = self.reduce_sum(weighted_losses,(0,)) | |||||
| loss = self.reduce_sum(weighted_losses, (0,)) | |||||
| zeros = self.fill(mstype.float32, self.shape(weights), 0.0) | zeros = self.fill(mstype.float32, self.shape(weights), 0.0) | ||||
| ones = self.fill(mstype.float32, self.shape(weights), 1.0) | ones = self.fill(mstype.float32, self.shape(weights), 1.0) | ||||
| present = self.select(self.equal(weights, zeros), zeros, ones) | present = self.select(self.equal(weights, zeros), zeros, ones) | ||||
| @@ -80,9 +80,9 @@ if __name__ == "__main__": | |||||
| ckpoint_cb = ModelCheckpoint(prefix='checkpoint_deeplabv3', config=config_ck) | ckpoint_cb = ModelCheckpoint(prefix='checkpoint_deeplabv3', config=config_ck) | ||||
| callback.append(ckpoint_cb) | callback.append(ckpoint_cb) | ||||
| net = deeplabv3_resnet50(config.seg_num_classes, [args_opt.batch_size, 3, args_opt.crop_size, args_opt.crop_size], | net = deeplabv3_resnet50(config.seg_num_classes, [args_opt.batch_size, 3, args_opt.crop_size, args_opt.crop_size], | ||||
| infer_scale_sizes=config.eval_scales, atrous_rates=config.atrous_rates, | |||||
| decoder_output_stride=config.decoder_output_stride, output_stride=config.output_stride, | |||||
| fine_tune_batch_norm=config.fine_tune_batch_norm, image_pyramid=config.image_pyramid) | |||||
| infer_scale_sizes=config.eval_scales, atrous_rates=config.atrous_rates, | |||||
| decoder_output_stride=config.decoder_output_stride, output_stride=config.output_stride, | |||||
| fine_tune_batch_norm=config.fine_tune_batch_norm, image_pyramid=config.image_pyramid) | |||||
| net.set_train() | net.set_train() | ||||
| model_fine_tune(args_opt, net, 'layer') | model_fine_tune(args_opt, net, 'layer') | ||||
| loss = OhemLoss(config.seg_num_classes, config.ignore_label) | loss = OhemLoss(config.seg_num_classes, config.ignore_label) | ||||