if args.resume: print('==> Resuming from checkpoint..') checkpoint = torch.load('./checkpoint/' + args.network) net = checkpoint['net'] top1_acc = checkpoint['top1_acc'] top5_acc = checkpoint['top5_acc'] else: net = mobilenetv2() best_acc = 0 #For pruning and quantization elif args.mode == 2: checkpoint = torch.load('./checkpoint/' + args.network) net = checkpoint['net'] params = utils.paramsGet(net) thres = utils.findThreshold(params, args.pr) mask_prune = utils.getPruningMask(net, thres) if args.resume: print('==> Resuming from checkpoint..') best_acc = 0 else: best_acc = 0 if use_cuda: net.cuda() net = torch.nn.DataParallel(net, device_ids=range(torch.cuda.device_count())) cudnn.benchmark = True criterion = nn.CrossEntropyLoss()
blinks = [] nblinks = 0 blink_counter = 0 window_sum = 0 window_count = 0 # Writing the result in a video stream out = cv2.VideoWriter('result.avi', cv2.VideoWriter_fourcc(*'XVID'), 29.0, (int(cap.get(3)), int(cap.get(4)))) df = pd.DataFrame() print('thresholdng...') while True: s, frame = cap.read() if frame is None: break gray_f = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) gray_f = cv2.GaussianBlur(gray_f, (5, 5), 0) # to reduce noise threshold, threshold_flag = findThreshold(gray_f) if threshold_flag: print(f'Threshold is done! \n threshold is {threshold}') break # Once thresholding is done, start processing the video on the calculated threshold while True: s, frame = cap.read() if frame is None: break gray_f = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) gray_f = cv2.GaussianBlur(gray_f, (5, 5), 0) h, w, = gray_f.shape