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

Inferring data shapes with single dimension for keras adapter #265

Closed
sarahmish opened this issue Oct 26, 2021 · 0 comments · Fixed by #266
Closed

Inferring data shapes with single dimension for keras adapter #265

sarahmish opened this issue Oct 26, 2021 · 0 comments · Fixed by #266
Assignees
Labels
internal improvement This is an improvement that does not add new functionality
Milestone

Comments

@sarahmish
Copy link
Contributor

  • MLPrimitives version: 0.3.1
  • Python version: 3.7

Description

When having numpy arrays of single dimension, for example

X = np.array([0, 2, 1, 3, 5]) # shape (5, )

the keras adapter fails due to the _augment_hyperparameters function where we try to infer the shapes of the input and target variables. More specifically, the following lines can be edited

def _augment_hyperparameters(self, X, mode, kwargs):
    shape = np.asarray(X)[0].shape
    length = shape[0]
    self._setdefault(kwargs, '{}_shape'.format(mode), shape)
    self._setdefault(kwargs, '{}_dim'.format(mode), length)
    self._setdefault(kwargs, '{}_length'.format(mode), length)

    return kwargs

rather than assuming the data is at least contains two dimensions, i.e. shape = (m, n, ..) we can consume a shape of any size and cast it as uni-dimensional if we infer an empty tuple, more concretely the edited function would look like

def _augment_hyperparameters(self, X, mode, kwargs):
    shape = np.asarray(X)[0].shape
    if shape:
        length = shape[0]
    else:
        length = 1 # supporting shape (l, )

    self._setdefault(kwargs, '{}_shape'.format(mode), shape)
    self._setdefault(kwargs, '{}_dim'.format(mode), length)
    self._setdefault(kwargs, '{}_length'.format(mode), length)

    return kwargs

This issue was initially discovered in sintel-dev/Draco#59

@sarahmish sarahmish self-assigned this Oct 26, 2021
@sarahmish sarahmish added the internal improvement This is an improvement that does not add new functionality label Nov 9, 2021
@sarahmish sarahmish added this to the 0.3.2 milestone Nov 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internal improvement This is an improvement that does not add new functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant