-
-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
coco dataset support, automatic aws weight upload (#54)
* ignore neptune logs * ignore neptune logs * add s3 weight upload to readme * add s3 file upload util * integrate automatic s3 upload * add missing boto3 requirement * update logging * better exception handling * update s3 weight dir * add coco styled data support for training * add sahi dependency * update sahi version * fix wandb logging error * fix category based ap logging * minor fix
- Loading branch information
Showing
8 changed files
with
142 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,3 +36,7 @@ seaborn>=0.11.0 | |
thop # FLOPs computation | ||
# CLI | ||
fire | ||
# AWS | ||
boto3>=1.19.1 | ||
# coco to yolov5 conversion | ||
sahi>=0.8.8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import os | ||
from pathlib import Path | ||
import logging | ||
import boto3 | ||
from botocore.exceptions import NoCredentialsError | ||
from yolov5.utils.general import colorstr | ||
|
||
|
||
AWS_ACCESS_KEY_ID = os.getenv("AWS_ACCESS_KEY_ID") | ||
AWS_SECRET_ACCESS_KEY = os.environ.get("AWS_SECRET_ACCESS_KEY") | ||
|
||
LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
def parse_s3_uri(s3_uri): | ||
# strip 's3://' | ||
if s3_uri.startswith("s3://"): | ||
s3_uri = s3_uri[5:] | ||
# parse bucket and key | ||
s3_components = s3_uri.split("/") | ||
bucket = s3_components[0] | ||
s3_key = "" | ||
if len(s3_components) > 1: | ||
s3_key = "/".join(s3_components[1:]) | ||
return bucket, s3_key | ||
|
||
def upload_file_to_s3(local_file, s3_dir, s3_file): | ||
s3 = boto3.client('s3', aws_access_key_id=AWS_ACCESS_KEY_ID, | ||
aws_secret_access_key=AWS_SECRET_ACCESS_KEY) | ||
# parse s3 uri | ||
bucket, s3_key = parse_s3_uri(s3_dir) | ||
# upload to s3 | ||
try: | ||
s3_path = str(Path(s3_key) / s3_file) | ||
s3.upload_file(local_file, bucket, s3_path) | ||
return True | ||
except FileNotFoundError: | ||
print(f"{colorstr('aws:')} S3 upload failed because local file not found: {local_file}") | ||
return False | ||
except NoCredentialsError: | ||
print(f"{colorstr('aws:')} AWS credentials are not set. Please configure aws via CLI or set required ENV variables.") | ||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters