-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Apple M1 Support #64
Comments
Hmmm... that's not what we want. I don't have an M1 Mac to test on, but this thread looks promising: It seems like maybe running: conda install nomkl ...prior to any other package installations (but from within the target conda environment) will fix this. Assuming you're installing from from environment-detector-mac.yml, can you try adding "nomkl" somewhere near the top of that file? If that works, that's a good solution and we'll update the instructions. If that doesn't work, that doesn't necessarily mean that "nomkl" isn't a good approach; I don't think in-order installation is guaranteed from a conda environment file, so we may need to do some more experimenting. But that's a good first debugging step. Mind giving that a try? Thanks! (Comment originally posted by agentmorris) |
Progressed past the initial mentioned issue
and
Output now looks like this:
This error is mentioned here ultralytics/yolov5#6948 within yolov5. @agentmorris is this why a specific commit of yolov5 is mentioned? I have tried each permutation of the following with the same result:
Any ideas or something i am overlooking? (Comment originally posted by sim-kelly) |
This issue is why we install a specific version of PyTorch, actually. At the time we released MDv5, even the newest commits to YOLOv5 had this issue when running against the newest version of PyTorch. Our use of a specific YOLOv5 commit is just future-proofing. I don't know that anything would stop working if you used the most recent YOLOv5 commit, but just to minimize the number of variables, I recommend sticking with the recommended commit. So I think what's happening here is that when you pip installed PyTorch (after installing nomkl), you installed the latest version. Can you install pytorch 1.10.1 and torchvision 0.11.2 and see what happens? (Comment originally posted by agentmorris) |
Closing due to inactivity, but let us know if you're able to make nomkl work by checking out the recommended PyTorch version. Thanks! (Comment originally posted by agentmorris) |
For Apple M1 support you will need the following:
Creating an updated version of MDv5 is pretty easy and will make the model available to newer versions of PyTorch on all platforms by removing the upsample problem. Set up a new virtual environment with the latest versions of PyTorch and YOLOv5 Follow the YOLOv5 instructions for organizing directories Training Custom Data but only include one image and one label. Then "fine-tune" the current mdv5a.0.0.pt model with all layers frozen: My dataset.yaml :
The resulting model will be usable on all platforms with the latest versions of PyTorch. *NOTE: training can not be done on the M1 (Comment originally posted by persts) |
We are frustratingly close to not having to deal with several of these issues: the Upsample issue appears to have been resolved when using the latest YOLOv5 and the latest stable build of PyTorch (1.12); i.e. you can use "vanilla MD" with the latest PyTorch version. We're not updating our recommended environment yet, mostly because we don't want to rock the boat and what we have is working, but for those who have a specific reason to use the latest stable PyTorch build or the latest YOLOv5, I've confirmed that this works. However, the latest nightly build of PyTorch (1.13) still has the Upsample issue, and 1.13 is what's required for M1 support. Grrr. So to use M1 support, you'll still need a custom MegaDetector and the nightly PT build. But I just merged Peter's PR to add M1 inference support, as well as a new environment-detector-m1.yml file that is identical to environment-detector-mac.yml, except that "nomkl" has been added. For now, this isn't "officially" supported, but this issue will serve as documentation for adventurous folks who want to try this. Get the latest CameraTraps repoThese instructions assume you have a recent version of our repo... i.e., go into your CameraTraps folder (c:\git\CameraTraps if you copied and pasted our "standard" instructions), and run:
Get the latest YOLOv5 repoWe can't say that "latest" will always be correct, but for now (September 2022), "latest" works here, but the YOLOv5 commit (c23a441c9df7ca9b1f275e8c8719c949269160d1 ) that we recommend for "standard" MD use does not work. So, if you've already checked out the old commit, head into your YOLOv5 folder and run:
If and when M1 inference becomes "officially supported", we'll pin a new commit that we've tested thoroughly. For now, just go with latest. Re-build MD for the latest YOLOv5 (or download unofficial re-builds)Peter's instructions were excellent, I trained one epoch on one image with all layers frozen. My dataset.yml looked like this:
And the only files in /home/user/train were one image from Snapshot Serengeti and the corresponding .txt file. It looks like you cannot train on only one negative image, there must be at least one bounding box. FYI the image I used is here and the bbox file is here. I ran:
...and ditto for MDv5b. I compared the output to "stock" MDv5a, and I really want them to be exactly the same. Boxes appear to be the same to around two decimal places in both location and confidence, which is good, but I would feel better if they were exactly the same. I also tried opening up data/hyp/*.yml, where YOLOv5 stores its hyperparameters, and setting all learning rates to zero. This resulted in... slightly different numbers, but off by about the same (very small) amount. This is the main reason this will remain unofficial for now, but for folks who are dying to get around this Upsample issue, here are my re-built MDv5a and MDv5b files. YMMV. Set up the M1 inference environmentOnly very slight variations to Sam's instructions earlier on this issue:
(Comment originally posted by agentmorris) |
@agentmorris, I tried using your suggested solution for an Apple M1:
and get this error:
Any ideas how to proceed? (Comment originally posted by gerlis22) |
Are you using the specific YOLOv5 commit (c23a441c9df7ca9b1f275e8c8719c949269160d1) that we recommend for a "standard" MegaDetector setup? If so, I'm about 65% sure this is the issue: for the accelerated M1 setup, you'll need a newer version of YOLOv5. I.e., in your YOLOv5 repo folder, run: git checkout master My bad, I should have clarified this above as well. If this works, can you confirm here, and I'll update the instructions? (Comment originally posted by agentmorris) |
Yes, indeed was using YOLOv5 commit (c23a441c9df7ca9b1f275e8c8719c949269160d1). I updated to commit(489920ab30b217fed14d3ddd31c23e9afc5be238) and works now. Thanks! (Comment originally posted by gerlis22) |
Excellent, I added a section to my post earlier on this issue. (Comment originally posted by agentmorris) |
@agentmorris I ran (Comment originally posted by gerlis22) |
I connected with @gerliss22 offline; it turns out that the discrepancy was between MDv5a and MDv5b (which is fine), not between run_detector.py and run_detector_batch.py (which would be a catastrophe). So, no cause for alarm here, but thanks to @gerlis22 for checking on this, always better to ask! (Comment originally posted by agentmorris) |
Thanks for the great work. Just in case anyone else gets stuck where I was for the past hours. Since torch 0.13 is released now, I changed the diff --git a/environment-detector-m1.yml b/environment-detector-m1.yml
index 13979af..ad7050e 100644
--- a/environment-detector-m1.yml
+++ b/environment-detector-m1.yml
@@ -27,8 +27,8 @@ dependencies:
- pandas
- seaborn>=0.11.0
- PyYAML>=5.3.1
- # - pytorch::pytorch=1.10.1
- # - pytorch::torchvision=0.11.2
+ - pytorch::pytorch=1.13.1
+ - pytorch::torchvision=0.14.1
# - conda-forge::cudatoolkit=11.3
# - conda-forge::cudnn=8.1 Then to install:
And it results in:
In this case, the fix is (to RTFM....) download @agentmorris's patched models above. I got confused because it gave me this error rather than the "advertised" Upsampling error.
(Comment originally posted by reinhrst) |
See issue 72 where Peter suggests this change:
|
Finally closing this issue and adopting Peter's recommended change! |
Hi All - very excited about this release!
I know this is probably deep down in the dependencies but wanted to raise given that M1 chips are becoming more common and that Mac instructions are given in the README.
The following error occurred running run_detector.py
Issue cloned from Microsoft/CameraTraps, original issue posted by sim-kelly on Jun 23, 2022.
The text was updated successfully, but these errors were encountered: