Exemple #1
0
def main(argv):
    parser = argparse.ArgumentParser(
        description='Display image readable with tensorflow.')
    parser.add_argument('filename', type=str, help='Image file to display.')
    args = parser.parse_args()

    if ctfi.is_image(args.filename) == False:
        sys.exit(-1)

    image = ctfi.load(args.filename, channels=3)
    image = tf.expand_dims(image, 0)
    dx, dy = tf.image.image_gradients(image)

    dxr, dxg, dxb = tf.split(dx, 3, 3)
    dyr, dyg, dyb = tf.split(dy, 3, 3)

    strides = [1, 1, 1, 1]
    padding = "SAME"

    #reconstructed = tf.nn.conv2d_transpose(dxr + dyr, tf.ones([3,3,1,1], dtype=tf.float32),[1,32,32,1],strides,padding)# + tf.nn.conv2d(dy, tf.ones([3,3,1,3], dtype=tf.float32),strides,padding)
    #reconstructed = tf.concat([tf.nn.conv2d_transpose(c, tf.ones([1,32,1,1], dtype=tf.float32),[1,32,32,1],strides,padding) for c in tf.split(dx,3,3)],3)
    #reconstructed += tf.concat([tf.nn.conv2d_transpose(c, tf.ones([32,1,1,1], dtype=tf.float32),[1,32,32,1],strides,padding) for c in tf.split(dy,3,3)],3)
    fig, ax = plt.subplots(2, 2)
    ax[0, 0].imshow(image[0].numpy())
    ax[0, 1].imshow(dx[0] + dy[0].numpy())
    ax[1, 0].imshow(dx[0].numpy())
    ax[1, 1].imshow(dy[0].numpy())
    plt.show()
Exemple #2
0
def main(argv):
    filename = os.path.join(git_root, 'data', 'images', 'tile_8_14.jpeg')

    if ctfi.is_image(filename):
        image = ctfi.load(filename, width=1024, height=1024, channels=3)
    else:
        image = np.random.rand(1024, 1024, 3)

    # Using eager execution
    fig, ax = plt.subplots()
    plt.imshow(image.numpy())
    plt.show()
Exemple #3
0
def main(argv):
    parser = argparse.ArgumentParser(
        description='Compute latent code for image patch by model inference.')

    parser.add_argument('export_dir',
                        type=str,
                        help='Path to saved model to use for inference.')
    parser.add_argument('filename',
                        type=str,
                        help='Image file or numpy array to run inference on.')
    parser.add_argument('--output',
                        type=str,
                        help='Where to store the output.')

    args = parser.parse_args()

    predict_fn = predictor.from_saved_model(args.export_dir)

    # Extract patch size and latent space size from the model identifier
    patch_size = ctfsm.determine_patch_size(args.export_dir)
    latent_space_size = ctfsm.determine_latent_space_size(args.export_dir)

    image = None

    # Check if it is image or numpy array data
    if ctfi.is_image(args.filename):
        image = ctfi.load(args.filename).numpy()
    elif cutil.is_numpy_format(args.filename):
        image = np.load(args.filename)
    else:
        sys.exit(3)

    # Resize image to match size required by the model
    image = np.resize(image, [patch_size, patch_size, 3])

    batch = np.expand_dims(image, 0)
    # Make predictions
    pred = predict_fn({
        'fixed': batch,
        'moving': np.random.rand(1, patch_size, patch_size, 3),
        'embedding': np.random.rand(1, 1, 1, latent_space_size)
    })
    latent_code = pred['latent_code_fixed']
    print(latent_code)

    if args.output:
        with open(args.output, 'w') as f:
            json.dump(
                {
                    'filename': args.filename,
                    'model': args.export_dir,
                    'latent_code': latent_code.tolist()
                }, f)
Exemple #4
0
def main(argv):    
    parser = argparse.ArgumentParser(description='Display image readable with tensorflow.')
    parser.add_argument('filename',type=str,help='Image file to display.')
    args = parser.parse_args()

    if ctfi.is_image(args.filename) == False:
        sys.exit(-1)

    image = ctfi.load(args.filename, channels=3)   
    
    fig, ax = plt.subplots()
    plt.imshow(image.numpy())
    plt.show()