Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def save_visualization(X, nh_nw=(batch_size,2+frames), save_path='../results/%s/sample.jpg'%(sys.argv[4])):
X = morph(X)
print(X.shape)
h,w = X.shape[1], X.shape[2]
img = np.zeros((h * nh_nw[0], w * nh_nw[1], 3))
for n,x in enumerate(X):
j = n // nh_nw[1]
i = n % nh_nw[1]
img[j*h:j*h+h, i*w:i*w+w, :] = x[:,:,:3]
np.save("%s.%s"%(save_path.split(".")[0],".npy"), img)
scipy.misc.imsave(save_path, img)
def log_image(np_img, np_confidences, np_boxes, np_global_step,
pred_or_true):
merged = train_utils.add_rectangles(hyp, np_img, np_confidences,
np_boxes,
use_stitching=True,
rnn_len=hyp['rnn_len'])[0]
num_images = 10
filename = '%s_%s.jpg' % \
((np_global_step // hyp['logging']['write_iter'])
% num_images, pred_or_true)
img_path = os.path.join(hyp['dirs']['output_dir'], filename)
scp.misc.imsave(img_path, merged)
return merged
"tools/pseudo_visualization/crop_option_2d/crop_center.png".
The test is successful if the 2nd image
is a random crop of the 1st image and the
3rd image is a central crop of the 1st image.
"""
width_crop = 64
luminance_uint8 = numpy.load('tools/pseudo_data/luminances_uint8.npy')[0, :, :, 0]
crop_0 = tls.crop_option_2d(luminance_uint8,
width_crop,
True)
crop_1 = tls.crop_option_2d(luminance_uint8,
width_crop,
False)
scipy.misc.imsave('tools/pseudo_visualization/crop_option_2d/luminance_image.png',
luminance_uint8)
scipy.misc.imsave('tools/pseudo_visualization/crop_option_2d/crop_random.png',
crop_0)
scipy.misc.imsave('tools/pseudo_visualization/crop_option_2d/crop_center.png',
crop_1)
def print_images(images, num_x, num_y, file='./'):
scipy.misc.imsave(file, # current epoch No.
(images.reshape(num_x, num_y, 3, DIM_X, DIM_Y)
.transpose(0, 3, 1, 4, 2)
.reshape(num_x * DIM_X, num_y * DIM_Y, 3)))
def label_image_saver(image_path, label_image):
im = labels_to_colors(label_image)
scipy.misc.imsave(image_path, im)
def save_image(img, path):
imsave(path, (img+0.5))
def visualize2(seg, gt):
if not os.path.isdir('visualize'):
os.mkdir('visualize')
for i in range(seg.shape[0]):
imsave(os.path.join('visualize', 'step%d.png' % (i+1)), np.concatenate([draw_from_pred(seg[i]), draw_from_pred(gt[i])], 1))
for i in tqdm(range(n_iter)):
_, loss = sess.run([T("vis_op"), T("loss"), ])
# Save trained variables
train_vars = sess.graph.get_collection(tf.GraphKeys.TRAINABLE_VARIABLES)
params = np.array(sess.run(train_vars), object)
save(params, f_model)
# Save final image
images = T("input").eval({t_size: 600})
img = images[0]
sess.close()
imsave(f_image, img)
def save_x(img,filename="output.png"):
img = img.reshape((3,224,224))
img = np.transpose(img,(1,2,0))
imsave(filename,img)
def writeout(tmp, cl, labels, outpath, thres):
l, cnt = md(cl.flatten())
l = np.squeeze(l)
if cnt/len(cl.flatten()) > thres:
outfile = id_generator()+'.jpg'
fp = outpath+os.sep+labels[l]+os.sep+outfile
imsave(fp, tmp)