Skip to content

Commit

Permalink
Patch for older YOLOV5 models and newest version of PyTorch
Browse files Browse the repository at this point in the history
  • Loading branch information
persts committed Sep 9, 2022
1 parent 9115795 commit b30b762
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 22 deletions.
22 changes: 0 additions & 22 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ git clone https://github.com/ultralytics/yolov5 YOLO5
python -m pip install -r YOLO5/requirements.txt
```

Downgrade the version of torch **See note below for newer verisons or M1 support
```bash
python -m pip install torch==1.10.1 torchvision==0.11.2
```

You need to add the YOLO5 to your PYTHONPATH
```bash
[Linux]
Expand All @@ -66,20 +61,3 @@ The [Colorado Parks and Wildlife use case](./UseCase) doubles as basic user guid

## M1 Support and Newer versions of PyTorch
If you want M1 support you will need PyTorch >= v1.13. At the time of writing this, that version is only available as a nighly build.

Newer versions of Torch will not work with MegaDetector, but the modification is relatively straight forward
```bash
edit the file
[VENV_PATH]/lib/python3.8/site-packages/torch/nn/modules/upsampling.py

Change the following function from:

def forward(self, input: Tensor) -> Tensor:
return F.interpolate(input, self.size, self.scale_factor, self.mode, self.align_corners,
recompute_scale_factor=self.recompute_scale_factor)

to:

def forward(self, input: Tensor) -> Tensor:
return F.interpolate(input, self.size, self.scale_factor, self.mode, self.align_corners)
```
4 changes: 4 additions & 0 deletions stage2_gen_bbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@

# Load model
checkpoint = torch.load('./md_v5a.0.0.pt')
# Patch for older YOLOV5 model
for m in checkpoint['model'].modules():
if type(m) is torch.nn.Upsample:
m.recompute_scale_factor = None
model = checkpoint['model'].float().fuse().eval().to(device)

# Pass each image through megadetector
Expand Down

0 comments on commit b30b762

Please sign in to comment.