Classify training cleanup (#33)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Glenn Jocher
2022-11-07 00:15:57 +01:00
committed by GitHub
parent 2e9b18ce4e
commit 6fe8bead35
4 changed files with 29 additions and 31 deletions

View File

@ -1,25 +1,27 @@
model: null
data: null
# YOLO 🚀 by Ultralytics, GPL-3.0 license
# Default training settings and hyperparameters for medium-augmentation COCO training
# Training options
# Train settings -------------------------------------------------------------------------------------------------------
model: null # i.e. yolov5s.pt
data: null # i.e. coco128.yaml
epochs: 300
batch_size: 16
img_size: 640
nosave: False
cache: False # True/ram for ram, or disc
device: '' # cuda device, i.e. 0 or 0,1,2,3 or cpu
cache: False # True/ram, disk or False
device: '' # cuda device, i.e. 0 or 0,1,2,3 or cpu
workers: 8
project: "ultralytics-yolo"
name: "exp" # TODO: make this informative, maybe exp{#number}_{datetime} ?
project: 'runs'
name: 'exp'
exist_ok: False
pretrained: False
optimizer: "Adam" # choices=['SGD', 'Adam', 'AdamW', 'RMSProp']
optimizer: 'SGD' # choices=['SGD', 'Adam', 'AdamW', 'RMSProp']
verbose: False
seed: 0
local_rank: -1
#-----------------------------------#
# Hyper-parameters
# Hyperparameters ------------------------------------------------------------------------------------------------------
lr0: 0.001 # initial learning rate (SGD=1E-2, Adam=1E-3)
lrf: 0.01 # final OneCycleLR learning rate (lr0 * lrf)
momentum: 0.937 # SGD momentum/Adam beta1
@ -50,9 +52,8 @@ mosaic: 1.0 # image mosaic (probability)
mixup: 0.0 # image mixup (probability)
copy_paste: 0.0 # segment copy-paste (probability)
# Hydra configs -------------------------------------
# to disable hydra directory creation
# Hydra configs --------------------------------------------------------------------------------------------------------
hydra:
output_subdir: null
output_subdir: null # disable hydra directory creation
run:
dir: .

View File

@ -107,18 +107,17 @@ def parse_model(d, ch): # model_dict, input_channels(3)
return nn.Sequential(*layers), sorted(save)
def get_model(model: str):
def get_model(model='s.pt', pretrained=True):
# Load a YOLO model locally, from torchvision, or from Ultralytics assets
if model.endswith(".pt"):
model = model.split(".")[0]
if Path(model + ".pt").is_file():
trained_model = torch.load(model + ".pt", map_location='cpu')
elif model in torchvision.models.__dict__: # try torch hub classifier models
trained_model = torch.hub.load("pytorch/vision", model, pretrained=True)
else:
model_ckpt = attempt_download(model + ".pt") # try ultralytics assets
trained_model = torch.load(model_ckpt, map_location='cpu')
return trained_model
if Path(f"{model}.pt").is_file(): # local file
return torch.load(f"{model}.pt", map_location='cpu')
elif model in torchvision.models.__dict__: # TorchVision models i.e. resnet50, efficientnet_b0
return torchvision.models.__dict__[model](weights='IMAGENET1K_V1' if pretrained else None)
else: # Ultralytics assets
return torch.load(attempt_download(f"{model}.pt"), map_location='cpu')
def yaml_load(file='data.yaml'):