def calc_basic_test(): band_7_test = utils.get_truth(get_swir2(), 0.03, '>') btc_test = utils.get_truth(utils.convert_to_celsius(get_temp()), 27.0, '<') ndsi_test = utils.get_truth(calc_ndsi(), 0.8, '<') ndvi_test = utils.get_truth(calc_ndvi(), 0.8, '<') basic_test = np.logical_and.reduce((band_7_test, btc_test, ndsi_test, ndvi_test)) return basic_test
print 'sideoutput:', img_path, MSE_loss MSE_loss_list.append(MSE_loss) if save_test_img: pred_img = cv2.resize(new_Image.astype(np.uint8), (ROI_img.shape[1], ROI_img.shape[0])) tmp_img = pred_img.copy() tmp_ROI_img = ROI_img.copy() pred_img[pred_img==3]=2 pred_img[NucluesImage==1]=3 ROI_img = crop_boundry(ROI_img, pred_img) alpha_img = ori_img.copy() alpha_img[BeginY:, ally[0]:ally[1]] = ROI_img ROI_img = cv2.addWeighted(alpha_img, 0.4, ori_img, 0.6, 0) ## imshow the truth ROI_img = get_truth(ROI_img, img_path, ally, BeginY) if not os.path.exists(os.path.join(args.results,model_name)): os.mkdir(os.path.join(args.results,model_name)) img_path2 = img_path[:-4] + '_ray.png' save_name = os.path.join(args.results,model_name, img_path2) cv2.imwrite(save_name, ROI_img) FullImage = np.zeros(imshape) FinalShape = FinalShape * 1 pred_imgFinal = pred_img FullImage[BeginY:, ally[0]:ally[1]] = pred_imgFinal a = np.zeros(imshape) tmp_label = FullImage.copy() # with open('./logs/data/%s_ray.pkl'%img_path, 'w+') as f: # data = [a, tmp_label, img_path, ally] # pkl.dump(data, f)
new_Image = ppi.astype(np.uint8) kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (3, 3)) new_Image = cv2.morphologyEx(new_Image, cv2.MORPH_CLOSE, kernel) ori_img_path = os.path.join(ori_data, path) ori_img = cv2.imread(ori_img_path) ROI_img = ori_img[top:, left:right, :].copy() pred_img = cv2.resize(new_Image.astype(np.uint8), (ROI_img.shape[1], ROI_img.shape[0]), interpolation=cv2.INTER_LANCZOS4) ROI_img = crop_boundry(ROI_img, pred_img) alpha_img = ori_img.copy() alpha_img[top:, left:right] = ROI_img ROI_img = cv2.addWeighted(alpha_img, 0.4, ori_img, 0.6, 0) try: ROI_img = get_truth(ROI_img, path, [left, right], top) except: print path if not os.path.exists('./visual_results/%s' % model_name): os.mkdir('./visual_results/%s' % model_name) save_name = './visual_results/%s/label_%s_%s.png' % (model_name, epoch, i) cv2.imwrite(save_name, ROI_img) MSE_loss = None if not os.path.exists('./models/%s' % model_name): os.mkdir('./models/%s' % model_name) if args.test_every_step: start = time.time() print("Begining test ")
def calc_whiteness_test(): whiteness_test = utils.get_truth(calc_whiteness(), 0.7, '<') # 0.7 in paper return whiteness_test
del pos_list, pos_lab, neg_list, neg_lab # hog_par = {'winStride': (8, 8), 'padding': (0, 0), 'scale': 1.2} # hog_par = {'hitThreshold': 1.2, 'winStride': (8, 8), 'padding': (0, 0), 'scale': 1.2, 'finalThreshold': 4} hog_par = {'hitThreshold': 1.4, 'winStride': (8, 8), 'padding': (0, 0), 'scale': 1.2, 'finalThreshold': 2} """Initialize and train the SVM""" x, y = utils.get_data(hog_list) del hog_list svm_par = dict(kernel_type=cv2.SVM_LINEAR, svm_type=cv2.SVM_C_SVC) # svm_par = dict(kernel_type=cv2.SVM_LINEAR, svm_type=cv2.SVM_C_SVC, C=0.01) svm_vec = utils.load_svm("svm.pickle", x, y, svm_par) # svm_vec = cv2.HOGDescriptor_getDefaultPeopleDetector() hog_obj.setSVMDetector(np.array(svm_vec)) """Ground truth""" true_detection_list = utils.get_truth('view8.json') n_frame = len(true_detection_list) """Multi-scale detector on the video""" hog_detection_list = [] frm_list = utils.get_frame(frm_path) frm_list = frm_list[0:n_frame] i = -1 for frm in frm_list: i += 1 found_true = true_detection_list[i] found_filtered = [] found, w = hog_obj.detectMultiScale(frm, **hog_par) for r in found: inside = False for q in found:
new_Image = ppi.astype(np.uint8) kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (3, 3)) new_Image = cv2.morphologyEx(new_Image, cv2.MORPH_CLOSE, kernel) ori_img_path = os.path.join(ori_data, path) ori_img = cv2.imread(ori_img_path) ROI_img = ori_img[top:, left:right, :].copy() pred_img = cv2.resize(new_Image.astype(np.uint8), (ROI_img.shape[1], ROI_img.shape[0]), interpolation=cv2.INTER_LANCZOS4) ROI_img = crop_boundry(ROI_img, pred_img) alpha_img = ori_img.copy() alpha_img[top:, left:right] = ROI_img ROI_img = cv2.addWeighted(alpha_img, 0.4, ori_img, 0.6, 0) ROI_img = get_truth(ROI_img, path, [left, right], top) if not os.path.exists('./visual_results/%s' % model_name): os.mkdir('./visual_results/%s' % model_name) save_name = './visual_results/%s/label_%s_%s.png' % (model_name, epoch, i) cv2.imwrite(save_name, ROI_img) MSE_loss = None if not os.path.exists('./models/%s' % model_name): os.mkdir('./models/%s' % model_name) if epoch and epoch % 10 == 0: torch.save(model.state_dict(), './models/%s/%s_%s.pth' % (model_name, epoch, args.lr)) print 'success save every step model'
'hitThreshold': 1.4, 'winStride': (8, 8), 'padding': (0, 0), 'scale': 1.2, 'finalThreshold': 2 } """Initialize and train the SVM""" x, y = utils.get_data(hog_list) del hog_list svm_par = dict(kernel_type=cv2.SVM_LINEAR, svm_type=cv2.SVM_C_SVC) # svm_par = dict(kernel_type=cv2.SVM_LINEAR, svm_type=cv2.SVM_C_SVC, C=0.01) svm_vec = utils.load_svm("svm.pickle", x, y, svm_par) # svm_vec = cv2.HOGDescriptor_getDefaultPeopleDetector() hog_obj.setSVMDetector(np.array(svm_vec)) """Ground truth""" true_detection_list = utils.get_truth('view8.json') n_frame = len(true_detection_list) """Multi-scale detector on the video""" hog_detection_list = [] frm_list = utils.get_frame(frm_path) frm_list = frm_list[0:n_frame] i = -1 for frm in frm_list: i += 1 found_true = true_detection_list[i] found_filtered = [] found, w = hog_obj.detectMultiScale(frm, **hog_par) for r in found: inside = False for q in found: if utils.is_inside(r, q):