-
Notifications
You must be signed in to change notification settings - Fork 23
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
[WIP] Conv2D Layer #39
Open
plavin
wants to merge
7
commits into
arrayfire:master
Choose a base branch
from
plavin:conv2d-fix
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6954663
Add auxiliary functions needed for conv2d
plavin 4beea0f
add conv2d function
plavin 42da3a8
added Conv2D layer
plavin 34ac18e
cleanup
plavin 93b3554
cleanup
plavin a037c0a
changed name of Conv2D to Colvolve2
plavin 49e077e
rename conv2d to convolve2
plavin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/******************************************************* | ||
* Copyright (c) 2017, ArrayFire | ||
* All rights reserved. | ||
* | ||
* This file is distributed under 3-clause BSD license. | ||
* The complete license agreement can be obtained at: | ||
* http://arrayfire.com/licenses/BSD-3-Clause | ||
********************************************************/ | ||
#pragma once | ||
|
||
#include <af/nn/Modules/Module.hpp> | ||
|
||
namespace af | ||
{ | ||
namespace nn | ||
{ | ||
class Convolve2 : public Module | ||
{ | ||
private: | ||
bool m_bias; | ||
int m_wx; | ||
int m_wy; | ||
int m_sx; | ||
int m_sy; | ||
int m_px; | ||
int m_py; | ||
public: | ||
Convolve2(int wx, int wy, int sx, int sy, int px, int py, int n_in, int n_out, bool bias = true); | ||
|
||
Convolve2(const autograd::Variable &w, int sx = 1, int sy = 1, int px = 0, int py = 0); | ||
|
||
Convolve2(const autograd::Variable &w, const autograd::Variable &b, int sx = 1, int sy = 1, int px = 0, int py = 0); | ||
|
||
autograd::Variable forward(const autograd::Variable &input); | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/******************************************************* | ||
* Copyright (c) 2017, ArrayFire | ||
* All rights reserved. | ||
* | ||
* This file is distributed under 3-clause BSD license. | ||
* The complete license agreement can be obtained at: | ||
* http://arrayfire.com/licenses/BSD-3-Clause | ||
********************************************************/ | ||
#include <af/autograd/Functions.hpp> | ||
#include <af/nn/Init.hpp> | ||
#include <af/nn/Modules/Convolve2.hpp> | ||
//output will be ho x wo x no x n | ||
namespace af | ||
{ | ||
namespace nn | ||
{ | ||
using namespace autograd; | ||
|
||
Convolve2::Convolve2(int wx, int wy, int sx, int sy, int px, int py, int n_in, int n_out, bool bias) : | ||
m_wx(wx), | ||
m_wy(wy), | ||
m_sx(sx), | ||
m_sy(sy), | ||
m_px(px), | ||
m_py(py), | ||
m_bias(bias) | ||
{ | ||
auto w = nn::lecunNormal(dim4(wx, wy, n_in, n_out)); | ||
if (bias) { | ||
auto b = nn::lecunNormal(dim4(1, 1, n_out, 1)); | ||
setParams({w, b}); | ||
} else { | ||
setParams({w}); | ||
} | ||
} | ||
|
||
Convolve2::Convolve2(const Variable &w, int sx, int sy, int px, int py) : | ||
m_sx(sx), | ||
m_sy(sy), | ||
m_px(px), | ||
m_py(py), | ||
m_bias(false), | ||
Module({w}) | ||
{ | ||
dim4 pdims = w.dims(); | ||
m_wx = pdims[0]; | ||
m_wy = pdims[1]; | ||
} | ||
|
||
Convolve2::Convolve2(const Variable &w, const Variable &b, int sx, int sy, int px, int py) : | ||
m_sx(sx), | ||
m_sy(sy), | ||
m_px(px), | ||
m_py(py), | ||
m_bias(true), | ||
Module({w, b}) | ||
{ | ||
if (b.dims()[1] != 1) { | ||
throw af::exception("nn::Linear: Bias must be a vector."); | ||
} | ||
dim4 pdims = w.dims(); | ||
m_wx = pdims[0]; | ||
m_wy = pdims[1]; | ||
} | ||
|
||
Variable Convolve2::forward(const Variable &input) | ||
{ | ||
auto res = convolve2(input, m_parameters[0], m_wx, m_wy, m_sx, m_sy, m_px, m_py); | ||
if (m_bias) { | ||
res = res + tileAs(m_parameters[1], res); | ||
} | ||
return res; | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is all that is preventing me from having batches working.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can make the
matmulXY
functions in arrayfire-ml support batches for now.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be good.