From f7b154f69cee327187f85e8ea9f6121f3116eccb Mon Sep 17 00:00:00 2001
From: Samuel Marks <807580+SamuelMarks@users.noreply.github.com>
Date: Thu, 2 Jan 2020 12:45:18 +1100
Subject: [PATCH 1/2] [scripts/load_efficientnet.py] TensorFlow 2 support
---
scripts/load_efficientnet.py | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/scripts/load_efficientnet.py b/scripts/load_efficientnet.py
index 67372f1..ec786ba 100644
--- a/scripts/load_efficientnet.py
+++ b/scripts/load_efficientnet.py
@@ -93,14 +93,14 @@ def convert_tensorflow_model(
""" Loads and saves a TensorFlow model. """
image_files = [example_img]
eval_ckpt_driver = eval_ckpt_main.EvalCkptDriver(model_name)
- with tf.Graph().as_default(), tf.Session() as sess:
+ with tf.Graph().as_default(), tf.compat.v1.Session() as sess:
images, _ = eval_ckpt_driver.build_dataset(
image_files, [0] * len(image_files), False
)
eval_ckpt_driver.build_model(images, is_training=False)
- sess.run(tf.global_variables_initializer())
+ sess.run(tf.compat.v1.global_variables_initializer())
eval_ckpt_driver.restore_model(sess, model_ckpt)
- global_variables = tf.global_variables()
+ global_variables = tf.compat.v1.global_variables()
weights = dict()
for variable in global_variables:
try:
From ba81b59c08d5cddf63a58843caa48d045a0570ab Mon Sep 17 00:00:00 2001
From: Samuel Marks <807580+SamuelMarks@users.noreply.github.com>
Date: Thu, 2 Jan 2020 12:54:02 +1100
Subject: [PATCH 2/2] [*.py,README.md] Minor linting fixes
---
README.md | 4 ++--
efficientnet/__init__.py | 2 ++
efficientnet/model.py | 6 ++----
efficientnet/preprocessing.py | 2 +-
scripts/load_efficientnet.py | 14 ++++++--------
setup.py | 5 +++--
tests/test_model.py | 2 +-
7 files changed, 17 insertions(+), 18 deletions(-)
diff --git a/README.md b/README.md
index 896b174..579be70 100644
--- a/README.md
+++ b/README.md
@@ -25,10 +25,10 @@ EfficientNets rely on AutoML and compound scaling to achieve superior performanc
diff --git a/efficientnet/__init__.py b/efficientnet/__init__.py
index 44a90ad..8350bd7 100644
--- a/efficientnet/__init__.py
+++ b/efficientnet/__init__.py
@@ -35,6 +35,7 @@ def get_submodules_from_kwargs(kwargs):
def inject_keras_modules(func):
import keras
+
@functools.wraps(func)
def wrapper(*args, **kwargs):
kwargs['backend'] = keras.backend
@@ -48,6 +49,7 @@ def wrapper(*args, **kwargs):
def inject_tfkeras_modules(func):
import tensorflow.keras as tfkeras
+
@functools.wraps(func)
def wrapper(*args, **kwargs):
kwargs['backend'] = tfkeras.backend
diff --git a/efficientnet/model.py b/efficientnet/model.py
index b5de6f4..c094c7a 100644
--- a/efficientnet/model.py
+++ b/efficientnet/model.py
@@ -27,15 +27,12 @@
from __future__ import print_function
import os
-import json
import math
import string
import collections
-import numpy as np
from six.moves import xrange
from keras_applications.imagenet_utils import _obtain_input_shape
-from keras_applications.imagenet_utils import decode_predictions
from keras_applications.imagenet_utils import preprocess_input as _preprocess_input
from . import get_submodules_from_kwargs
@@ -139,6 +136,7 @@ def preprocess_input(x, **kwargs):
def get_swish(**kwargs):
backend, layers, models, keras_utils = get_submodules_from_kwargs(kwargs)
+
def swish(x):
"""Swish activation function: x * sigmoid(x).
Reference: [Searching for Activation Functions](https://arxiv.org/abs/1710.05941)
@@ -153,7 +151,7 @@ def swish(x):
pass
return x * backend.sigmoid(x)
- return swish
+ return swish
def get_dropout(**kwargs):
diff --git a/efficientnet/preprocessing.py b/efficientnet/preprocessing.py
index 079b4b4..7735f85 100644
--- a/efficientnet/preprocessing.py
+++ b/efficientnet/preprocessing.py
@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
-import numpy as np
+
from skimage.transform import resize
MAP_INTERPOLATION_TO_ORDER = {
diff --git a/scripts/load_efficientnet.py b/scripts/load_efficientnet.py
index ec786ba..b167e74 100644
--- a/scripts/load_efficientnet.py
+++ b/scripts/load_efficientnet.py
@@ -17,8 +17,6 @@
import argparse
import sys
-import numpy as np
-
import tensorflow as tf
import efficientnet.keras
from keras.layers import BatchNormalization, Conv2D, Dense
@@ -149,15 +147,15 @@ def convert_tensorflow_model(
default="true",
help="Whether to include metadata in the serialized Keras model",
)
- args = parser.parse_args()
+ cli_args = parser.parse_args()
- sys.path.append(args.source)
+ sys.path.append(cli_args.source)
import eval_ckpt_main
true_values = ("yes", "true", "t", "1", "y")
convert_tensorflow_model(
- model_name=args.model_name,
- model_ckpt=args.tf_checkpoint,
- output_file=args.output_file,
- weights_only=args.weights_only in true_values,
+ model_name=cli_args.model_name,
+ model_ckpt=cli_args.tf_checkpoint,
+ output_file=cli_args.output_file,
+ weights_only=cli_args.weights_only in true_values,
)
diff --git a/setup.py b/setup.py
index 159e1a8..461c9db 100644
--- a/setup.py
+++ b/setup.py
@@ -1,3 +1,6 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
# Copyright 2019 The TensorFlow Authors, Pavel Yakubovskiy. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -12,8 +15,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
# Note: To use the 'upload' functionality of this file, you must:
# $ pip install twine
diff --git a/tests/test_model.py b/tests/test_model.py
index 40b1ec1..9ca0471 100644
--- a/tests/test_model.py
+++ b/tests/test_model.py
@@ -71,4 +71,4 @@ def test_models_result(args):
if __name__ == "__main__":
- pytest.main([__file__])
\ No newline at end of file
+ pytest.main([__file__])