In [1]:
import tensorflow as tf
import numpy as np
from rcnn.simple_nn import build_rpn, build_shared
from rcnn.video_parser import get_data
from rcnn.data_generators import get_anchor, video_streamer
import pickle
from matplotlib import pyplot as plt
import os
In [2]:
os.environ['CUDA_VIDIBLE_DEVICES'] = '1'
In [3]:
from random import seed
seed(1234)
np.random.seed(1234)
In [4]:
data,_,_ = get_data('./videos/', './annotations/')
In [5]:
with open('config.pickle', 'rb') as f:
C = pickle.load(f)
In [6]:
data_gen = video_streamer(data, 2, C, lambda x,y: [x,y], 'tf', 'test')
In [7]:
x = next(data_gen)
In [8]:
x[1][0].shape
Out[8]:
In [9]:
plt.imshow(x[0][0,16])
plt.show()
In [10]:
num_anchors = len(C.anchor_box_ratios) * len(C.anchor_box_scales)
In [11]:
plt.imshow((x[1][0][0,16][...,:num_anchors]).sum(axis=-1))
plt.show()
In [12]:
x[1][1].shape
Out[12]:
In [13]:
sess = tf.Session()
In [14]:
video_input = tf.placeholder(tf.float32, [1, None, None, None, 3])
In [15]:
base = build_shared(video_input)
rpn = build_rpn(base, num_anchors)
In [16]:
saver = tf.train.Saver()
In [17]:
rpn[0] = tf.nn.sigmoid(rpn[0])
def predict_rpn(X):
return sess.run(rpn, {video_input:X})
In [21]:
saver.restore(sess, './save_dir/rpn_only.sv')
In [22]:
preds = predict_rpn(x[0])[0]
In [23]:
plt.imshow(preds[0,16].max(axis=-1), vmin=0, vmax=1)
plt.show()
In [45]:
preds[0,19].max(), preds[0,19].min(), preds[0,19].mean()
Out[45]:
In [30]:
x[1][0][...,num_anchors:].mean()
Out[30]:
In [17]:
preds.shape
Out[17]:
In [ ]:
In [286]:
class_mapping = C.class_mapping
In [280]:
P_rpn = predict_rpn(x[0])
In [281]:
P_rpn = list(map(lambda x: x[0,0][np.newaxis,...], P_rpn))
img_data = x[-1][0][0]
In [282]:
img_data
Out[282]:
In [283]:
from rcnn import roi_helpers
In [ ]:
In [287]:
R = roi_helpers.rpn_to_roi(P_rpn[0], P_rpn[1], C, 'tf', use_regr=True, overlap_thresh=0.7, max_boxes=300)
X2, Y1, Y2, IouS = roi_helpers.calc_iou(R, img_data, C, class_mapping)
In [272]:
P_rpn[0].shape
Out[272]:
In [289]:
X2.shape
Out[289]:
In [290]:
Y1.shape
Out[290]:
In [291]:
Y2.shape
Out[291]:
In [300]:
Y2
Out[300]:
In [ ]: