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

Clear Cuda cache before training loop and validate loop starts #835

Open
wants to merge 2 commits into
base: master
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: 2 additions & 0 deletions imageai/Detection/Custom/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ def trainModel(self) -> None:
os.makedirs(self.__output_models_dir, exist_ok=True)
os.makedirs(self.__output_json_dir, exist_ok=True)

torch.cuda.empty_cache()

mp, mr, map50, map50_95, best_fitness = 0, 0, 0, 0, 0.0
nbs = 64 # norminal batch size
nb = len(self.__train_loader) # number of batches
Expand Down
10 changes: 6 additions & 4 deletions imageai/Detection/Custom/yolo/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@ def run(model, val_dataloader, num_class, net_dim=416, nms_thresh=0.6, objectnes
iouv = torch.linspace(0.5, 0.95, 10).to(device) # iou vector for [email protected]:0.95
niou = iouv.numel()

p, r, f1, mp, mr, map50, map = 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
stats, ap, ap_class = [], [], []
torch.cuda.empty_cache()

mp, mr, map50, map = 0.0, 0.0, 0.0, 0.0
stats, ap = [], []

for batch_i, (im, targets) in tqdm(enumerate(val_dataloader)):
for im, targets in tqdm(val_dataloader):
im = im.to(device)
targets = targets.to(device)
nb = im.shape[0] # batch
Expand Down Expand Up @@ -108,7 +110,7 @@ def run(model, val_dataloader, num_class, net_dim=416, nms_thresh=0.6, objectnes
# Compute metrics
stats = [np.concatenate(x, 0) for x in zip(*stats)] # to numpy
if len(stats) and stats[0].any():
p, r, ap, f1, ap_class = ap_per_class(*stats)
p, r, ap, _, _ = ap_per_class(*stats)
ap50, ap = ap[:, 0], ap.mean(1) # [email protected], [email protected]:0.95
mp, mr, map50, map = p.mean(), r.mean(), ap50.mean(), ap.mean()

Expand Down