# Load test set X_test, y_test = dataset.read_data(test_dir, IM_SIZE) test_set = dataset.DataSet(X_test, y_test) """ 2. Set test hyperparameters """ hp_d = dict() # FIXME: Test hyperparameters hp_d['batch_size'] = 8 """ 3. Build graph, load weights, initialize a session and start test """ # Initialize graph = tf.get_default_graph() config = tf.ConfigProto() config.gpu_options.allow_growth = True model = ConvNet([IM_SIZE[0], IM_SIZE[1], 3], NUM_CLASSES, **hp_d) evaluator = Evaluator() saver = tf.train.Saver() sess = tf.Session(graph=graph, config=config) saver.restore(sess, './model.ckpt') # restore learned weights test_y_pred = model.predict(sess, test_set, **hp_d) test_score = evaluator.score(test_set.labels, test_y_pred) print('Test accuracy: {}'.format(test_score)) """ 4. Draw masks on image """ draw_dir = os.path.join(test_dir, 'draws') # FIXME if not os.path.isdir(draw_dir): os.mkdir(draw_dir) im_dir = os.path.join(test_dir, 'images') # FIXME im_paths = []
IM_SIZE = (512, 512) NUM_CLASSES = 3 """ 2. Set test hyperparameters """ hp_d = dict() # FIXME: Test hyperparameters hp_d['batch_size'] = 1 """ 3. Build graph, load weights, initialize a session """ # Initialize graph = tf.get_default_graph() config = tf.ConfigProto() config.gpu_options.allow_growth = True model = ConvNet([IM_SIZE[0], IM_SIZE[1], 3], NUM_CLASSES, **hp_d) saver = tf.train.Saver() sess = tf.Session(graph=graph, config=config) saver.restore(sess, './model.ckpt') # restore learned weights capture = cv2.VideoCapture(0) capture.set(cv2.CAP_PROP_FRAME_WIDTH, 512) capture.set(cv2.CAP_PROP_FRAME_HEIGHT, 512) while True: ret, frame = capture.read() resize = cv2.resize(frame, dsize=(512, 512), interpolation=cv2.INTER_AREA) test_y_pred = model.predict_video(sess, [resize, ], **hp_d)