-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from larq/make-it-general
Make it general
- Loading branch information
Showing
9 changed files
with
166 additions
and
71 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
from zookeeper.hparam import HParams | ||
from zookeeper.preprocessing import Preprocessing | ||
from zookeeper.cli import build_train, cli | ||
|
||
__all__ = ["build_train", "cli", "HParams"] | ||
__all__ = ["build_train", "cli", "HParams", "Preprocessing"] |
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
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,53 @@ | ||
import abc | ||
|
||
|
||
class Preprocessing(abc.ABC): | ||
"""An abstract class to be used to define data preprocessing. | ||
We define a neural network to be a mapping between an input and an output, hence we | ||
define two abstract methods, an input (e.g the image for image classification), and | ||
an output (e.g the class label for image classification). We also define decoders, | ||
which allows use to customize the decoding, and kwargs, which allows us to pass | ||
information from the preprocessing to the model (e.g input size.) | ||
# Arguments | ||
features: A [`tfds.features.FeaturesDict`](https://www.tensorflow.org/datasets/api_docs/python/tfds/features/FeaturesDict) | ||
# Properties | ||
- `decoders`: Nested `dict` of [`Decoder`](https://www.tensorflow.org/datasets/api_docs/python/tfds/decode/Decoder) | ||
objects which allow to customize the decoding. The structure should match the | ||
feature structure, but only customized feature keys need to be present. | ||
See [the guide](https://www.tensorflow.org/datasets/decode) for more info. | ||
- `kwargs`: A `dict` that can be used to pass additional keyword arguments to a | ||
model function. | ||
""" | ||
|
||
decoders = None | ||
kwargs = {} | ||
|
||
def __init__(self, features=None): | ||
self.features = features | ||
|
||
@abc.abstractmethod | ||
def inputs(self, data, training): | ||
"""A method to define preprocessing for inputs. | ||
This method needs to be overwritten by all subclasses. | ||
# Arguments | ||
data: A dictionary of type {feature_name: Tensor} | ||
training: An optional `boolean` to define if preprocessing is called during training. | ||
""" | ||
raise NotImplementedError("Must be implemented in subclasses.") | ||
|
||
@abc.abstractmethod | ||
def outputs(self, data, training): | ||
"""A method to define preprocessing for outputs. | ||
This method needs to be overwritten by all subclasses. | ||
# Arguments | ||
data: A dictionary of type {feature_name: Tensor} | ||
training: An optional `boolean` to define if preprocessing is called during training. | ||
""" | ||
raise NotImplementedError("Must be implemented in subclasses.") |
Oops, something went wrong.