Sfoglia il codice sorgente

Hierarchical tasks

Bobholamovic 2 anni fa
parent
commit
6ada72fb65
30 ha cambiato i file con 43 aggiunte e 40 eliminazioni
  1. 2 2
      paddlers/deploy/predictor.py
  2. 5 5
      paddlers/tasks/__init__.py
  3. 1 1
      paddlers/tasks/base.py
  4. 1 1
      paddlers/tasks/change_detector.py
  5. 8 6
      paddlers/tasks/load_model.py
  6. 1 1
      paddlers/tasks/utils/infer_nets.py
  7. 1 1
      paddlers/transforms/__init__.py
  8. 1 1
      tutorials/train/change_detection/bit.py
  9. 1 1
      tutorials/train/change_detection/cdnet.py
  10. 1 1
      tutorials/train/change_detection/dsamnet.py
  11. 1 1
      tutorials/train/change_detection/dsifn.py
  12. 1 1
      tutorials/train/change_detection/fc_ef.py
  13. 1 1
      tutorials/train/change_detection/fc_siam_conc.py
  14. 1 1
      tutorials/train/change_detection/fc_siam_diff.py
  15. 1 1
      tutorials/train/change_detection/snunet.py
  16. 1 1
      tutorials/train/change_detection/stanet.py
  17. 1 1
      tutorials/train/classification/condensenetv2_b_rs_mul.py
  18. 1 1
      tutorials/train/classification/hrnet.py
  19. 2 1
      tutorials/train/classification/mobilenetv3.py
  20. 1 1
      tutorials/train/classification/resnet50_vd.py
  21. 1 1
      tutorials/train/image_restoration/drn_train.py
  22. 1 1
      tutorials/train/image_restoration/esrgan_train.py
  23. 1 1
      tutorials/train/image_restoration/lesrcnn_train.py
  24. 1 1
      tutorials/train/object_detection/faster_rcnn.py
  25. 1 1
      tutorials/train/object_detection/ppyolo.py
  26. 1 1
      tutorials/train/object_detection/ppyolotiny.py
  27. 1 1
      tutorials/train/object_detection/ppyolov2.py
  28. 1 1
      tutorials/train/object_detection/yolov3.py
  29. 1 1
      tutorials/train/semantic_segmentation/deeplabv3p.py
  30. 1 1
      tutorials/train/semantic_segmentation/unet.py

+ 2 - 2
paddlers/deploy/predictor.py

@@ -157,7 +157,7 @@ class Predictor(object):
             }
         elif self._model.model_type == 'detector':
             pass
-        elif self._model.model_type == 'changedetector':
+        elif self._model.model_type == 'change_detector':
             preprocessed_samples = {
                 'image': preprocessed_samples[0],
                 'image2': preprocessed_samples[1],
@@ -186,7 +186,7 @@ class Predictor(object):
                 'scores_map': s,
                 'label_names_map': n,
             } for l, s, n in zip(class_ids, scores, label_names)]
-        elif self._model.model_type in ('segmenter', 'changedetector'):
+        elif self._model.model_type in ('segmenter', 'change_detector'):
             label_map, score_map = self._model._postprocess(
                 net_outputs,
                 batch_origin_shape=ori_shape,

+ 5 - 5
paddlers/tasks/__init__.py

@@ -12,9 +12,9 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-from .object_detector import *
-from .segmenter import *
-from .change_detector import *
-from .classifier import *
+import paddlers.tasks.object_detector as det
+import paddlers.tasks.segmenter as seg
+import paddlers.tasks.change_detector as cd
+import paddlers.classifier as clas
+import paddlers.image_restorer as res
 from .load_model import load_model
-from .image_restorer import *

+ 1 - 1
paddlers/tasks/base.py

@@ -621,7 +621,7 @@ class BaseModel(metaclass=ModelMeta):
     def _build_inference_net(self):
         if self.model_type in ('classifier', 'detector'):
             infer_net = self.net
-        elif self.model_type == 'changedetector':
+        elif self.model_type == 'change_detector':
             infer_net = InferCDNet(self.net)
         else:
             infer_net = InferNet(self.net, self.model_type)

+ 1 - 1
paddlers/tasks/change_detector.py

@@ -50,7 +50,7 @@ class BaseChangeDetector(BaseModel):
         self.init_params = locals()
         if 'with_net' in self.init_params:
             del self.init_params['with_net']
-        super(BaseChangeDetector, self).__init__('changedetector')
+        super(BaseChangeDetector, self).__init__('change_detector')
         if model_name not in __all__:
             raise Exception("ERROR: There's no model named {}.".format(
                 model_name))

+ 8 - 6
paddlers/tasks/load_model.py

@@ -73,9 +73,11 @@ def load_model(model_dir, **params):
         assert status == 'Infer', \
             "Only exported models can be deployed for inference, but current model status is {}.".format(status)
 
-    if not hasattr(paddlers.tasks, model_info['Model']):
-        raise Exception("There is no {} attribute in paddlers.tasks.".format(
-            model_info['Model']))
+    model_type = model_info['_Attributes']['model_type']
+    mod = getattr(paddlers.tasks, model_type)
+    if not hasattr(mod, model_info['Model']):
+        raise Exception("There is no {} attribute in {}.".format(model_info[
+            'Model'], mod))
     if 'model_name' in model_info['_init_params']:
         del model_info['_init_params']['model_name']
 
@@ -88,7 +90,7 @@ def load_model(model_dir, **params):
             )
         params = model_info.pop('raw_params', {})
         params.update(model_info['_init_params'])
