Skip to content
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

Add download_weights.py #46

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Also have a look at the other installing method, if you want to use the commands
#### Download pretrained weights

```bash
./weights/download_weights.sh
poetry run yoeo-download-weights
```

## Test
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ build-backend = "poetry.core.masonry.api"
yoeo-detect = "yoeo.detect:run"
yoeo-train = "yoeo.train:run"
yoeo-test = "yoeo.test:run"
yoeo-download-weights = "scripts.download_weights:run"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this really work? Script seems like a non install directory, as it is not in the package.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TDB lets test this with a clean install

32 changes: 32 additions & 0 deletions scripts/download_weights.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env python3
import os
import pathlib
import argparse
import urllib.request


def run():
parser = argparse.ArgumentParser(description='Download YOEO pretrained weights')
parser.add_argument(
'--output',
'-o',
type=pathlib.Path,
default='weights/yoeo.pth',
help='The pretrained weights file (.pth) will be written to this path. Defaults to "weights/yoeo.pth"',
)
args = parser.parse_args()

url = "https://data.bit-bots.de/models/2021_12_06_flo_torso21_yoeo_7/yoeo.pth"
output_path = args.output

with urllib.request.urlopen(url) as input_file:
try:
with open(output_path, 'xb') as output_file:
print(f"Saving pretrained weights to: {output_path}")
output_file.write(input_file.read())
except FileExistsError as e:
print(f"ERROR: The output file {output_path} does already exist. Will abort and not overwrite.")


if __name__ == '__main__':
run()
9 changes: 0 additions & 9 deletions weights/download_weights.sh

This file was deleted.