Skip to content
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

Extend your get_deconv_filter from 2D to 3D. How? #44

Open
John1231983 opened this issue Sep 21, 2017 · 0 comments
Open

Extend your get_deconv_filter from 2D to 3D. How? #44

John1231983 opened this issue Sep 21, 2017 · 0 comments

Comments

@John1231983
Copy link

I want to extend your get_deconv_filter from 2D to 3D. In CAFFE, it can be implemented as

int f = ceil(blob->shape(-1) / 2.);
    float c = (2 * f - 1 - f % 2) / (2. * f);
    for (int i = 0; i < blob->count(); ++i) {
      float x = i % blob->shape(-1);
      float y = (i / blob->shape(-1)) % blob->shape(-2);
      float z = (i/(blob->shape(-1)*blob->shape(-2))) % blob->shape(-3);
      data[i] = (1 - fabs(x / f - c)) * (1 - fabs(y / f - c)) * (1-fabs(z / f - c));

So, the get_deconv_filter function will be changed as

def get_deconv_filter(self, f_shape):
        width = f_shape[0]
        heigh = f_shape[0]
        depth = f_shape[0]
        f = ceil(width/2.0)
        c = (2 * f - 1 - f % 2) / (2.0 * f)
        bilinear = np.zeros([f_shape[0], f_shape[1],f_shape[2]])
        for x in range(width):
            for y in range(heigh):
                for z in range(depth):
                      value = (1 - abs(x / f - c)) * (1 - abs(y / f - c))*(1 - abs(z / f - c))
                      bilinear[x, y, z] = value
        weights = np.zeros(f_shape)
        for i in range(f_shape[2]):
            weights[:, :, :, i, i] = bilinear

        init = tf.constant_initializer(value=weights,
                                       dtype=tf.float32)
        return tf.get_variable(name="up_filter", initializer=init,
                               shape=weights.shape)

Could you please look at my code and correct help me if it wrong? Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant