def imgs_to_out(path): save_log = os.path.join('train_log', '3') save_folder = os.path.join(save_log, 'models') img_names = os.listdir(path) config = tf.ConfigProto() config.gpu_options.allow_growth = True with tf.Session(config=config) as sess: r_net = R_Net.R_Net() o_net = O_Net.O_Net() img = tf.placeholder(tf.float32, [None, None, None, 3]) r_output = r_net.pr(img) o_output = o_net.pr(img) model_pr = tf.train.Saver() model_pr.restore( sess, os.path.join(save_folder, str(4000) + 'save_net.ckpt')) initialize_uninitialized(sess) imgs = [Image.open(os.path.join(path, i)) for i in img_names] imgs = [padding_img_rect(i) for i in imgs] p_imgs = [np.array(i.resize((24, 24), Image.BILINEAR)) for i in imgs] r_out = sess.run(r_output, feed_dict={img: p_imgs}) n_r_crops = [] n_imgs = [] n_ori_img = [] for i in range(r_out.shape[0]): n_out = r_out[i] n_ori_img.append(imgs[i]) n_crops = [n_out[2], n_out[3], n_out[4], n_out[5]] n_r_crops.append(n_crops) im1 = Image.fromarray(p_imgs[i]).crop(n_crops) im1 = padding_img_rect(im1) im1 = im1.resize([48, 48], Image.BILINEAR) n_imgs.append(np.array(im1)) o_out = sess.run(o_output, feed_dict={img: n_imgs}) for i in range(o_out.shape[0]): output_p = o_out[i, :] img_show = n_ori_img[i] draw = ImageDraw.Draw(img_show) labeln = output_p[2:] labeln = [ j * (n_r_crops[i][2] - n_r_crops[i][0]) / 48 for j in labeln ] labeln = [ k + n_r_crops[i][int(j % 2)] for j, k in enumerate(labeln) ] labeln = [j / 24 * max(img_show.size) for j in labeln] draw.rectangle(((labeln[0], labeln[1]), (labeln[2], labeln[3])), outline='black') draw.ellipse( (labeln[4] - 2, labeln[5] - 2, labeln[4] + 2, labeln[5] + 2), fill='blue') draw.ellipse( (labeln[6] - 2, labeln[7] - 2, labeln[6] + 2, labeln[7] + 2), fill='red') img_show.show()
default="1") parser.add_argument("-G", "--gpu-memory", help="gpu memary used", type=float, dest="gpu_memory", default="0.1") args = parser.parse_args() save_log = os.path.join('train_log', args.save_log) save_folder = os.path.join(save_log, 'models') gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=args.gpu_memory) with tf.Session(config=tf.ConfigProto(gpu_options=gpu_options)) as sess: net = R_Net.R_Net() input_img = tf.placeholder(tf.float32, [None, None, None, 3]) feature_map = net.pr(input_img) model_pr = tf.train.Saver() model_pr.restore(sess, os.path.join(save_folder, str(10000) + 'save_net.ckpt')) ge = generator_test_region.generator_test(image_path='/data/images/', image_size=24, batch=1, image_from_each_face=3, dy=[5, 11, 20])