Commit f069be37 authored by Jonas Müller's avatar Jonas Müller

fixed rotation during training

+ adaptions for testing
parent 13059763
Pipeline #178 canceled with stages
# Data dir
data/imgs/
data/results_imgs/
# Byte-compiled / optimized / DLL files
__pycache__/
......
No preview for this file type
20190507_113350.jpg,caries,1651,1403,2063,1651
20190510_114803.jpg,caries,743,1403,990,1651
20190510_114803.jpg,caries,2476,1733,2807,1898
20190510_114803.jpg,caries,2559,1733,2972,1898
20190523_095739.jpg,caries,412,990,825,1238
20190523_095739.jpg,caries,0,2724,247,3054
20190523_101812.jpg,caries,1486,1073,1651,1320
IMG_20190223_110731.jpg,caries,1379,328,1478,394
IMG_20190223_110731.jpg,caries,262,394,394,492
IMG_20190223_110731.jpg,caries,361,657,525,722
IMG_20190223_110731.jpg,caries,328,328,427,394
IMG_20190223_110731.jpg,caries,1281,689,1412,755
IMG_20190330_101819.jpg,caries,3455,2211,3732,2419
IMG_20190330_101819.jpg,caries,3179,967,3386,1244
IMG_20190330_101819.jpg,caries,3248,1451,3594,1797
IMG_20190330_101819.jpg,caries,1175,1105,1520,1313
IMG_20190330_101819.jpg,caries,1589,691,1935,967
IMG_20190330_101819.jpg,caries,3455,2142,3732,2350
IMG_20190404_123358.jpg,caries,829,3179,1105,3386
IMG_20190404_123358.jpg,caries,1036,2073,1313,2280
IMG_20190404_123358.jpg,caries,1105,3317,1382,3594
IMG_20190404_123358.jpg,caries,1451,2073,1727,2280
......@@ -56,4 +56,5 @@ class Config:
# https://github.com/fchollet/deep-learning-models/releases/download/v0.2/resnet50_weights_th_dim_ordering_th_kernels_notop.h5
# https://github.com/fchollet/deep-learning-models/releases/download/v0.2/resnet50_weights_tf_dim_ordering_tf_kernels_notop.h5
self.model_path = 'model_frcnn.vgg.hdf5'
#self.model_path = 'model_frcnn.vgg.hdf5'
self.model_path = 'data/model_frcnn.hdf5'
......@@ -11,7 +11,7 @@ def augment(img_data, config, augment=True):
img_data_aug = copy.deepcopy(img_data)
img = cv2.imread(img_data_aug['filepath'])
img = cv2.imread(img_data_aug['filepath'], cv2.IMREAD_IGNORE_ORIENTATION | cv2.IMREAD_COLOR)
if augment:
rows, cols = img.shape[:2]
......
......@@ -26,7 +26,10 @@ def get_map(pred, gt, f):
pred_probs = np.array([s['prob'] for s in pred])
box_idx_sorted_by_prob = np.argsort(pred_probs)[::-1]
# For each predicted box sorted by probabilty
for box_idx in box_idx_sorted_by_prob:
# Get bbox predicted data
pred_box = pred[box_idx]
pred_class = pred_box['class']
pred_x1 = pred_box['x1']
......@@ -34,25 +37,40 @@ def get_map(pred, gt, f):
pred_y1 = pred_box['y1']
pred_y2 = pred_box['y2']
pred_prob = pred_box['prob']
# If class was not predicted yet, create a new list for that class
if pred_class not in P:
P[pred_class] = []
T[pred_class] = []
# Add the predicted probability to P
P[pred_class].append(pred_prob)
# Set found match to False, meaning the prediction was not found yet on GT
found_match = False
# For each bbox in GT
for gt_box in gt:
# Get GT bbox data
gt_class = gt_box['class']
gt_x1 = gt_box['x1']/fx
gt_x2 = gt_box['x2']/fx
gt_y1 = gt_box['y1']/fy
gt_y2 = gt_box['y2']/fy
gt_seen = gt_box['bbox_matched']
# If the class does not match the predicted class, continue
if gt_class != pred_class:
continue
# If the bbox was already matched, continue
if gt_seen:
continue
# Else, check if IoU is greater than a value
iou = data_generators.iou((pred_x1, pred_y1, pred_x2, pred_y2), (gt_x1, gt_y1, gt_x2, gt_y2))
if iou >= 0.5:
# Set found_patch and bbox matched to true
found_match = True
gt_box['bbox_matched'] = True
break
......@@ -62,7 +80,8 @@ def get_map(pred, gt, f):
T[pred_class].append(int(found_match))
for gt_box in gt:
if not gt_box['bbox_matched'] and not gt_box['difficult']:
#if not gt_box['bbox_matched'] and not gt_box['difficult']:
if not gt_box['bbox_matched']:
if gt_box['class'] not in P:
P[gt_box['class']] = []
T[gt_box['class']] = []
......@@ -101,8 +120,9 @@ else:
raise ValueError("Command line option parser must be one of 'pascal_voc' or 'simple'")
config_output_filename = options.config_filename
print(config_output_filename)
with open(config_output_filename, 'r') as f_in:
with open(config_output_filename, 'rb') as f_in:
C = pickle.load(f_in)
# turn off any data augmentation at test time
......@@ -110,6 +130,9 @@ C.use_horizontal_flips = False
C.use_vertical_flips = False
C.rot_90 = False
#Fixing wrong path caused by different platforms
C.model_path = 'data/model_frcnn.hdf5'
img_path = options.test_path
......@@ -144,7 +167,7 @@ class_mapping = C.class_mapping
if 'bg' not in class_mapping:
class_mapping['bg'] = len(class_mapping)
class_mapping = {v: k for k, v in class_mapping.iteritems()}
class_mapping = {v: k for k, v in class_mapping.items()}
print(class_mapping)
class_to_color = {class_mapping[v]: np.random.randint(0, 255, 3) for v in class_mapping}
C.num_rois = int(options.num_rois)
......@@ -182,7 +205,8 @@ model_rpn.compile(optimizer='sgd', loss='mse')
model_classifier.compile(optimizer='sgd', loss='mse')
all_imgs, _, _ = get_data(options.test_path)
test_imgs = [s for s in all_imgs if s['imageset'] == 'test']
#test_imgs = [s for s in all_imgs if s['imageset'] == 'test']
test_imgs = all_imgs
T = {}
......@@ -192,7 +216,7 @@ for idx, img_data in enumerate(test_imgs):
st = time.time()
filepath = img_data['filepath']
img = cv2.imread(filepath)
img = cv2.imread(filepath, cv2.IMREAD_IGNORE_ORIENTATION | cv2.IMREAD_COLOR)
X, fx, fy = format_img(img, C)
......
......@@ -132,6 +132,8 @@ model_classifier_only = Model([feature_map_input, roi_input], classifier)
model_classifier = Model([feature_map_input, roi_input], classifier)
#Fixing wrong path caused by different platforms
C.model_path = 'data/model_frcnn.hdf5'
print('Loading weights from {}'.format(C.model_path))
model_rpn.load_weights(C.model_path, by_name=True)
model_classifier.load_weights(C.model_path, by_name=True)
......@@ -147,7 +149,7 @@ bbox_threshold = 0.8
visualise = True
output = open('data/output.txt','w')
output = open('data/test_output.txt','w')
for idx, img_name in enumerate(sorted(os.listdir(img_path))):
if not img_name.lower().endswith(('.bmp', '.jpeg', '.jpg', '.png', '.tif', '.tiff')):
......@@ -156,7 +158,7 @@ for idx, img_name in enumerate(sorted(os.listdir(img_path))):
st = time.time()
filepath = os.path.join(img_path,img_name)
img = cv2.imread(filepath)
img = cv2.imread(filepath, cv2.IMREAD_IGNORE_ORIENTATION | cv2.IMREAD_COLOR)
X, ratio = format_img(img, C)
......@@ -199,7 +201,7 @@ for idx, img_name in enumerate(sorted(os.listdir(img_path))):
continue
cls_name = class_mapping[np.argmax(P_cls[0, ii, :])]
print(cls_name)
#print(cls_name)
if cls_name not in bboxes:
bboxes[cls_name] = []
......@@ -235,7 +237,7 @@ for idx, img_name in enumerate(sorted(os.listdir(img_path))):
textLabel = '{}: {}'.format(key,int(100*new_probs[jk]))
all_dets.append((key,100*new_probs[jk]))
output.write(img_name+','+key+','+real_x1+','+real_y1+','+real_x2+','+real_y2+'\n')
output.write(img_name+','+key+','+str(real_x1)+','+str(real_y1)+','+str(real_x2)+','+str(real_y2)+'\n')
(retval,baseLine) = cv2.getTextSize(textLabel,cv2.FONT_HERSHEY_COMPLEX,1,1)
textOrg = (real_x1, real_y1-0)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment