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

Conv2D #37

Closed
wants to merge 4 commits into from
Closed

Conv2D #37

wants to merge 4 commits into from

Conversation

plavin
Copy link
Contributor

@plavin plavin commented Jul 24, 2017

The autograd part still needs to be written.

I also need to be able to join the outputs of multiple inputs, but I'm having trouble getting join to work. This is needed to do batched processing.

Currently arrayfire can join up to 10 arrays at a time. This may or may not be an acceptable batch size. A better solution would be to implement 3d and 4d matmul in arrayfire.

@plavin
Copy link
Contributor Author

plavin commented Jul 27, 2017

@pavanky Added the rest of the Conv2D layer - although it still isn't batched. I need to find a way to confirm it is working properly.

I added some more gradients of af functions.

int o2 = a.dims()[2];
int o3 = a.dims()[3];
printf("Orig: %d,%d,%d,%d -- New: %d,%d,%d,%d",o0,o1,o2,o3,d0,d1,d2,d3);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this. Besides you can call a.dims(i);

dim4 d = input.array().dims();
array res = unwrap(input.array(), wx, wy, sx, sy, px, py);
int params[] = {wx, wy, sx, sy, px, py, (int)d[0], (int)d[1]};
auto tmp = Variable(array(8, params), false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need a better way to handle this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be check if you can infer the parameters from having access to both input and grad_output

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK capturing the parameters in the lambda works. Instead of creating tmp, just capture the necessary input params.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by "just capture the necessary input params?"

We can't change the signature of grad_func, right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The [] part of the lambda need not be empty. You can specify what variables from the current scope are seen inside the lambda. http://en.cppreference.com/w/cpp/language/lambda#Lambda_capture

This does not change the signature of grad_func.

inputs[0].addGrad(moddims(grad_output, p[0], p[1], p[2], p[3]));
};
return Variable(res, {input, tmp}, grad_func);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this in my PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok this can be deleted after rebasing from master.

@pavanky
Copy link
Member

pavanky commented Jul 27, 2017

@plavin I want to figure out a way we can pass stuff that's not a variable to the backward pass.

Also wait until after #36 is merged.

inputs[0].addGrad(moddims(grad_output, p[0], p[1], p[2], p[3]));
};
return Variable(res, {input, tmp}, grad_func);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok this can be deleted after rebasing from master.

int *r = inputs[1].array().host<int>();
inputs[0].addGrad(reorder(grad_output, r[0], r[1], r[2], r[3]));
};
return Variable(res, {input, reverse}, grad_func);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comments from unwrap.

};
return Variable(res, {input, tmp}, grad_func);
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comments from unwrap.


int tmp[] = {wx, wy, sx, sy, px, py, c_i, x_o, y_o};
auto params = Variable(array(9, tmp), false);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capture the necessary params.


auto d = matmulTN(inputs[2],grad_out_reshape);
inputs[1].addGrad(moddims(d, p[0], p[1], p[6], d.array().dims()[1]));

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is there no loop here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should loop over the input images -- still need to do a gradient for join. I'll add that. But the c++ api can only join 4 arrays at a time.

{
auto w = nn::weight(wx, wy, n_in, n_out, spread);
if (bias) {
auto b = nn::weight(1, 1, n_out, 1, spread);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the new types. I think the suggested version is lecunNormal.

other usefull gradients are included
Helper functions added - wrap, unwrap, moddims, reorder
@plavin
Copy link
Contributor Author

plavin commented Aug 1, 2017

@pavanky This pr is kind of a mess now. I think I'll abandon this one and move changes to separate commits. One with extra functions and one with conv2d layer. And a third with the alexnet/example.cpp

@pavanky
Copy link
Member

pavanky commented Aug 1, 2017

@plavin sounds good.

@plavin plavin closed this Aug 2, 2017
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

Successfully merging this pull request may close these issues.

2 participants