Skip to content

Commit

Permalink
Fix pep8.
Browse files Browse the repository at this point in the history
  • Loading branch information
fchollet committed Jun 19, 2019
1 parent 27fe3cf commit 0bb241e
Show file tree
Hide file tree
Showing 18 changed files with 153 additions and 122 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ matrix:
- python: 3.6
env: TEST_MODE=PEP8
- python: 3.6
env: TEST_MODE=tf2
env: TEST_MODE=TF2
install:
# code below is taken from http://conda.pydata.org/docs/travis.html
# We do this conditionally because it saves us some downloading if the
Expand Down Expand Up @@ -37,7 +37,7 @@ script:
- if [[ "$TEST_MODE" == "INTEGRATION_TESTS" ]]; then
PYTHONPATH=$PWD:$PYTHONPATH py.test tests/integration_tests;
elif [[ "$TEST_MODE" == "PEP8" ]]; then
PYTHONPATH=$PWD:$PYTHONPATH py.test --pep8 -m pep8 -n0;
PYTHONPATH=$PWD:$PYTHONPATH py.test kerastuner/ --pep8 -m pep8 -n0;
else
PYTHONPATH=$PWD:$PYTHONPATH py.test tests/kerastuner --cov-config .coveragerc --cov=kerastuner;
fi
6 changes: 3 additions & 3 deletions kerastuner/abstractions/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Copyright 2019 The Keras Tuner Authors
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#
# https://www.apache.org/licenses/LICENSE-2.0
#
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down
9 changes: 5 additions & 4 deletions kerastuner/abstractions/display.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Copyright 2019 The Keras Tuner Authors
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#
# https://www.apache.org/licenses/LICENSE-2.0
#
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -14,7 +14,8 @@

# -*- coding: utf-8 -*-

"display utilities"
"""Display utilities."""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
Expand Down
6 changes: 3 additions & 3 deletions kerastuner/abstractions/io/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Copyright 2019 The Keras Tuner Authors
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#
# https://www.apache.org/licenses/LICENSE-2.0
#
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down
30 changes: 17 additions & 13 deletions kerastuner/abstractions/io/io.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Copyright 2019 The Keras Tuner Authors
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#
# https://www.apache.org/licenses/LICENSE-2.0
#
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -18,15 +18,17 @@
from kerastuner.abstractions.display import warning
import json


def Open(name, mode):
"""Open a file.
Args:
name (str): name of the file
mode (str): one of 'r', 'w', 'a', 'r+', 'w+', 'a+'. Append 'b' for bytes mode.
mode (str): one of 'r', 'w', 'a', 'r+', 'w+', 'a+'.
Append 'b' for bytes mode.
Returns:
GFile - a GFile object representing the opened file.
GFile - a GFile object representing the opened file.
"""
return tf.io.gfile.Open(name, mode)

Expand Down Expand Up @@ -94,7 +96,7 @@ def remove(path):
path: string, a path
Raises:
errors.OpError: Propagates any errors reported by the FileSystem API. E.g.,
errors.OpError: Propagates any errors reported by the FileSystem API.
NotFoundError if the path does not exist.
"""
return tf.io.gfile.remove(path)
Expand All @@ -106,8 +108,8 @@ def copy(src, dst, overwrite=False):
Args:
src: string, name of the file whose contents need to be copied
dst: string, name of the file to which to copy to
overwrite: boolean, if false its an error for newpath to be occupied by an
existing file.
overwrite: boolean, if false it is an error
for newpath to be occupied by an existing file.
Raises:
errors.OpError: If the operation fails.
Expand Down Expand Up @@ -162,12 +164,14 @@ def create_directory(path, remove_existing=False):


def get_config_filename(tuner_state, instance_state, execution_state):
""" Get the filename containing the model configuration for the given instance/execution.
"""Get the filename containing the model config.
Args:
tuner_state: TunerState, state of the tuner.
instance: Instance, the instance for which we are getting the configuration.
execution: Execution, the execution for which we are getting the configuration.
instance: Instance, the instance for which
we are getting the configuration.
execution: Execution, the execution for which
we are getting the configuration.
Returns:
str, the file which holds the model configuration.
Expand All @@ -184,7 +188,7 @@ def get_config_filename(tuner_state, instance_state, execution_state):


def get_weights_filename(tuner_state, instance_state, execution_state):
""" Get the filename containing the model weights for the given instance/execution.
""" Get the filename containing the model weights.
Args:
tuner_state: TunerState, state of the tuner.
Expand All @@ -206,7 +210,7 @@ def get_weights_filename(tuner_state, instance_state, execution_state):


def get_results_filename(tuner_state, instance_state):
""" Get the filename containing the results metadata for the given instance.
""" Get the filename containing the results metadata.
Args:
tuner_state: TunerState, state of the tuner.
Expand Down
6 changes: 3 additions & 3 deletions kerastuner/abstractions/tensorflow/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Copyright 2019 The Keras Tuner Authors
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#
# https://www.apache.org/licenses/LICENSE-2.0
#
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down
27 changes: 14 additions & 13 deletions kerastuner/abstractions/tensorflow/proxy.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Copyright 2019 The Keras Tuner Authors
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
Expand Down Expand Up @@ -68,7 +68,8 @@ def exists(self, path):
filesystem errors.
Raises:
errors.OpError: Propagates any errors reported by the FileSystem API.
errors.OpError: Propagates any errors
reported by the FileSystem API.
"""

