Comments (6)
Does Tensorflow Java API support .tflite file format?
AFAIK, it does not and I don't know what would be the amount of work to support it.
Ideally, you would still have access to the original .pb
model that was used to generate the TF Lite version and use that one instead, as there are no real gain running a .tflite
model if your application has access to the complete set of TF ops, as provided by TF Java. But if you are planning to use TF Lite models distributed on the public hub, it is possible that the original .pb
file is "lost", unless you reach and ask the author directly.
from java.
Sorry to resurrect a dead issue, however...
as there are no real gain running a .tflite model if your application has access to the complete set of TF ops, as provided by TF Java
I was under the assumption that post training quantization required use of the tflite model. In our scenario, we're interested in taking a SavedModel
with (a full .pb
file) and quantizing it before using it with tensorflow/java
bindings. Is that doable at all?
from java.
I think the TF implementation of it emits a tflite model, but there's no reason you couldn't do the ops by hand and save out a new SavedModel
.
from java.
@Craigacp that sounds interesting! Sadly, I'm rather new to using non-python interfaces to tensorflow. Could you expand, or link to any resources for what "do the ops by hand" mean?
Currently, we're trying to specifically utilize this TF1 model: universal sentence encoder version 3. I'm able to get it into a suitable SavedModel
format with some python code as follows:
# using tensorflow version 1.15.4
def save_module(url, save_path, input_type):
with tf.Graph().as_default():
module = hub.Module(url)
model_input = tf.compat.v1.placeholder(input_type, name="input")
model_output = tf.identity(module(model_input), name="output")
with tf.compat.v1.Session() as session:
session.run(tf.compat.v1.global_variables_initializer())
tf.compat.v1.saved_model.simple_save(
session,
save_path,
inputs={"input": model_input},
outputs={"output": model_output},
legacy_init_op=tf.compat.v1.initializers.tables_initializer(
name="init_all_tables"
),
)
output_path = "/opt/model"
url = "https://tfhub.dev/google/universal-sentence-encoder-large/3"
save_module(
url,
output_path,
tf.string,
)
This is because the version of the the hub module didn't have a tag and I had issues loading it with the tag-set value of ''
:
❯ saved_model_cli show --all --dir .
MetaGraphDef with tag-set: '' contains the following SignatureDefs:
signature_def['default']:
The given SavedModel SignatureDef contains the following input(s):
inputs['text'] tensor_info:
dtype: DT_STRING
shape: (-1)
name: Placeholder:0
The given SavedModel SignatureDef contains the following output(s):
outputs['default'] tensor_info:
dtype: DT_FLOAT
shape: (-1, 512)
name: Encoder_en/hidden_layers/l2_normalize:0
Method name is:
After resaving it though, it works. My hope was I'd be able to just quantize the model too (its around 750mb). I'd be interested in any resources or examples of what you're suggesting - I apologize in advance for my cluelessness 🙇
from java.
I had assumed that tflite would perform the transformation operations in python and so we could apply the same operations in Java (similar to the graph freezing). Unfortunately that's not the case, and so while you could naively replicate the model structure using int8 tensors and quantize the fp32 weights manually I'm not sure it would work that well (especially on a complex model like USE).
You might be able to use the graph transform tool to perform the quantization. It looks like it supports it, and should be able to write it back out to a frozen graph or a saved model, both of which are supported in Java.
Otherwise it looks like the options are limited for a pure TensorFlow-Java solution.
from java.
Great! I'll investigate that approach. Thanks for the pointer!
from java.
Related Issues (20)
- ivy dependency not working on windows or linux, native TF code not found on classpath HOT 5
- Could not load dynamic library 'xxxxx'; dlerror: xxxxx.dll not found HOT 5
- org.tensorflow.TensorFlowException: Can't parse /<modelPath>/<somePathToFolder>/saved_model.pb as binary proto - JDK 17 HOT 15
- Compiling from source, cuDNN version is not compatible? How can I change the cuDNN compile version? HOT 2
- SavedModelBundle Unable to Load Models with coo_sparse Encoded Input HOT 1
- Tensor type issue HOT 3
- Unable to build the project using 'mvn install ' command HOT 4
- how to use importGraphDef to load model.pb file? HOT 2
- Modular Java app can't create tensor object HOT 3
- Read/Write method of DataBuffer is against intuition HOT 1
- Distributing an Apple Silicon binary HOT 2
- Error when using tensorflow-text on tensorflow-core HOT 8
- Reductions on losses that have dynamic size
- No documentation for 1.0.0 HOT 5
- The loss CatagoricalCrossEntropy is currently unusable in framework
- Build native codes current master fails HOT 4
- Native artifacts are pulling transitive dependencies
- Q: How to add Regularizer and Constraint effect correctly to a weight/bias variable or activity? HOT 1
- Which is the "org.tensorflow.Tensor#create(java.lang.Object)" substitute? HOT 2
- right dependency for org.tensorflow.proto.framework? HOT 3
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 java.