MCPcopy Create free account
hub / github.com/Mattdl/ContinualPrototypeEvolution / life_experience

Function life_experience

main.py:330–380  ·  view source on GitHub ↗
(model, continuum, x_te, args)

Source from the content-addressed store, hash-verified

328
329
330def life_experience(model, continuum, x_te, args):
331 current_task = 0
332 time_start = time.time()
333
334 for (i, (x, t, y)) in enumerate(continuum):
335 if t > args.tasks_to_preserve:
336 print("Aborting: task exceeds task {}".format(args.tasks_to_preserve))
337 break
338 if (((i % args.log_every) == 0) or (t != current_task)):
339 tot_res_seq, tot_avg_acc, task_res_seq, task_avg_acc = eval_tasks(model, x_te, current_task, args)
340 args.tracker.update(current_task, tot_res_seq, tot_avg_acc, task_res_seq, task_avg_acc)
341
342 if hasattr(model, "mem_update_scheme"):
343 model.mem_update_scheme.print_mem_stats()
344 if hasattr(model, "lossFunc"):
345 model.lossFunc.tracker['log_it'].append(i) # For loss tracking history
346 model.log = True
347 if args.visual and args.visual_chkpt == 'log':
348 plot.plot_featspace(args.visual, continuum.data, x_te, model, current_task, i,
349 save_img_path=args.imgname)
350 current_task = t
351
352 v_x = x.view(x.size(0), -1)
353 v_y = y.long()
354
355 if args.cuda:
356 v_x = v_x.cuda()
357 v_y = v_y.cuda()
358
359 model.train()
360 model.observe(v_x, t, v_y)
361 model.log = False
362
363 # Append final accs (after log_every)
364 tot_res_seq, tot_avg_acc, task_res_seq, task_avg_acc = eval_tasks(model, x_te, args.tasks_to_preserve, args)
365 args.tracker.update(current_task, tot_res_seq, tot_avg_acc, task_res_seq, task_avg_acc)
366 args.tracker.to_tensor()
367
368 if hasattr(model, "mem_update_scheme"):
369 model.mem_update_scheme.print_mem_stats()
370 if args.visual and args.visual_chkpt in ['log', 'final']:
371 plot.plot_featspace(args.visual, continuum.data, x_te, model, current_task, "FINAL({})".format(len(continuum)),
372 save_img_path=args.imgname)
373
374 # Get results on memories
375 res_on_mem = eval_on_memory(args, model)
376
377 time_end = time.time()
378 time_spent = time_end - time_start
379
380 return args.tracker, res_on_mem, time_spent
381
382
383def get_model(args, n_inputs, n_outputs):

Callers 1

mainFunction · 0.85

Calls 6

eval_tasksFunction · 0.85
eval_on_memoryFunction · 0.85
updateMethod · 0.80
print_mem_statsMethod · 0.80
to_tensorMethod · 0.80
observeMethod · 0.45

Tested by

no test coverage detected