-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mask images and file lists #10
Comments
Thanks for your good suggestions. Here is my code for generating random masks and the corresponding mask file list in the testing. This code generates 10,000 masks, where each even-numbered mask is composed of three random rectangles, and each odd-numbered mask is composed of five random free-form strokes. import os
import cv2
import sys
import numpy as np
import tensorflow as tf
import net.nn as nn
save_dir = '/gdata/test_set/random_mask'
bbox1 = nn.random_bbox(256, 256, 0, 128, random_mask=True)
regular_mask1 = nn.bbox2mask(bbox1, 256, 256, 64, name='mask_r1')
bbox2 = nn.random_bbox(256, 256, 0, 128, random_mask=True)
regular_mask2 = nn.bbox2mask(bbox2, 256, 256, 64, name='mask_r2')
bbox3 = nn.random_bbox(256, 256, 0, 128, random_mask=True)
regular_mask3 = nn.bbox2mask(bbox3, 256, 256, 64, name='mask_r3')
irregular_mask1 = nn.brush_stroke_mask(256, 256, name='mask_i1')
irregular_mask2 = nn.brush_stroke_mask(256, 256, name='mask_i2')
irregular_mask3 = nn.brush_stroke_mask(256, 256, name='mask_i3')
irregular_mask4 = nn.brush_stroke_mask(256, 256, name='mask_i4')
irregular_mask5 = nn.brush_stroke_mask(256, 256, name='mask_i5')
mask1 = tf.cast(tf.cast(regular_mask1 + regular_mask2 + regular_mask3, tf.bool), tf.float32) * 255
mask1 = tf.cast(mask1, tf.uint8)
mask2 = tf.cast(tf.cast(irregular_mask1 + irregular_mask2 + irregular_mask3 + irregular_mask4+ irregular_mask5, tf.bool), tf.float32) *255
mask2 = tf.cast(mask2, tf.uint8)
# TF session
with tf.Session(config=tf.ConfigProto(allow_soft_placement=True)) as sess:
mask_path_list = []
for i in range(10000):
if i % 2:
mask_np = sess.run(mask1)[0,:,:,:]
if not i % 2:
mask_np = sess.run(mask2)[0,:,:,:]
mask_path = save_dir+'/mask_%05d.png' % i
mask_path_list.append(mask_path)
cv2.imwrite(mask_path, mask_np)
print("Processing %05d random mask..." % i)
sys.stdout.flush()
fo = open('/gdata/test_set/flist/random_mask.flist', "w")
fo.write("\n".join(mask_path_list))
fo.close()
print("FINISHED!!!") |
BTW, here is my code for generating Places2 validation images of 256x256 resolution and the corresponding image file list. This code generates 10,000 images given the file list of Places2 validation set. import os
import cv2
import numpy as np
image_list = np.genfromtxt('/gdata1/places2_flist/places2_valid.flist', dtype=np.str)
save_dir = '/gdata/test_set/places2_img'
img_path_list = []
for i in range(10000):
img = cv2.imread(image_list[i])[:,:,::-1]
h, w = img.shape[:2]
if h >= 256 and w >= 256:
h_start = (h-256) // 2
w_start = (w-256) // 2
img = img[h_start: h_start+256, w_start: w_start+256, :]
else:
img = cv2.resize(img, (256, 256))
img_path = save_dir+'/img_%05d.png' % i
img_path_list.append(img_path)
cv2.imwrite(img_path, img[:,:,::-1])
print("Processing %05d image..." % i)
sys.stdout.flush()
fo = open('/gdata/test_set/flist/places2_img.flist', "w")
fo.write("\n".join(img_path_list))
fo.close()
print("FINISHED!!!") |
Certainly, you can modify the code to generate masks with 128x128 center holes or testing images of other datasets. Best wishes, |
The first result seems acceptable. The second one is poor, probably because the scene is too complicated. |
I appreciate your quick response! Did you find any of these artifacts in your experiments? |
When the scene is too complicated, these artifacts may happen. You can try to generate multiple results and select a plausible one from them. |
Thank you for your kind support! |
I only have one file of image, and I want to generate mask image. |
This folder is |
You can make a file list with only one line for this image. Also, you need to change |
Thank you for sharing your great work!
I want to run
test.py
using your pretrained models. Do I need to prepare the mask images and file lists by myself? If you have the code to generate them, would you mind sharing it?The text was updated successfully, but these errors were encountered: