yjh0410 11 月之前
父節點
當前提交
eb8e9e42d0
共有 3 個文件被更改,包括 60 次插入9 次删除
  1. 3 7
      yolo/dataset/data_augment/yolo_augment.py
  2. 2 2
      yolo/dataset/voc.py
  3. 55 0
      yolo/models/yolov3/README.md

+ 3 - 7
yolo/dataset/data_augment/yolo_augment.py

@@ -158,7 +158,7 @@ class YOLOAugmentation(object):
             target["boxes"] = boxes
 
         # --------------- To torch.Tensor ---------------
-        image = F.to_tensor(image) * 255.
+        image = torch.as_tensor(image).permute(2, 0, 1).contiguous()
         if target is not None:
             target["boxes"] = torch.as_tensor(target["boxes"]).float()
             target["labels"] = torch.as_tensor(target["labels"]).long()
@@ -203,7 +203,7 @@ class YOLOBaseTransform(object):
             target["boxes"][..., [1, 3]] = target["boxes"][..., [1, 3]] / orig_h * img_h
 
         # --------------- To torch.Tensor ---------------
-        image = F.to_tensor(image) * 255.
+        image = torch.as_tensor(image).permute(2, 0, 1).contiguous()
         if target is not None:
             target["boxes"] = torch.as_tensor(target["boxes"]).float()
             target["labels"] = torch.as_tensor(target["labels"]).long()
@@ -228,7 +228,7 @@ class YOLOBaseTransform(object):
 
 if __name__ == "__main__":
     image_path = "voc_image.jpg"
-    is_train = False
+    is_train = True
 
     affine_params = {
         'degrees': 0.0,
@@ -247,16 +247,12 @@ if __name__ == "__main__":
                                        affine_params=affine_params,
                                        pixel_mean=[0., 0., 0.],
                                        pixel_std=[255., 255., 255.],
-                                       box_format="xyxy",
-                                       normalize_coords=False,
                                        )
     else:
         ssd_augment = YOLOBaseTransform(img_size=416,
                                         max_stride=32,
                                         pixel_mean=[0., 0., 0.],
                                         pixel_std=[255., 255., 255.],
-                                        box_format="xyxy",
-                                        normalize_coords=False,
                                         )
     
     # 读取图像数据

+ 2 - 2
yolo/dataset/voc.py

@@ -213,8 +213,8 @@ if __name__ == "__main__":
             self.box_format = 'xywh'
             self.normalize_coords = False
             self.mosaic_prob = 1.0
-            self.mixup_prob  = 0.15
-            self.copy_paste  = 0.3
+            self.mixup_prob  = 0.0
+            self.copy_paste  = 1.0
             ## Pixel mean & std
             self.pixel_mean = [0., 0., 0.]
             self.pixel_std  = [255., 255., 255.]

+ 55 - 0
yolo/models/yolov3/README.md

@@ -0,0 +1,55 @@
+# Redesigned YOLOv3:
+
+- VOC
+
+|   Model  | Batch | Scale | AP<sup>val<br>0.5 | Weight |
+|----------|-------|-------|-------------------|--------|
+|  YOLOv3  | 1xb16 |  640  |               | [ckpt](https://github.com/yjh0410/YOLO-Tutorial-v2/releases/download/yolo_tutorial_ckpt/yolov3_voc.pth) |
+
+- COCO
+
+|  Model  | Batch | Scale | AP<sup>val<br>0.5:0.95 | AP<sup>val<br>0.5 | FLOPs<br><sup>(G) | Params<br><sup>(M) | Weight |
+|---------|-------|-------|------------------------|-------------------|-------------------|--------------------|--------|
+| YOLOv3  | 1xb16 |  640  |                    |               |               |                 | [ckpt](https://github.com/yjh0410/YOLO-Tutorial-v2/releases/download/yolo_tutorial_ckpt/yolov3_coco.pth) |
+
+
+## Train YOLOv3
+### Single GPU
+Taking training YOLOv3-S on COCO as the example,
+```Shell
+python train.py --cuda -d coco --root path/to/coco -m yolov3 -bs 16 --fp16 
+```
+
+### Multi GPU
+Taking training YOLOv3-S on COCO as the example,
+```Shell
+python -m torch.distributed.run --nproc_per_node=8 train.py --cuda --distributed -d coco --root path/to/coco -m yolov3 -bs 16 --fp16 
+```
+
+## Test YOLOv3
+Taking testing YOLOv3-S on COCO-val as the example,
+```Shell
+python test.py --cuda -d coco --root path/to/coco -m yolov3 --weight path/to/yolov3.pth --show 
+```
+
+## Evaluate YOLOv3
+Taking evaluating YOLOv3-S on COCO-val as the example,
+```Shell
+python eval.py --cuda -d coco --root path/to/coco -m yolov3 --weight path/to/yolov3.pth 
+```
+
+## Demo
+### Detect with Image
+```Shell
+python demo.py --mode image --path_to_img path/to/image_dirs/ --cuda -m yolov3 --weight path/to/weight --show
+```
+
+### Detect with Video
+```Shell
+python demo.py --mode video --path_to_vid path/to/video --cuda -m yolov3 --weight path/to/weight --show --gif
+```
+
+### Detect with Camera
+```Shell
+python demo.py --mode camera --cuda -m yolov3 --weight path/to/weight --show --gif
+```