def main(): args = get_args() logger = get_logger() logger.info(vars(args)) with tf.device("/gpu:0"): if args.densenet == True: model = DenseNet() else: model = CnnLstm() tfrecord = TFRecord() tfrecord.make_iterator(args.tfr_fname, training=False) total = sum(1 for _ in tf.python_io.tf_record_iterator(args.tfr_fname)) // tfrecord.batch_size saver = tf.train.Saver(tf.global_variables()) with tf.Session(config=tf.ConfigProto(allow_soft_placement=True)) as sess: saver.restore(sess, args.model_fname) sess.run(tfrecord.init_op) spec = tfrecord.load(sess, training=False) predict = model.predict(sess, spec, args.proba) progress_bar = tqdm(total=total, desc="[PREDICT]", unit="batch", leave=False) while True: try: spec = tfrecord.load(sess, training=False) if args.proba: predict = np.vstack([predict, model.predict(sess, spec, args.proba)]) else: predict = np.hstack([predict, model.predict(sess, spec, args.proba)]) progress_bar.update(1) except tf.errors.OutOfRangeError: break make_submission(predict, args.sample_fname, args.output_fname, args.proba) logger.info(f"{args.output_fname} is created.")
im = np.array(im) im = np.delete(im, [1, 2], axis=2) im = np.array(im) / 255.0 im = np.expand_dims(im, axis=0) print(im.shape) model = DenseNet(dense_blocks=5, dense_layers=-1, growth_rate=8, dropout_rate=0.2, bottleneck=True, compression=1.0, weight_decay=1e-4, depth=40) model.load_weights("outputs/model-230.h5") lmarks = model.predict(im) print(lmarks) lmarks = lmarks[0] lmarks[0:8:2] = lmarks[0:8:2] * im.shape[2] lmarks[1:8:2] = lmarks[1:8:2] * im.shape[1] print(lmarks) #print(lmarks) im = im[0] * 255 im = np.squeeze(im, axis=(2, )) print(im.shape) for m in range(0, 8, 2): cv2.circle(im, (int(lmarks[m]), int(lmarks[m + 1])), 5, (255, 255, 255), -1) plt.figure(1, figsize=(25, 25))