@abstractmethod
Expand All @@ -90,7 +91,8 @@ def glob(self, pattern):
pattern: string or iterable of strings. The glob pattern(s).
Returns:
A list of strings containing filenames that match the given pattern(s).
A list of strings containing filenames that
match the given pattern(s).
Raises:
errors.OpError: If there are filesystem / directory listing errors.
Expand All @@ -104,7 +106,8 @@ def remove(self, path):
path: string, a path
Raises:
errors.OpError: Propagates any errors reported by the FileSystem API.
errors.OpError: Propagates any errors reported
by the FileSystem API.
"""

@abstractmethod
Expand All @@ -114,8 +117,8 @@ def copy(self, src, dst, overwrite=False):
Args:
src: string, name of the file whose contents need to be copied
dst: string, name of the file to which to copy to
overwrite: boolean, if false its an error for newpath to be occupied
by an existing file.
overwrite: boolean, if false its an error for
newpath to be occupied by an existing file.
Raises:
errors.OpError: If the operation fails.
Expand Down Expand Up @@ -167,7 +170,6 @@ def __init__(self, tf_proxy):
self.tf_proxy = tf_proxy

def compute_model_size(self, model):
"Compute the size of a given model, in terms of the number of parameters."
params = [self.tf_proxy.keras.backend.count_params(
p) for p in set(model.trainable_weights)]
return int(np.sum(params))
Expand All @@ -181,8 +183,8 @@ def serialize_loss(self, loss):
Args:
loss - One of the following:
(str): Name of one of the loss functions known to Keras.
(Callable): A function or callable object. Must be registered as a
Keras loss.
(Callable): A function or callable object.
Must be registered as a Keras loss.
(dict): A dictionary mapping output nodes to loss functions in
string or callable form. Loss functions must be represented
as a str or Callable, as above.
Expand Down Expand Up @@ -233,8 +235,7 @@ def freeze_graph(
saved_model_path,
output_graph_path,
output_tensor_names):
"""
Create a frozen version of the specified saved model.
"""Create a frozen version of the specified saved model.
This cannot be done in the main session, as the names will conflict
with the existing model. Rather than resorting to manipulating
Expand Down Expand Up @@ -467,8 +468,8 @@ def create_directory(self, path, remove_existing=False):
if not self.tf_proxy.io.gfile.exists(path):
self.tf_proxy.io.gfile.makedirs(path)

# If it does exist, and remove_existing it specified, the directory will be
# removed and recreated.
# If it does exist, and remove_existing it specified,
# the directory will be removed and recreated.
elif remove_existing:
self.tf_proxy.io.gfile.rmtree(path)
self.tf_proxy.io.gfile.makedirs(path)
Expand Down
32 changes: 19 additions & 13 deletions kerastuner/abstractions/tensorflow/tensorflow_1_x.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Copyright 2019 The Keras Tuner Authors
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#
# https://www.apache.org/licenses/LICENSE-2.0
#
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -32,7 +32,8 @@ def Open(self, name, mode):
Args:
name (str): name of the file
mode (str): one of 'r', 'w', 'a', 'r+', 'w+', 'a+'. Append 'b' for bytes mode.
mode (str): one of 'r', 'w', 'a', 'r+', 'w+', 'a+'.
Append 'b' for bytes mode.
Returns:
GFile - a GFile object representing the opened file.
Expand All @@ -59,10 +60,12 @@ def exists(self, path):
Returns:
True if the path exists, whether it's a file or a directory.
False if the path does not exist and there are no filesystem errors.
False if the path does not exist
and there are no filesystem errors.
Raises:
errors.OpError: Propagates any errors reported by the FileSystem API.
errors.OpError: Propagates any errors
reported by the FileSystem API.
"""
return tf.io.gfile.exists(path)

Expand Down Expand Up @@ -98,8 +101,8 @@ def remove(self, path):
path: string, a path
Raises:
errors.OpError: Propagates any errors reported by the FileSystem API. E.g.,
NotFoundError if the path does not exist.
errors.OpError: Propagates any errors reported by the FileSystem API.
NotFoundError if the path does not exist.
"""
return tf.io.gfile.remove(path)

Expand All @@ -109,8 +112,8 @@ def copy(self, src, dst, overwrite=False):
Args:
src: string, name of the file whose contents need to be copied
dst: string, name of the file to which to copy to
overwrite: boolean, if false its an error for newpath to be occupied by an
existing file.
overwrite: boolean, if false its an error for newpath
to be occupied by an existing file.
Raises:
errors.OpError: If the operation fails.
Expand Down Expand Up @@ -193,8 +196,10 @@ def optimize_graph(self, frozen_model_path, input_ops, output_ops,
return transformed_graph_def

def clear_tf_session(self):
"""Clear the tensorflow graph/session. Used to avoid OOM issues related to
having numerous models."""
"""Clear the tensorflow graph/session.
Used to avoid OOM issues related to having numerous models.
"""

tf.keras.backend.clear_session()
gc.collect()
Expand Down Expand Up @@ -236,7 +241,8 @@ def save_model(self,
and operations. See:
https://github.com/tensorflow/tensorflow/tree/master/tensorflow/tools/graph_transforms
"tf_lite" - A TF Lite model.
tmp_path (str, optional): directory in which to store temporary files.
tmp_path (str, optional): directory in which
to store temporary files.
"""

KNOWN_OUTPUT_TYPES = [
Expand Down
Loading

0 comments on commit 0bb241e

Please sign in to comment.