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

Tensorflow 1 and 2 Step Savers, And Base Classes #5

Merged
merged 30 commits into from Jan 16, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
bb20f6b
Create Setup.py, And Folder Structure
alexbrillant Dec 2, 2019
6c943dd
Add TensorflowModelWrapperMixin
alexbrillant Dec 2, 2019
8c06467
Move Usage Example Link In ReadMe
alexbrillant Dec 2, 2019
fd5b1fa
Add Docstrings To Tensorflow Model V1 Wrapper Mixin
alexbrillant Dec 2, 2019
d5ccc5d
Add Tensorflow V2 Step Saver
alexbrillant Dec 30, 2019
d623bdb
Add New Line In file Headers before copyright notice
alexbrillant Dec 30, 2019
8337d09
Simplify Tensorflow 1 Model And Saver Wip
alexbrillant Dec 30, 2019
536b4dd
Simplify Tensorflow 2 Models, And Saver
alexbrillant Dec 31, 2019
84680d6
Simplify Tensorflow 2 Models, And Saver
alexbrillant Dec 31, 2019
0efda6b
Add Docstrings To Base Tensorflow Steps
alexbrillant Dec 31, 2019
bb41bee
Fix Tensorflow 1 And Tensorflow 2 Test / Examples
alexbrillant Dec 31, 2019
a98b150
Apply Review Comments #5
alexbrillant Jan 6, 2020
c6baca8
Apply Review Comments Pr #5
alexbrillant Jan 6, 2020
333945d
Apply Review Comments #5
alexbrillant Jan 6, 2020
d68b876
Fix README
alexbrillant Jan 6, 2020
1d72294
Fix Tensorflow V1 Model Graph Argument And Loss
alexbrillant Jan 7, 2020
16846bf
Add the possibility to return 2 outputs on the create graph function …
alexbrillant Jan 8, 2020
d562cc9
Save Loss array in Tensorflow v1 Model step, And Add Print Loss func
alexbrillant Jan 11, 2020
2333f12
Apply Review Comments #5
alexbrillant Jan 13, 2020
6d4f34e
Apply Review Comments #5
alexbrillant Jan 13, 2020
50bcd7d
Fix tensorflow v1 create graph return in test
alexbrillant Jan 13, 2020
40f156d
Add create_inputs to tensorflow models, and add data_inputs, expected…
alexbrillant Jan 14, 2020
ffbf749
Add Train Loss, And Test Loss To BaseTensorflow Model
alexbrillant Jan 14, 2020
1c68f89
Remove Dead Code
alexbrillant Jan 14, 2020
7824c5d
Fix Test Losses
alexbrillant Jan 14, 2020
7d26a91
Fix Transform Data Container For Tensorflow 2
alexbrillant Jan 14, 2020
7db0771
Fix Tensorflow 2 Transform
alexbrillant Jan 14, 2020
4864bb9
Fix Transform Data Container In Tensorflow 2
alexbrillant Jan 14, 2020
d41e46e
Fit Transform Data Container In Tensorflow 2
alexbrillant Jan 14, 2020
1cbbdd1
Add device support in tensorflow 2 (GPU, CPU, etc.)
alexbrillant Jan 15, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 15 additions & 4 deletions README.md
Expand Up @@ -19,8 +19,19 @@ def create_graph(step: TensorflowV1ModelStep):

tf.Variable(np.random.rand(), name='weight')
tf.Variable(np.random.rand(), name='bias')

return tf.add(tf.multiply(step['data_inputs'], step['weight']), step['bias'])

"""
# Note: you can also return a tuple containing two elements : tensor for training (fit), tensor for inference (transform)

Choose a reason for hiding this comment

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

Was indentation lost during auto-format? where should this comment go?

def create_graph(step: TensorflowV1ModelStep)
# ...
decoder_outputs_training = create_training_decoder(step, encoder_state, decoder_cell)
decoder_outputs_inference = create_inference_decoder(step, encoder_state, decoder_cell)

return decoder_outputs_training, decoder_outputs_inference
"""

tf.add(tf.multiply(step['data_inputs'], step['weight']), step['bias'], name='output')

