-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Support variable-dimension input feature for 2D convolution operation. #2215
Conversation
self.__height__ = 0 | ||
|
||
def pre_scan(self, dat): | ||
self.__height__ += 1 | ||
|
||
def finish_pre_scan(self, argument): | ||
def finish_pre_scan(self, argument, dat=None): |
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.
It is not necessary to change finish_pre_scan
interface. The self.shape could be set in pre_scan
routine. and should we check shape are same for each data?
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.
Done. I move the shape settings to pre_scan
function and also check the shape for each data.
raise ValueError("The dimension of input is greater than 3.") | ||
dim = reduce(lambda x, y: x * y, self.__shape__) | ||
if len(self.__shape__) == 1: | ||
assert dim == self.input_type.dim |
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.
if len(self.__shape__) == 1 and dim != self.input_type.dim:
raise ValueError(...)
Please use exception instead of assert.
And it seems that this check should be in pre_scan
method.
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.
Done.
self.__height__ = 0 | ||
|
||
def scan(self, dat): | ||
if isinstance(dat, numpy.ndarray): | ||
assert self.__shape__ == dat.shape |
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.
It is no need to validate data if you validate data shape in pre_scan
method.
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.
Done.
self.__height__ = 0 | ||
|
||
def scan(self, dat): | ||
if isinstance(dat, numpy.ndarray): | ||
assert self.__shape__ == dat.shape | ||
dat = dat.flatten() |
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.
what about not a numpy array?
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.
Handled this case. I test the numpy.array() time and it's better to use NumPy array.
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.
@reyoung Thanks for your review! :)
self.__height__ = 0 | ||
|
||
def pre_scan(self, dat): | ||
self.__height__ += 1 | ||
|
||
def finish_pre_scan(self, argument): | ||
def finish_pre_scan(self, argument, dat=None): |
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.
Done. I move the shape settings to pre_scan
function and also check the shape for each data.
raise ValueError("The dimension of input is greater than 3.") | ||
dim = reduce(lambda x, y: x * y, self.__shape__) | ||
if len(self.__shape__) == 1: | ||
assert dim == self.input_type.dim |
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.
Done.
self.__height__ = 0 | ||
|
||
def scan(self, dat): | ||
if isinstance(dat, numpy.ndarray): | ||
assert self.__shape__ == dat.shape |
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.
Done.
self.__height__ = 0 | ||
|
||
def scan(self, dat): | ||
if isinstance(dat, numpy.ndarray): | ||
assert self.__shape__ == dat.shape | ||
dat = dat.flatten() |
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.
Handled this case. I test the numpy.array() time and it's better to use NumPy array.
7069654
to
8e06f73
Compare
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.
LGTM.
dense_array
type instead of usingdense_vector
.The data feeder will set height and width according to the shape of input data each mini-batch.
Fix #2198