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

Update TF version #31

Merged
merged 1 commit into from
Sep 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Update TF version
  • Loading branch information
tushuhei committed Sep 16, 2021
commit 1ecd083322236e3714290cab78541e99f05dd0b2
14 changes: 7 additions & 7 deletions mozc-nazoru/bin/nazoru-training
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from tensorflow.contrib import slim
from tensorflow.contrib.slim.python.slim.learning import train_step
import tf_slim as slim
from tensorflow.python.framework import dtypes
from tensorflow.python.framework import graph_util
from tensorflow.python.platform import gfile
Expand All @@ -31,7 +30,7 @@ import nazoru.core as nazoru
import numpy as np
import os
import sys
import tensorflow as tf
import tensorflow.compat.v1 as tf
import zipfile

FLAGS = None
Expand Down Expand Up @@ -139,6 +138,7 @@ def main(_):
nazoru.DepthSepConv(kernel=[3, 3], stride=1, depth=128),
]

tf.disable_eager_execution()
with tf.Graph().as_default():
tf.logging.set_verbosity(tf.logging.INFO)

Expand Down Expand Up @@ -176,7 +176,7 @@ def main(_):
train_op = slim.learning.create_train_op(train_total_loss, optimizer)

def train_step_fn(sess, *args, **kwargs):
total_loss, should_stop = train_step(sess, *args, **kwargs)
total_loss, should_stop = slim.learning.train_step(sess, *args, **kwargs)
if train_step_fn.step % FLAGS.n_steps_to_log == 0:
val_acc = sess.run(val_accuracy)
tf_logging.info('step: %d, validation accuracy: %.3f' % (
Expand Down Expand Up @@ -236,19 +236,19 @@ if __name__ == '__main__':
parser.add_argument(
'--output_graph',
type=str,
default='nazoru.pb',
default='nazoru_custom.pb',
help='Where to save the trained graph.'
)
parser.add_argument(
'--optimized_output_graph',
type=str,
default='optimized_nazoru.pb',
default='optimized_nazoru_custom.pb',
help='Where to save the trained graph optimized for inference.'
)
parser.add_argument(
'--saved_model_dir',
type=str,
default='nazoru_saved_model',
default='nazoru_saved_model_custom',
help='Where to save the exported graph.'
)
parser.add_argument(
Expand Down
8 changes: 3 additions & 5 deletions mozc-nazoru/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,10 @@ def read_file(name):
# data_files=[('/etc/systemd/system', ['data/nazoru.service'])],

install_requires=[
'np_utils',
'cairocffi<=1.0.0',
'h5py',
'cairocffi',
'pillow',
'tensorflow~=1.15.4',
'markdown<=3.0.1',
'tensorflow~=2.5.1',
'tf_slim~=1.1.0',
'enum34;python_version<"3.4"',
'pyserial',
'evdev;platform_system=="Linux"',
Expand Down
6 changes: 3 additions & 3 deletions mozc-nazoru/src/nazoru/nazorunet.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"""

from collections import namedtuple
from tensorflow.contrib import slim
import tensorflow as tf
import tf_slim as slim
import tensorflow.compat.v1 as tf

Conv = namedtuple('Conv', ['kernel', 'stride', 'depth'])
DepthSepConv = namedtuple('DepthSepConv', ['kernel', 'stride', 'depth'])
Expand Down Expand Up @@ -161,7 +161,7 @@ def nazorunet(inputs,
is_training=True,
min_depth=8,
depth_multiplier=1.0,
prediction_fn=tf.contrib.layers.softmax,
prediction_fn=slim.layers.softmax,
spatial_squeeze=True,
reuse=None,
scope='NazoruNet',
Expand Down
4 changes: 2 additions & 2 deletions mozc-nazoru/src/nazoru/predictor.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

def _load_graph(model_file):
graph = tf.Graph()
graph_def = tf.GraphDef()
graph_def = tf.compat.v1.GraphDef()
with open(model_file, "rb") as f:
graph_def.ParseFromString(f.read())
with graph.as_default():
Expand All @@ -44,7 +44,7 @@ def _predict(self, data):
inputs = lib.keydowns2image(data, True, True, 16, 2)
inputs = np.expand_dims(inputs, axis=0)
with utils.Measure('sess.run'):
with tf.Session(graph=self._graph) as sess:
with tf.compat.v1.Session(graph=self._graph) as sess:
result = sess.run(self._output_operation.outputs[0],
{self._input_operation.outputs[0]: inputs})[0]
return result
Expand Down