def create_loss(step: TensorflowV1ModelStep):
return tf.reduce_sum(tf.pow(step['output'] - step['expected_outputs'], 2)) / (2 * N_SAMPLES)
Expand All @@ -32,7 +43,7 @@ model_step = TensorflowV1ModelStep(
create_grah=create_graph,
create_loss=create_loss,
create_optimizer=create_optimizer,
has_expected_outputs=False
has_expected_outputs=True
).set_hyperparams(HyperparameterSamples({
'learning_rate': 0.01
})).set_hyperparams_space(HyperparameterSpace({
Expand All @@ -51,8 +62,8 @@ def create_model(step: Tensorflow2ModelStep):
def create_optimizer(step: Tensorflow2ModelStep):
return tf.keras.optimizers.Adam(0.1)

def create_loss(step: Tensorflow2ModelStep, expected_outputs, actual_outputs):
return tf.reduce_mean(tf.abs(actual_outputs - expected_outputs))
def create_loss(step: Tensorflow2ModelStep, expected_outputs, predicted_outputs):
return tf.reduce_mean(tf.abs(predicted_outputs - expected_outputs))

model_step = Tensorflow2ModelStep(
create_model=create_model,
Expand Down
23 changes: 17 additions & 6 deletions neuraxle_tensorflow/tensorflow_v1.py
Expand Up @@ -61,7 +61,7 @@ def __init__(
self.variable_scope = variable_scope
alexbrillant marked this conversation as resolved.
Show resolved Hide resolved
self.has_expected_outputs = has_expected_outputs
self.create_feed_dict = create_feed_dict
self.loss = []
self.losses = []
self.print_loss = print_loss
if print_func is None:
print_func = print
Expand Down Expand Up @@ -147,9 +147,9 @@ def fit_model(self, data_inputs, expected_outputs=None) -> BaseStep:
feed_dict.update(additional_feed_dict_arguments)

results = self.session.run([self['optimizer'], self['loss']], feed_dict=feed_dict)
self.loss.append(results[1])
self.losses.append(results[1])

Choose a reason for hiding this comment

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

srry for the double comment here. I think this could even be train_losses or test_losses. Or have two variables for those losses if we compute both at some point. Just saying. It's okay to not rename for now, although in the doc this will need to be clear when doing a documentation pass.

if self.print_loss:
self.print_func(self.loss[-1])
self.print_func(self.losses[-1])

return self

Expand All @@ -164,9 +164,7 @@ def transform_model(self, data_inputs):
:param data_inputs:
:return:
"""
inference_output_name = 'output'
if len(self['inference_output'].get_shape().as_list()) > 0:
inference_output_name = 'inference_output'
inference_output_name = self._get_inference_output_name()

feed_dict = {
self['data_inputs']: data_inputs
Expand All @@ -176,6 +174,19 @@ def transform_model(self, data_inputs):

return results

def _get_inference_output_name(self):
"""
Return the output tensor name for inference (transform).
In create_graph, the user can return a tuple of two elements : the output tensor for training, and the output tensor for inference.

:return:
"""
inference_output_name = 'output'
if len(self['inference_output'].get_shape().as_list()) > 0:
inference_output_name = 'inference_output'

return inference_output_name

def __getitem__(self, item):
alexbrillant marked this conversation as resolved.
Show resolved Hide resolved
"""
Get a graph tensor by name using get item.
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
@@ -1 +1 @@
Neuraxle
neuraxle>=0.3.0
11 changes: 6 additions & 5 deletions setup.py
Expand Up @@ -19,7 +19,7 @@

from setuptools import setup, find_packages

from neuraxle import __version__ as _VERSION
from neuraxle_tensorflow import __version__ as _VERSION

with open('README.md') as _f:
_README = _f.read()
Expand All @@ -29,6 +29,7 @@
version=_VERSION,
description='TensorFlow steps, savers, and utilities for Neuraxle. Neuraxle is a Machine Learning (ML) library for building neat pipelines, providing the right '
'abstractions to both ease research, development, and deployment of your ML applications.',
long_description_content_type='text/markdown',
long_description=_README,
guillaume-chevalier marked this conversation as resolved.
Show resolved Hide resolved
classifiers=[
"Development Status :: 3 - Alpha",
Expand Down Expand Up @@ -79,16 +80,16 @@
"Topic :: Utilities",
"Typing :: Typed"
],
url='https://github.com/Neuraxio/Neuraxle',
download_url='https://github.com/Neuraxio/Neuraxle/tarball/{}'.format(
url='https://github.com/Neuraxio/Neuraxle-Tensorflow',
download_url='https://github.com/Neuraxio/Neuraxle-Tensorflow/tarball/{}'.format(
_VERSION),
author='Neuraxio Inc.',
author_email='guillaume.chevalier@neuraxio.com',
packages=find_packages(include=['neuraxle-tensorflow*']),
packages=find_packages(include=['neuraxle_tensorflow*']),
test_suite="testing",
setup_requires=["pytest-runner"],
install_requires=[
'neuraxle>=0.2.1'
'neuraxle>=0.3.0'
],
tests_require=["pytest", "pytest-cov"],
include_package_data=True,
Expand Down
2 changes: 1 addition & 1 deletion testing/test_tensorflow_v1.py
Expand Up @@ -19,7 +19,7 @@ def create_graph(step: TensorflowV1ModelStep):
tf.Variable(np.random.rand(), name='weight')
tf.Variable(np.random.rand(), name='bias')

tf.add(tf.multiply(step['data_inputs'], step['weight']), step['bias'], name='output')
return tf.add(tf.multiply(step['data_inputs'], step['weight']), step['bias'])


def create_loss(step: TensorflowV1ModelStep):
Expand Down