Comments (3)
finally I worked it out, here is the code for 1 case inference @tom-samsung
import numpy as np
import tensorflow.compat.v1 as tf
#To make tf 2.0 compatible with tf1.0 code, we disable the tf2.0 functionalities
tf.disable_eager_execution()
from tensorflow.python.client import session
from tensorflow.python.framework import importer
from tensorflow.python.framework import ops
from tensorflow.python.summary import summary
from tensorflow.python.tools import saved_model_utils
from tensorflow.core.framework import graph_pb2 as gpb
from google.protobuf import text_format as pbtf
def extract_tensors(signature_def, graph):
output = dict()
for key in signature_def:
value = signature_def[key]
if isinstance(value, tf.TensorInfo):
output[key] = graph.get_tensor_by_name(value.name)
return output
def extract_input_name(signature_def, graph):
input_tensors = extract_tensors(signature_def['serving_default'].inputs, graph)
#Assuming one input in model.
name_list = []
for key in list(input_tensors.keys()):
name_list.append(input_tensors.get(key).name)
return name_list
def extract_output_name(signature_def, graph):
output_tensors = extract_tensors(signature_def['serving_default'].outputs, graph)
#Assuming one output in model.
name_list = []
for key in list(output_tensors.keys()):
name_list.append(output_tensors.get(key).name)
return name_list
def ass_input_dict(tensor_input_sample):
dict_input = {str(i+1)+":0" : [tensor_input_sample[i]] for i in range(len(tensor_input_sample))}
return dict_input
checkpoint_path = "/tmp/run/tuner-1/160/saved_model/assets/"
with tf.Session(graph=tf.Graph()) as sess:
serve = tf.saved_model.load(sess, tags=["serve"], export_dir=checkpoint_path)
#print(type(model)) <class 'tensorflow.core.protobuf.meta_graph_pb2.MetaGraphDef'>
#input_tensor_name = extract_input_name(serve.signature_def, sess.graph)
output_tensor_name = extract_output_name(serve.signature_def, sess.graph)
input_dict = ass_input_dict(sen_vec.detach().numpy())
prediction = sess.run(output_tensor_name, feed_dict=input_dict)
print(prediction)
from model_search.
Hi tom, I just downloaded and re-installed the latest version, there is new folder generated with .pb file for each model, I think it might make things easier
from model_search.
Hey @Xiaoping777
thanks for the code. yes, I noticed that with a new version of repo and saved_models things are much easier now.
Unfortunately, I need to re-run everything but it's ok.
I'll try to wrap this up into keras lambda layer to have this additional option for people who have keras pipelines and post it somewhere. Maybe authors of this repo will update readme with all those information to make people lives easier before closing those issues:
#43
#39
Thanks again and happy model searching!
from model_search.
Related Issues (20)
- How to Train a model with 2 dimensional dataset , ie. sentence with wordVec
- RuntimeError: Error when executing query: file is not a database query
- Could it search for models that use time series such as RNN HOT 5
- Evaluating Model Search Results HOT 7
- Model Architecture Output? HOT 2
- Is there anyway we can use model_search for object detection also ?
- Is it feasible to use MirroredStrategy for training?
- I'm confused by distributed search, any suggestions are welcomed!
- RuntimeError: Cannot connect sqlite3 database: unable to open database file HOT 2
- Neural Network Architecture Details HOT 3
- Documentation for Utilizing Output of Model Search?
- Possible beta for Regression Modeling? HOT 1
- Training on Multiclass Image Dataset HOT 1
- How to predict from model_search saved_model.pb HOT 3
- How to know which model is the best and what is its accuracy? HOT 4
- AttributeError: module 'ml_metadata.metadata_store' has no attribute 'MetadataStore' HOT 1
- UnicodedecodeErroe HOT 1
- sqlite default filename is not Windows compatible
- AttributeError: 'Tensor' object has no attribute 'numpy'
- Project dependencies may have API risk issues
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from model_search.