示例#1
0
def model_predictions(folder, start, end):
    batch_siz = 250
    iterator_count = int(((end - (start - 1)) / batch_siz)) + 1
    for j in range(1, iterator_count):
        print("Batch ", j, " started..")
        jstart = (j - 1) * batch_siz + start
        jend = j * batch_siz + (start - 1)
        inputs = load_images(file_name, folder, jstart, jend)
        inputs = scale_up(2, inputs)
        outputs = predict(model, inputs, batch_size=64)
        save_output(outputs, output_dir, folder, jstart, jend)
    return True
示例#2
0
def decode(y, relu_max):
    assert len(y._keras_shape) == 2
    latent_dim = y._keras_shape[-1]
    x = Reshape((1, 1, latent_dim))(y)
    # 1, 1, latent_dim
    if relu_max:
        x = Activation(utils.scale_up(relu_max))(x)
    # not good? x = BN(mode=2, axis=3)(x)

    batch_size = tf.shape(x)[0]
    x = Deconv2D(40, 7, 7, output_shape=[batch_size, 7, 7, 40], activation='relu',
                 border_mode='same', subsample=(7,7))(x)
    x = BN(mode=2, axis=3)(x)
    # 7, 7, 40
    x = Deconv2D(20, 3, 3, output_shape=[batch_size, 14, 14, 20], activation='relu',
                 border_mode='same', subsample=(2,2))(x)
    x = BN(mode=2, axis=3)(x)
    # 14, 14, 20
    x = Deconv2D(1, 3, 3, output_shape=[batch_size, 28, 28, 1], activation='sigmoid',
                 border_mode='same', subsample=(2,2))(x)
    # 28, 28, 1
    return x
predictions = []

