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

Support variable-dimension input feature for 2D convolution operation. #2215

Merged
merged 7 commits into from
May 26, 2017

Conversation

qingqing01
Copy link
Contributor

@qingqing01 qingqing01 commented May 19, 2017

  • add dense_array type instead of using dense_vector.
  • the 2D or 3D input feature should be numpy.array

The data feeder will set height and width according to the shape of input data each mini-batch.

Fix #2198

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):
Copy link
Collaborator

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?

Copy link
Contributor Author

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
Copy link
Collaborator

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.

Copy link
Contributor Author

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
Copy link
Collaborator

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.

Copy link
Contributor Author

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()
Copy link
Collaborator

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?

Copy link
Contributor Author

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.

@qingqing01 qingqing01 changed the title Support variable-demension input feature for 2D convolution operation. Support variable-dimension input feature for 2D convolution operation. May 24, 2017
Copy link
Contributor Author

@qingqing01 qingqing01 left a 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):
Copy link
Contributor Author

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
Copy link
Contributor Author

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
Copy link
Contributor Author

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()
Copy link
Contributor Author

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.

Copy link
Collaborator

@reyoung reyoung left a comment

Choose a reason for hiding this comment

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

LGTM.

@qingqing01 qingqing01 merged commit 1220f38 into PaddlePaddle:develop May 26, 2017
@qingqing01 qingqing01 deleted the variable_input branch July 7, 2017 13:35
heavengate pushed a commit to heavengate/Paddle that referenced this pull request Aug 16, 2021
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