# RPN week13 實驗
## 1 epoch
train

val

time:
386
## 2 epoch
train

val

time:
703
# 4 epoch
train

val

time
1308.7086091041565
```python=
# IOU answer
def IOU_threshold(num_batch, label, max_ious_all, gt_argmax_ious_all):
pos_iou_threshold = 0.7
neg_iou_threshold = 0.3
label_all = []
for n in range(num_batch):
l = copy.deepcopy(label)
l[max_ious_all[n] < neg_iou_threshold] = 0
l[gt_argmax_ious_all[n]] = 1
l[max_ious_all[n] >= pos_iou_threshold] = 1
label_all.append(l)
#print ("label_all 0 and 1: ", sum(label_all[0]), sum(label_all[1]))
pos_ratio = 0.5
n_sample = 256
n_pos = int(pos_ratio * n_sample)
#print(n_pos)
for n in range(num_batch):
#print(np.sum((label_all[n] == 1)))
pos_index = np.where(label_all[n] == 1)[0]
#print(pos_index)
if len(pos_index) > n_pos:
disable_index = np.random.choice(pos_index, size=(len(pos_index) - n_pos), replace=False)
label_all[n][disable_index] = -1
#print(np.sum((label_all[n] == 1)))
n_neg = n_sample - np.sum(label_all[n] == 1)
neg_index = np.where(label_all[n] == 0)[0]
if len(neg_index) > n_neg:
disable_index = np.random.choice(neg_index, size=(len(neg_index) - n_neg), replace = False)
label_all[n][disable_index] = -1
#print(np.sum((label_all[n] == 0)))
return label_all
```
```python=
# Implementation 2: count GTBbox answer
def d_calculatrion(base_ctr_y_all, base_ctr_x_all, ctr_y, ctr_x, base_height_all, base_width_all, height, width, num_batch):
anchor_locs_all = []
for n in range(num_batch):
dy = (base_ctr_y_all[n].numpy() - ctr_y) / height
dx = (base_ctr_x_all[n].numpy() - ctr_x) / width
dh = np.log(base_height_all[n].numpy()/ height)
dw = np.log(base_width_all[n].numpy() / width)
anchor_locs_all.append(np.vstack((dy, dx,dh, dw)).transpose())
return anchor_locs_all
```
epoch4

epoch2