-        model = getattr(paddlers.tasks, model_info['Model'])(**params)
+        model = getattr(mod, model_info['Model'])(**params)
         if with_net:
             if status == 'Pruned' or osp.exists(
                     osp.join(model_dir, "prune.yml")):
@@ -127,9 +129,9 @@ def load_model(model_dir, **params):
                 else:
                     net_state_dict = paddle.load(osp.join(model_dir, 'model'))
                     if model.model_type in [
-                            'classifier', 'segmenter', 'changedetector'
+                            'classifier', 'segmenter', 'change_detector'
                     ]:
-                        # When exporting a classifier, segmenter, or changedetector,
+                        # When exporting a classifier, segmenter, or change_detector,
                         # InferNet (or InferCDNet) is defined to append softmax and argmax operators to the model,
                         # so the parameter names all start with 'net.'
                         new_net_state_dict = {}

+ 1 - 1
paddlers/tasks/utils/infer_nets.py

@@ -46,7 +46,7 @@ class InferCDNet(paddle.nn.Layer):
     def __init__(self, net):
         super(InferCDNet, self).__init__()
         self.net = net
-        self.postprocessor = PostProcessor('changedetector')
+        self.postprocessor = PostProcessor('change_detector')
 
     def forward(self, x1, x2):
         net_outputs = self.net(x1, x2)

+ 1 - 1
paddlers/transforms/__init__.py

@@ -59,7 +59,7 @@ def arrange_transforms(model_type, transforms, mode='train'):
         else:
             transforms.apply_im_only = False
         arrange_transform = ArrangeSegmenter(mode)
-    elif model_type == 'changedetector':
+    elif model_type == 'change_detector':
         if mode == 'eval':
             transforms.apply_im_only = True
         else:

+ 1 - 1
tutorials/train/change_detection/bit.py

@@ -68,7 +68,7 @@ eval_dataset = pdrs.datasets.CDDataset(
 # 使用默认参数构建BIT模型
 # 目前已支持的模型请参考:https://github.com/PaddleCV-SIG/PaddleRS/blob/develop/docs/apis/model_zoo.md
 # 模型输入参数请参考:https://github.com/PaddleCV-SIG/PaddleRS/blob/develop/paddlers/tasks/change_detector.py
-model = pdrs.tasks.BIT()
+model = pdrs.tasks.cd.BIT()
 
 # 执行模型训练
 model.train(

+ 1 - 1
tutorials/train/change_detection/cdnet.py

@@ -68,7 +68,7 @@ eval_dataset = pdrs.datasets.CDDataset(
 # 使用默认参数构建CDNet模型
 # 目前已支持的模型请参考:https://github.com/PaddleCV-SIG/PaddleRS/blob/develop/docs/apis/model_zoo.md
 # 模型输入参数请参考:https://github.com/PaddleCV-SIG/PaddleRS/blob/develop/paddlers/tasks/change_detector.py
-model = pdrs.tasks.CDNet()
+model = pdrs.tasks.cd.CDNet()
 
 # 执行模型训练
 model.train(

+ 1 - 1
tutorials/train/change_detection/dsamnet.py

@@ -68,7 +68,7 @@ eval_dataset = pdrs.datasets.CDDataset(
 # 使用默认参数构建DSAMNet模型
 # 目前已支持的模型请参考:https://github.com/PaddleCV-SIG/PaddleRS/blob/develop/docs/apis/model_zoo.md
 # 模型输入参数请参考:https://github.com/PaddleCV-SIG/PaddleRS/blob/develop/paddlers/tasks/change_detector.py
-model = pdrs.tasks.DSAMNet()
+model = pdrs.tasks.cd.DSAMNet()
 
 # 执行模型训练
 model.train(

+ 1 - 1
tutorials/train/change_detection/dsifn.py

@@ -68,7 +68,7 @@ eval_dataset = pdrs.datasets.CDDataset(
 # 使用默认参数构建DSIFN模型
 # 目前已支持的模型请参考:https://github.com/PaddleCV-SIG/PaddleRS/blob/develop/docs/apis/model_zoo.md
 # 模型输入参数请参考:https://github.com/PaddleCV-SIG/PaddleRS/blob/develop/paddlers/tasks/change_detector.py
-model = pdrs.tasks.DSIFN()
+model = pdrs.tasks.cd.DSIFN()
 
 # 执行模型训练
 model.train(

+ 1 - 1
tutorials/train/change_detection/fc_ef.py

@@ -68,7 +68,7 @@ eval_dataset = pdrs.datasets.CDDataset(
 # 使用默认参数构建FC-EF模型
 # 目前已支持的模型请参考:https://github.com/PaddleCV-SIG/PaddleRS/blob/develop/docs/apis/model_zoo.md
 # 模型输入参数请参考:https://github.com/PaddleCV-SIG/PaddleRS/blob/develop/paddlers/tasks/change_detector.py
-model = pdrs.tasks.FCEarlyFusion()
+model = pdrs.tasks.cd.FCEarlyFusion()
 
 # 执行模型训练
 model.train(

+ 1 - 1
tutorials/train/change_detection/fc_siam_conc.py

@@ -68,7 +68,7 @@ eval_dataset = pdrs.datasets.CDDataset(
 # 使用默认参数构建FC-Siam-conc模型
 # 目前已支持的模型请参考:https://github.com/PaddleCV-SIG/PaddleRS/blob/develop/docs/apis/model_zoo.md
 # 模型输入参数请参考:https://github.com/PaddleCV-SIG/PaddleRS/blob/develop/paddlers/tasks/change_detector.py
-model = pdrs.tasks.FCSiamConc()
+model = pdrs.tasks.cd.FCSiamConc()
 
 # 执行模型训练
 model.train(

+ 1 - 1
tutorials/train/change_detection/fc_siam_diff.py

@@ -68,7 +68,7 @@ eval_dataset = pdrs.datasets.CDDataset(
 # 使用默认参数构建FC-Siam-diff模型
 # 目前已支持的模型请参考:https://github.com/PaddleCV-SIG/PaddleRS/blob/develop/docs/apis/model_zoo.md
 # 模型输入参数请参考:https://github.com/PaddleCV-SIG/PaddleRS/blob/develop/paddlers/tasks/change_detector.py
-model = pdrs.tasks.FCSiamDiff()
+model = pdrs.tasks.cd.FCSiamDiff()
 
 # 执行模型训练
 model.train(

+ 1 - 1
tutorials/train/change_detection/snunet.py

@@ -68,7 +68,7 @@ eval_dataset = pdrs.datasets.CDDataset(
 # 使用默认参数构建SNUNet模型
 # 目前已支持的模型请参考:https://github.com/PaddleCV-SIG/PaddleRS/blob/develop/docs/apis/model_zoo.md
 # 模型输入参数请参考:https://github.com/PaddleCV-SIG/PaddleRS/blob/develop/paddlers/tasks/change_detector.py
-model = pdrs.tasks.SNUNet()
+model = pdrs.tasks.cd.SNUNet()
 
 # 执行模型训练
 model.train(

+ 1 - 1
tutorials/train/change_detection/stanet.py

@@ -68,7 +68,7 @@ eval_dataset = pdrs.datasets.CDDataset(
 # 使用默认参数构建STANet模型
 # 目前已支持的模型请参考:https://github.com/PaddleCV-SIG/PaddleRS/blob/develop/docs/apis/model_zoo.md
 # 模型输入参数请参考:https://github.com/PaddleCV-SIG/PaddleRS/blob/develop/paddlers/tasks/change_detector.py
-model = pdrs.tasks.STANet()
+model = pdrs.tasks.cd.STANet()
 
 # 执行模型训练
 model.train(

+ 1 - 1
tutorials/train/classification/condensenetv2_b_rs_mul.py

@@ -36,7 +36,7 @@ eval_dataset = pdrs.datasets.ClasDataset(
 
 # 初始化模型
 num_classes = len(train_dataset.labels)
-model = pdrs.tasks.CondenseNetV2_b(in_channels=5, num_classes=num_classes)
+model = pdrs.tasks.clas.CondenseNetV2_b(in_channels=5, num_classes=num_classes)
 
 # 进行训练
 model.train(

+ 1 - 1
tutorials/train/classification/hrnet.py

@@ -65,7 +65,7 @@ eval_dataset = pdrs.datasets.ClasDataset(
 # 使用默认参数构建HRNet模型
 # 目前已支持的模型请参考:https://github.com/PaddleCV-SIG/PaddleRS/blob/develop/docs/apis/model_zoo.md
 # 模型输入参数请参考:https://github.com/PaddleCV-SIG/PaddleRS/blob/develop/paddlers/tasks/classifier.py
-model = pdrs.tasks.HRNet_W18_C(num_classes=len(train_dataset.labels))
+model = pdrs.tasks.clas.HRNet_W18_C(num_classes=len(train_dataset.labels))
 
 # 执行模型训练
 model.train(

+ 2 - 1
tutorials/train/classification/mobilenetv3.py

@@ -65,7 +65,8 @@ eval_dataset = pdrs.datasets.ClasDataset(
 # 使用默认参数构建MobileNetV3模型
 # 目前已支持的模型请参考:https://github.com/PaddleCV-SIG/PaddleRS/blob/develop/docs/apis/model_zoo.md
 # 模型输入参数请参考:https://github.com/PaddleCV-SIG/PaddleRS/blob/develop/paddlers/tasks/classifier.py
-model = pdrs.tasks.MobileNetV3_small_x1_0(num_classes=len(train_dataset.labels))
+model = pdrs.tasks.clas.MobileNetV3_small_x1_0(
+    num_classes=len(train_dataset.labels))
 
 # 执行模型训练
 model.train(

+ 1 - 1
tutorials/train/classification/resnet50_vd.py

@@ -65,7 +65,7 @@ eval_dataset = pdrs.datasets.ClasDataset(
 # 使用默认参数构建ResNet50-vd模型
 # 目前已支持的模型请参考:https://github.com/PaddleCV-SIG/PaddleRS/blob/develop/docs/apis/model_zoo.md
 # 模型输入参数请参考:https://github.com/PaddleCV-SIG/PaddleRS/blob/develop/paddlers/tasks/classifier.py
-model = pdrs.tasks.ResNet50_vd(num_classes=len(train_dataset.labels))
+model = pdrs.tasks.clas.ResNet50_vd(num_classes=len(train_dataset.labels))
 
 # 执行模型训练
 model.train(

+ 1 - 1
tutorials/train/image_restoration/drn_train.py

@@ -66,7 +66,7 @@ test_dataset = pdrs.datasets.SRdataset(
     scale=scale)
 
 # 初始化模型,可以对网络结构的参数进行调整
-model = pdrs.tasks.DRNet(
+model = pdrs.tasks.res.DRNet(
     n_blocks=30, n_feats=16, n_colors=3, rgb_range=255, negval=0.2)
 
 model.train(

+ 1 - 1
tutorials/train/image_restoration/esrgan_train.py

@@ -65,7 +65,7 @@ test_dataset = pdrs.datasets.SRdataset(
 # 初始化模型,可以对网络结构的参数进行调整
 # 若loss_type='gan' 使用感知损失、对抗损失和像素损失
 # 若loss_type = 'pixel' 只使用像素损失
-model = pdrs.tasks.ESRGANet(loss_type='pixel')
+model = pdrs.tasks.res.ESRGANet(loss_type='pixel')
 
 model.train(
     total_iters=1000000,

+ 1 - 1
tutorials/train/image_restoration/lesrcnn_train.py

@@ -63,7 +63,7 @@ test_dataset = pdrs.datasets.SRdataset(
     scale=scale)
 
 # 初始化模型,可以对网络结构的参数进行调整
-model = pdrs.tasks.LESRCNNet(scale=4, multi_scale=False, group=1)
+model = pdrs.tasks.res.LESRCNNet(scale=4, multi_scale=False, group=1)
 
 model.train(
     total_iters=1000000,

+ 1 - 1
tutorials/train/object_detection/faster_rcnn.py

@@ -74,7 +74,7 @@ eval_dataset = pdrs.datasets.VOCDetection(
 # 构建Faster R-CNN模型
 # 目前已支持的模型请参考:https://github.com/PaddleCV-SIG/PaddleRS/blob/develop/docs/apis/model_zoo.md
 # 模型输入参数请参考:https://github.com/PaddleCV-SIG/PaddleRS/blob/develop/paddlers/tasks/object_detector.py
-model = pdrs.tasks.FasterRCNN(num_classes=len(train_dataset.labels))
+model = pdrs.tasks.det.FasterRCNN(num_classes=len(train_dataset.labels))
 
 # 执行模型训练
 model.train(

+ 1 - 1
tutorials/train/object_detection/ppyolo.py

@@ -75,7 +75,7 @@ eval_dataset = pdrs.datasets.VOCDetection(
 # 构建PP-YOLO模型
 # 目前已支持的模型请参考:https://github.com/PaddleCV-SIG/PaddleRS/blob/develop/docs/apis/model_zoo.md
 # 模型输入参数请参考:https://github.com/PaddleCV-SIG/PaddleRS/blob/develop/paddlers/tasks/object_detector.py
-model = pdrs.tasks.PPYOLO(num_classes=len(train_dataset.labels))
+model = pdrs.tasks.det.PPYOLO(num_classes=len(train_dataset.labels))
 
 # 执行模型训练
 model.train(

+ 1 - 1
tutorials/train/object_detection/ppyolotiny.py

@@ -75,7 +75,7 @@ eval_dataset = pdrs.datasets.VOCDetection(
 # 构建PP-YOLO Tiny模型
 # 目前已支持的模型请参考:https://github.com/PaddleCV-SIG/PaddleRS/blob/develop/docs/apis/model_zoo.md
 # 模型输入参数请参考:https://github.com/PaddleCV-SIG/PaddleRS/blob/develop/paddlers/tasks/object_detector.py
-model = pdrs.tasks.PPYOLOTiny(num_classes=len(train_dataset.labels))
+model = pdrs.tasks.det.PPYOLOTiny(num_classes=len(train_dataset.labels))
 
 # 执行模型训练
 model.train(

+ 1 - 1
tutorials/train/object_detection/ppyolov2.py

@@ -75,7 +75,7 @@ eval_dataset = pdrs.datasets.VOCDetection(
 # 构建PP-YOLOv2模型
 # 目前已支持的模型请参考:https://github.com/PaddleCV-SIG/PaddleRS/blob/develop/docs/apis/model_zoo.md
 # 模型输入参数请参考:https://github.com/PaddleCV-SIG/PaddleRS/blob/develop/paddlers/tasks/object_detector.py
-model = pdrs.tasks.PPYOLOv2(num_classes=len(train_dataset.labels))
+model = pdrs.tasks.det.PPYOLOv2(num_classes=len(train_dataset.labels))
 
 # 执行模型训练
 model.train(

+ 1 - 1
tutorials/train/object_detection/yolov3.py

@@ -75,7 +75,7 @@ eval_dataset = pdrs.datasets.VOCDetection(
 # 构建YOLOv3模型,使用DarkNet53作为backbone
 # 目前已支持的模型请参考:https://github.com/PaddleCV-SIG/PaddleRS/blob/develop/docs/apis/model_zoo.md
 # 模型输入参数请参考:https://github.com/PaddleCV-SIG/PaddleRS/blob/develop/paddlers/tasks/object_detector.py
-model = pdrs.tasks.YOLOv3(
+model = pdrs.tasks.det.YOLOv3(
     num_classes=len(train_dataset.labels), backbone='DarkNet53')
 
 # 执行模型训练

+ 1 - 1
tutorials/train/semantic_segmentation/deeplabv3p.py

@@ -66,7 +66,7 @@ eval_dataset = pdrs.datasets.SegDataset(
 # 构建DeepLab V3+模型,使用ResNet-50作为backbone
 # 目前已支持的模型请参考:https://github.com/PaddleCV-SIG/PaddleRS/blob/develop/docs/apis/model_zoo.md
 # 模型输入参数请参考:https://github.com/PaddleCV-SIG/PaddleRS/blob/develop/paddlers/tasks/segmenter.py
-model = pdrs.tasks.DeepLabV3P(
+model = pdrs.tasks.seg.DeepLabV3P(
     input_channel=NUM_BANDS,
     num_classes=len(train_dataset.labels),
     backbone='ResNet50_vd')

+ 1 - 1
tutorials/train/semantic_segmentation/unet.py

@@ -66,7 +66,7 @@ eval_dataset = pdrs.datasets.SegDataset(
 # 构建UNet模型
 # 目前已支持的模型请参考:https://github.com/PaddleCV-SIG/PaddleRS/blob/develop/docs/apis/model_zoo.md
 # 模型输入参数请参考:https://github.com/PaddleCV-SIG/PaddleRS/blob/develop/paddlers/tasks/segmenter.py
-model = pdrs.tasks.UNet(
+model = pdrs.tasks.seg.UNet(
     input_channel=NUM_BANDS, num_classes=len(train_dataset.labels))
 
 # 执行模型训练