2

Using this Link for Bilinear Interpolation http://cv-tricks.com/image-segmentation/transpose-convolution-in-tensorflow/

I am trying to get some results using a dummy matrix i.e filter_shape of dimension 4 named as a tensor in my code. But it gives me an error. Can anyone help me with a dummy example to run this Bilinear Interpolation code?

import tensorflow as tf
import numpy as np
#tensor=np.zeros((2,2,3,3))
tensor=np.random.random((2,2,3,3))
print(tensor)
def get_bilinear_filter(filter_shape, upscale_factor):
    ##filter_shape is [width, height, num_in_channels, num_out_channels]
    kernel_size = filter_shape[1]
    ### Centre location of the filter for which value is calculated
    if kernel_size % 2 == 1:
        centre_location = upscale_factor - 1
    else:
        centre_location = upscale_factor - 0.5

    bilinear = np.zeros([filter_shape[0], filter_shape[1]])
    for x in range(filter_shape[0]):
        for y in range(filter_shape[1]):
            ##Interpolation Calculation
            value = (1 - abs((x - centre_location)/ upscale_factor)) * (1 - abs((y - centre_location)/ upscale_factor))
            bilinear[x, y] = value
    weights = np.zeros(filter_shape)
    print(weights)
    for i in range(filter_shape[2]):
        weights[:, :, i, i] = bilinear
    init = tf.constant_initializer(value=weights,
                                   dtype=tf.float32)

    bilinear_weights = tf.get_variable(name="decon_bilinear_filter", initializer=init,
                           shape=weights.shape)
    print(bilinear_weights)



get_bilinear_filter(tensor,3)
  • Please post the exact error message and where in the code it occurs. – xdurch0 Jun 29 '18 at 11:45
  • it occurs at this line `if kernel_size % 2 == 1:` – Zeeshan Nisar Jun 29 '18 at 11:47
  • And exact error is this **The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()** – Zeeshan Nisar Jun 29 '18 at 11:48
  • I think you messed up something in your code. You are passing an array of random numbers of shape `(2,2,3,3)` as your `kernel_shape`. I would assume that you are simply trying to pass the array `[2, 2, 3, 3]`? However I'm not familiar with what exactly you are trying to do so I'm not sure about this. – xdurch0 Jun 29 '18 at 11:59

0 Answers0