for i in range(N // bs):
    x = []
    rgb_paths = void_rgb_list[(i) * bs:(i + 1) * bs]
    for rgb_path in rgb_paths:
        img = np.asarray(Image.open(rgb_path)).reshape(480, 640, 3)
        x.append(img)
    inds = np.arange(len(x)).tolist()
    x = [x[i] for i in inds]
    x = np.stack(x).astype(np.float32)

    # Compute results
    pred_y = scale_up(
        2,
        predict(model, x / 255, minDepth=10, maxDepth=1000,
                batch_size=bs)[:, :, :, 0]) * 10.0

    # Test time augmentation: mirror image estimate
    pred_y_flip = scale_up(
        2,
        predict(model,
                x[..., ::-1, :] / 255,
                minDepth=10,
                maxDepth=1000,
                batch_size=bs)[:, :, :, 0]) * 10.0

    # Compute errors per image in batch
    for j in range(len(x)):
        path = rgb_paths[j].replace('image', 'prediction')
        prediction = (0.5 * pred_y[j]) + (0.5 * np.fliplr(pred_y_flip[j]))
示例#4
0
    out_min = np.min(output)
    out_max = np.max(output)
    output = output - out_min
    outputs = output / out_max

    if is_colormap:
        rescaled = outputs[:, :, 0]
        pred_x = plasma(rescaled)[:, :, :3]
        imgs.append(pred_x)

    img_set = np.hstack(imgs)

    return img_set


count = 0
ret = True
while ret:
    ret, image = cap.read()
    if ret is False:
        break
    img_arr = get_img_arr(image)
    count += 1
    output = scale_up(2, predict(model, img_arr, batch_size=1))
    pred = output.reshape(output.shape[1], output.shape[2], 1)
    img_set = display_single_image(pred, img_arr)
    plt.figure(figsize=(20, 10))
    plt.imshow(img_set)
    filename = 'img_' + str(count).zfill(4) + '.png'
    plt.savefig(os.path.join('image_results', filename), bbox_inches='tight')
示例#5
0
# mylist = [f for f in glob.glob(input_dir)]
for count in range(1,101):
  zip_file_name = "/content/drive/My Drive/Utils/S15A/Images/fg_bg" + str(count) + ".zip"
  my_dict = {"bg_number": count, "zip_file_name" : zip_file_name}
  mylist.append(my_dict)

print("My_List", mylist[start:end])

for file_name in mylist[start:end]:
  print(file_name, start, end)
  print("Bg Loop",datetime.datetime.now())
  with zipfile.ZipFile(file_name["zip_file_name"], 'r') as zip:
    start = timeit.default_timer()
    print("start", start)
    file_list = zip.namelist()
    new_zip_name = file_name["bg_number"]
    dense_depth_zip = zipfile.ZipFile(output_dir+f'/fb_bg_depth{new_zip_name}.zip', mode='a', compression=zipfile.ZIP_STORED)
    for i in range(0, 4000, 50):
      snipped_list = file_list[i:i+50]
      inputs= load_zip_images(zip, snipped_list)
      inputs = scale_up(2, inputs)
      outputs = predict(model, inputs)
      save_output(outputs, output_dir, snipped_list, dense_depth_zip, is_rescale=True)
      
    stop = timeit.default_timer()
    execution_time = stop - start
    dense_depth_zip.close()
    print("Program Executed in "+str(execution_time))


示例#6
0
#print(names[:5])
inputs = load_images(names)
print('\nLoaded ({0}) images of size {1}.'.format(inputs.shape[0],
                                                  inputs.shape[1:]))
#print(inputs.shape)
#print(inputs[1,:,:,0])
#print(np.amax(inputs[1,:,:,0]))
#print(np.amin(inputs[1,:,:,0]))

# Compute results
print("start prediction")
#outputs = predict(model, inputs)
#test = predict(model, inputs, minDepth=10, maxDepth=1000)
#print(test.shape)
outputs = scale_up(
    2,
    predict(model, inputs, minDepth=10, maxDepth=1000)[:, :, :, 0]) * 10.0
print("about to start printing result")
print(outputs.shape)
print(outputs[0])

outputs = np.float32(outputs)

savefolder = '/work/NYUv2_DE'
np.savez("%s/%s_depth_estimation_densedepth.npz" % (savefolder, "train"),
         outputs)
print("save successful")

#np.savez("%s/%s_depth_estimation_megadepth.npz" % (savefolder, "test"), test_depth)

#for i in range(outputs.shape[0]):
示例#7
0
    img = np.asarray(Image.open(file), dtype='float32')
    rgb_height, rgb_width = img.shape[:2]
    xx, yy = worldCoords(width=rgb_width, height=rgb_height)
    inputRGB = np.clip(img / 255, 0, 1)

    # Compute results
    start = time.time()
    output = predict(pytorch_model, inputRGB)
    print(f"Predicted in {time.time() - start} s.")
   
    # save image:
    # im = Image.fromarray(np.uint8(output * 255))
    # im.save("data/_out/sample_2_depth.png")

    # Compute PCD and visualize:
    output = scale_up(2, output) * 10.0
    pcd = posFromDepth(output.copy(), xx, yy)
    
    # Open3d pcd:
    pcl = o3d.geometry.PointCloud()
    pcl.points = o3d.utility.Vector3dVector(pcd)
    pcl.colors = o3d.utility.Vector3dVector(inputRGB.reshape(rgb_width * rgb_height, 3))
    # Flip it, otherwise the pointcloud will be upside down
    pcl.transform([[1, 0, 0, 0], [0, -1, 0, 0], [0, 0, -1, 0], [0, 0, 0, 1]])

    # Compute point cloud from rgbd image:
    '''
    rgbd_image = o3d.geometry.RGBDImage.create_from_color_and_depth(
         inputRGB, output, convert_rgb_to_intensity=False)
    pcd = o3d.geometry.PointCloud.create_from_rgbd_image(
         rgbd_image,
示例#8
0
文件: stl_ae.py 项目: hengyuan-hu/dem
def decode(y, relu_max):
    print 'decoder input shape:', y._keras_shape
    assert len(y._keras_shape) == 2
    if relu_max:
        x = GaussianNoise(0.2)(y)
        x = Activation(utils.relu_n(1))(x)
    else:
        x = y

    x = Reshape((1, 1, LATENT_DIM))(x)
    # 1, 1, LATENT_DIM
    if relu_max:
        print 'in decode: relu_max:', relu_max
        x = Activation(utils.scale_up(relu_max))(x)
    # x = BN(mode=2, axis=3)(x) # this bn seems not good? NOT VERIFIED

    # why use 512 instead of 256 here?
    batch_size = keras.backend.shape(x)[0]
    x = Deconv2D(512,
                 6,
                 6,
                 output_shape=[batch_size, 6, 6, 512],
                 activation='relu',
                 border_mode='same',
                 subsample=(6, 6))(x)
    x = BN(mode=2, axis=3)(x)
    # 6, 6, 512
    x = Deconv2D(256,
                 5,
                 5,
                 output_shape=[batch_size, 12, 12, 256],
                 activation='relu',
                 border_mode='same',
                 subsample=(2, 2))(x)
    x = BN(mode=2, axis=3)(x)
    # 12, 12, 256
    x = Deconv2D(128,
                 5,
                 5,
                 output_shape=(batch_size, 24, 24, 128),
                 activation='relu',
                 border_mode='same',
                 subsample=(2, 2))(x)
    x = BN(mode=2, axis=3)(x)
    # 24, 24, 128
    x = Deconv2D(64,
                 5,
                 5,
                 output_shape=(batch_size, 48, 48, 64),
                 activation='relu',
                 border_mode='same',
                 subsample=(2, 2))(x)
    x = BN(mode=2, axis=3)(x)
    # 48, 48, 64
    x = Deconv2D(32,
                 5,
                 5,
                 output_shape=(batch_size, 96, 96, 32),
                 activation='relu',
                 border_mode='same',
                 subsample=(2, 2))(x)
    x = BN(mode=2, axis=3)(x)
    # 96, 96, 32
    x = Deconv2D(3,
                 5,
                 5,
                 output_shape=(batch_size, 96, 96, 3),
                 activation='linear',
                 border_mode='same',
                 subsample=(1, 1))(x)
    # 32, 32, 3
    x = BN(mode=2, axis=3)(x)
    return x