Update TF version

This commit is contained in:
Shuhei Iitsuka
2021-09-16 12:55:38 +09:00
parent 85c6365235
commit 1ecd083322
4 changed files with 15 additions and 17 deletions

View File

@@ -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
@@ -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
@@ -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)
@@ -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' % (
@@ -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(

View File

@@ -59,12 +59,10 @@ setup(
# 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"',

View File

@@ -20,8 +20,8 @@ predict input characters from visualized trace.
"""
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'])
@@ -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',

View File

@@ -23,7 +23,7 @@ import numpy as np
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():
@@ -44,7 +44,7 @@ class NazoruPredictor():
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