Post-training quantization with tflite cause runtime error - python

I am trying to quantize my model (specifically pretrained faster_rcnn_inception_v2 on coco, that was downloaded from the model zoo), in hopes to speedup inference time.
I use the following code from here:
import tensorflow as tf
converter = tf.lite.TocoConverter.from_saved_model(saved_model_dir)
converter.post_training_quantize = True
tflite_quantized_model = converter.convert()
open("quantized_model.tflite", "wb").write(tflite_quantized_model)
Models directory didnt have saved_model.pb file. So i renamed frozen_inference_graph.pb to saved_model.pb.
Running the code above produce the following runtime error:
Traceback (most recent call last):
File "/home/juggernaut/pycharm-community-2018.2.4/helpers/pydev/pydevd.py", line 1664, in <module>
main()
File "/home/juggernaut/pycharm-community-2018.2.4/helpers/pydev/pydevd.py", line 1658, in main
globals = debugger.run(setup['file'], None, None, is_module)
File "/home/juggernaut/pycharm-community-2018.2.4/helpers/pydev/pydevd.py", line 1068, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "/hdd/motorola/motorola_heads/tensorflow_face_detection/quantize.py", line 5, in <module>
converter = tf.lite.TocoConverter.from_saved_model(saved_model_dir)
File "/hdd/motorola/venv_py27_tf1.10/local/lib/python2.7/site-packages/tensorflow/python/util/deprecation.py", line 318, in new_func
return func(*args, **kwargs)
File "/hdd/motorola/venv_py27_tf1.10/local/lib/python2.7/site-packages/tensorflow/lite/python/lite.py", line 587, in from_saved_model
tag_set, signature_key)
File "/hdd/motorola/venv_py27_tf1.10/local/lib/python2.7/site-packages/tensorflow/lite/python/lite.py", line 376, in from_saved_model
output_arrays, tag_set, signature_key)
File "/hdd/motorola/venv_py27_tf1.10/local/lib/python2.7/site-packages/tensorflow/lite/python/convert_saved_model.py", line 254, in freeze_saved_model
meta_graph = get_meta_graph_def(saved_model_dir, tag_set)
File "/hdd/motorola/venv_py27_tf1.10/local/lib/python2.7/site-packages/tensorflow/lite/python/convert_saved_model.py", line 61, in get_meta_graph_def
return loader.load(sess, tag_set, saved_model_dir)
File "/hdd/motorola/venv_py27_tf1.10/local/lib/python2.7/site-packages/tensorflow/python/util/deprecation.py", line 318, in new_func
return func(*args, **kwargs)
File "/hdd/motorola/venv_py27_tf1.10/local/lib/python2.7/site-packages/tensorflow/python/saved_model/loader_impl.py", line 269, in load
return loader.load(sess, tags, import_scope, **saver_kwargs)
File "/hdd/motorola/venv_py27_tf1.10/local/lib/python2.7/site-packages/tensorflow/python/saved_model/loader_impl.py", line 420, in load
**saver_kwargs)
File "/hdd/motorola/venv_py27_tf1.10/local/lib/python2.7/site-packages/tensorflow/python/saved_model/loader_impl.py", line 347, in load_graph
meta_graph_def = self.get_meta_graph_def_from_tags(tags)
File "/hdd/motorola/venv_py27_tf1.10/local/lib/python2.7/site-packages/tensorflow/python/saved_model/loader_impl.py", line 323, in get_meta_graph_def_from_tags
" could not be found in SavedModel. To inspect available tag-sets in"
RuntimeError: MetaGraphDef associated with tags set(['serve']) could not be found in SavedModel. To inspect available tag-sets in the SavedModel, please use the SavedModel CLI: `saved_model_cli`
What does it mean and what should i do?

Please refer to this issue. They seem to have the same issue as you.
This may be fixed in a more recent version of Tensorflow (perhaps the tag has switched from 'serve' to 'serving' in the meantime).

You should use tf.saved_model.simple_save to save the pb model.

Related

pyspark unable load pipelineModel

I met a problem, unable to load PipelineModel
I test my model in practice environment, but unable to apply this model and code on production environment
Traceback (most recent call last):
File "/home/fwfx_yaofei/telbd-yjy/src/ml/complain_user_it/predict/model_predict.py", line 228, in <module>
main(xdr_input_file,model_file,xdr_output_file)
File "/home/fwfx_yaofei/telbd-yjy/src/ml/complain_user_it/predict/model_predict.py", line 215, in main
xdr_df_predict = xdr_predict(xdr_df,model_file)
File "/home/fwfx_yaofei/telbd-yjy/src/ml/complain_user_it/predict/model_predict.py", line 193, in xdr_predict
loadmodel = PipelineModel.load(model_input_path)
File "/usr/bch/1.5.0/spark/python/lib/pyspark.zip/pyspark/ml/util.py", line 257, in load
File "/usr/bch/1.5.0/spark/python/lib/pyspark.zip/pyspark/ml/util.py", line 197, in load
File "/usr/bch/1.5.0/spark/python/lib/py4j-0.10.4-src.zip/py4j/java_gateway.py", line 1133, in __call__
File "/usr/bch/1.5.0/spark/python/lib/pyspark.zip/pyspark/sql/utils.py", line 79, in deco
pyspark.sql.utils.IllegalArgumentException: 'requirement failed: Error loading metadata: Expected class name org.apache.spark.ml.PipelineModel but found class name pyspark.ml.pipeline.PipelineModel'
21/12/01 12:01:06 INFO SparkContext: Invoking stop() from shutdown hook
Thanks all the help.I am a intern in bigdata industry.This is my first time to post in stackoverflow,i am sorry to post in unreguired method.
Finally,i sovled this problem to adjust my code from spark2.4 to spark2.2.
Here is details about this tracesback:
I test my code in test environment under the version of spark2.4 and python3.7; i meet error when i deploy it in product environment under the version of spark2.2 and python3.7.
I train model under product envirenment, this si Model generate error:
Traceback (most recent call last):
File "/home/fwfx_yaofei/telbd-yjy/src/ml/complain_user_it/train/model_generate.py", line 331, in
main(xdr_file_path,jingfeng_file_path,save_model_path)
File "/home/fwfx_yaofei/telbd-yjy/src/ml/complain_user_it/train/model_generate.py", line 318, in main
tvs_piplineModel, gbdt_bestModel = generate_model(label_col, xdr_75109_String_title, union_df, save_model_path)
File "/home/fwfx_yaofei/telbd-yjy/src/ml/complain_user_it/train/model_generate.py", line 310, in generate_model
tvs_piplineModel.save(save_model_path)
File "/usr/bch/1.5.0/spark/python/lib/pyspark.zip/pyspark/ml/pipeline.py", line 217, in save
File "/usr/bch/1.5.0/spark/python/lib/pyspark.zip/pyspark/ml/pipeline.py", line 212, in write
File "/usr/bch/1.5.0/spark/python/lib/pyspark.zip/pyspark/ml/util.py", line 100, in init
File "/usr/bch/1.5.0/spark/python/lib/pyspark.zip/pyspark/ml/pipeline.py", line 249, in _to_java
AttributeError: 'TrainValidationSplitModel' object has no attribute '_to_java'
when i skip model generate to model predict in model which i trained in test envirenment,this is Model predict error:
Traceback (most recent call last):
File "/home/fwfx_yaofei/telbd-yjy/src/ml/complain_user_it/predict/model_predict.py", line 228, in
main(xdr_input_file,model_file,xdr_output_file)
File "/home/fwfx_yaofei/telbd-yjy/src/ml/complain_user_it/predict/model_predict.py", line 215, in main
xdr_df_predict = xdr_predict(xdr_df,model_file)
File "/home/fwfx_yaofei/telbd-yjy/src/ml/complain_user_it/predict/model_predict.py", line 193, in xdr_predict
loadmodel = PipelineModel.load(model_input_path)
File "/usr/bch/1.5.0/spark/python/lib/pyspark.zip/pyspark/ml/util.py", line 257, in load
File "/usr/bch/1.5.0/spark/python/lib/pyspark.zip/pyspark/ml/util.py", line 197, in load
File "/usr/bch/1.5.0/spark/python/lib/py4j-0.10.4-src.zip/py4j/java_gateway.py", line 1133, in call
File "/usr/bch/1.5.0/spark/python/lib/pyspark.zip/pyspark/sql/utils.py", line 79, in deco
pyspark.sql.utils.IllegalArgumentException: 'requirement failed: Error loading metadata: Expected class name org.apache.spark.ml.PipelineModel but found class name pyspark.ml.pipeline.PipelineModel'
I check official document it explains ML persistence:version changes of ML persistence
So the error might casused by the vision of spark.
I ignore the "TrainValidationSplitModel" function which mention in first traceback,and it does work.My code run successfully.
Success run screenshot
Conclusion, my code aim to deploy a machine-learning classificaiton model in product environment. So i import pyspark.ml.gbdt to process dataframe. But i ignore the vision of test and product envirenoment.Thanks for all the help,this is the experience of an chinese intern.Forgive my pool expressive ability.

Resize method is not implemented Python

Hi I am working on a project to do segmentation for persons. Now I followed the code from https://pixellib.readthedocs.io/en/latest/Image_pascal.html#image-pascal and it is giving me an error: ValueError: Resize method is not implemented. in line 4.
import pixellib
from pixellib.semantic import semantic_segmentation
segment_video = semantic_segmentation()
segment_video.load_pascalvoc_model("deeplabv3_xception_tf_dim_ordering_tf_kernels.h5")
segment_video.process_video_pascalvoc("IMG_2649.mp4", overlay = True, frames_per_second= 15,
output_video_name="output.mp4")
Anyone know why this error is being triggered?
Error:
Traceback (most recent call last):
File "H:/Yolo/person_seg.py", line 4, in <module>
segment_video = semantic_segmentation()
File "G:\anaconda3\envs\yolo5\lib\site-packages\pixellib\semantic.py", line 23, in __init__
self.model = Deeplab_xcep_pascal()
File "G:\anaconda3\envs\yolo5\lib\site-packages\pixellib\deeplab.py", line 214, in Deeplab_xcep_pascal
method='bilinear', align_corners=True))(b4)
File "G:\anaconda3\envs\yolo5\lib\site-packages\tensorflow\python\keras\engine\base_layer.py", line 554, in __call__
outputs = self.call(inputs, *args, **kwargs)
File "G:\anaconda3\envs\yolo5\lib\site-packages\tensorflow\python\keras\layers\core.py", line 743, in call
return self.function(inputs, **arguments)
File "G:\anaconda3\envs\yolo5\lib\site-packages\pixellib\deeplab.py", line 214, in <lambda>
method='bilinear', align_corners=True))(b4)
File "G:\anaconda3\envs\yolo5\lib\site-packages\tensorflow\python\ops\image_ops_impl.py", line 960, in resize_images
name=None)
File "G:\anaconda3\envs\yolo5\lib\site-packages\tensorflow\python\ops\image_ops_impl.py", line 1088, in resize_images_v2
raise ValueError('Resize method is not implemented.')
ValueError: Resize method is not implemented.
Make sure to follow the initial steps prior installing the PixelLib library, since it requires the latest version of Tensorflow (Tensorflow 2.0+) as well as imgaug.

AssertionError: Torch not compiled with CUDA enabled for Key Information Extraction as Character-wise Classification with LSTM

Im trying to implement the train.py file from this repo but the error I'm getting is:
Traceback (most recent call last):
File "./src/train.py", line 74, in <module>
main()
File "./src/train.py", line 21, in main
model = MyModel0(len(VOCAB), 20, args.hidden_size).to(args.device)
File "/home/guest/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 426, in to
return self._apply(convert)
File "/home/guest/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 202, in _apply
module._apply(fn)
File "/home/guest/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 224, in _apply
param_applied = fn(param)
File "/home/guest/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 424, in convert
return t.to(device, dtype if t.is_floating_point() else None, non_blocking)
File "/home/guest/anaconda3/lib/python3.7/site-packages/torch/cuda/__init__.py", line 192, in _lazy_init
_check_driver()
File "/home/guest/anaconda3/lib/python3.7/site-packages/torch/cuda/__init__.py", line 95, in _check_driver
raise AssertionError("Torch not compiled with CUDA enabled")
AssertionError: Torch not compiled with CUDA enabled
Even though the # torch.backends.cudnn.enabled = False, I'm still getting this error. Maybe there's more GPU dependencies which I'm not familiar with. I'm not so familiar with PyTorch, any suggestions, please?

tensorflow.python.framework.errors_impl.NotFoundError: data/kitti_label_map.pbtxt; No such file or directory

I'm trying to convert the kitti dataset into the tensorflow .record. After I typed the command:
python object_detection/dataset_tools/create_kitti_tf_record.py
--lable_map_path=object_detection/data/kitti_label_map.pbtxt --data_dir=/Users/zhenglyu/Graduate/research/DataSet/kitti/data_object_image_2/testing/image_2
--output_path=/Users/zhenglyu/Graduate/research/DataSet/kitti2tf/train.record
validation_set_size=1000
I got this error:
Traceback (most recent call last): File
"object_detection/dataset_tools/create_kitti_tf_record.py", line 310,
in
tf.app.run() File "/Users/zhenglyu/tensorflow/lib/python3.6/site-packages/tensorflow/python/platform/app.py",
line 126, in run
_sys.exit(main(argv)) File "object_detection/dataset_tools/create_kitti_tf_record.py", line 307,
in main
validation_set_size=FLAGS.validation_set_size) File "object_detection/dataset_tools/create_kitti_tf_record.py", line 94,
in convert_kitti_to_tfrecords
label_map_dict = label_map_util.get_label_map_dict(label_map_path) File
"/Users/zhenglyu/Graduate/research/TensorFlow/model/research/object_detection/utils/label_map_util.py",
line 152, in get_label_map_dict
label_map = load_labelmap(label_map_path) File "/Users/zhenglyu/Graduate/research/TensorFlow/model/research/object_detection/utils/label_map_util.py",
line 132, in load_labelmap
label_map_string = fid.read() File "/Users/zhenglyu/tensorflow/lib/python3.6/site-packages/tensorflow/python/lib/io/file_io.py",
line 120, in read
self._preread_check() File "/Users/zhenglyu/tensorflow/lib/python3.6/site-packages/tensorflow/python/lib/io/file_io.py",
line 80, in _preread_check
compat.as_bytes(self.name), 1024 * 512, status) File "/Users/zhenglyu/tensorflow/lib/python3.6/site-packages/tensorflow/python/framework/errors_impl.py",
line 519, in __exit
c_api.TF_GetCode(self.status.status)) tensorflow.python.framework.errors_impl.NotFoundError:
data/kitti_label_map.pbtxt; No such file or directory
The file exists for sure. And I don't know why as I set the label_map_path to another one (object_detection/data/kitti_label_map.pbtxt), the path still remains the default setting (data/kitti_label_map.pbtxt).
I know there's a lot of related problem but none of the solutions that I found works for me. I used Virtualenv to install the tensorflow and using python 3.6. Could these be the problem? Thanks!
I don't have a definitive solution to this but here is what resolved it.
First, I copied the kitti_label_map.pbtxt into the data_dir. Then I also copied create_kitti_tf_record.py into the data_dir. And now I copied(this is what made it run in the end) the name and absolute path of the kitti_label_map.pbtxt and pasted it as label_map_path
I have no idea why but it worked.

Failed to execute Augustus PMML Gaslog Example. Need help to debug

I ran command testing the Gaslog example of Augutus:
Augustus consumer_config.xcfg
But got following error:
Traceback (most recent call last):
File "/usr/local/bin/Augustus", line 171, in <module>
main(config)
File "/usr/local/lib/python2.7/dist-packages/augustus/engine/mainloop.py", line 532, in main
mainLoop = MainLoop(configuration, dataStream=dataStream, rethrowExceptions=rethrowExceptions)
File "/usr/local/lib/python2.7/dist-packages/augustus/engine/mainloop.py", line 150, in __init__
self.model = xmlbase.loadfile(fileLocation, pmml.X_ODG_PMML, lineNumbers=True)
File "/usr/local/lib/python2.7/dist-packages/augustus/core/xmlbase.py", line 1628, in loadfile
return load(file(fileName), base, validation, dropSpecial, lineNumbers)
File "/usr/local/lib/python2.7/dist-packages/augustus/core/xmlbase.py", line 1807, in load
parser.parse(stream)
File "/usr/lib/python2.7/xml/sax/expatreader.py", line 107, in parse
xmlreader.IncrementalParser.parse(self, source)
File "/usr/lib/python2.7/xml/sax/xmlreader.py", line 123, in parse
self.feed(buffer)
File "/usr/lib/python2.7/xml/sax/expatreader.py", line 210, in feed
self._parser.Parse(data, isFinal)
File "/usr/lib/python2.7/xml/sax/expatreader.py", line 307, in end_element
self._cont_handler.endElement(name)
File "/usr/local/lib/python2.7/dist-packages/augustus/core/xmlbase.py", line 1728, in endElement
raise XMLValidationError("%sXMLValidationError: %s." % (stacktrace, str(err)))
augustus.core.xmlbase.XMLValidationError: Below is a traceback to the line that caused the actual exception.
File "/usr/local/lib/python2.7/dist-packages/augustus/core/xmlbase.py", line 1721, in endElement
last.validate(recurse=False, exception=True)
File "/usr/local/lib/python2.7/dist-packages/augustus/core/xmlbase.py", line 872, in validate
self.xsd.validate(self)
File "/usr/local/lib/python2.7/dist-packages/augustus/core/xmlbase.py", line 1579, in validate
xml.post_validate()
File "/usr/local/lib/python2.7/dist-packages/augustus/core/pmml41.py", line 1656, in post_validate
pmmlApply.top_validate_transformationDictionary(self.transformationDictionary)
File "/usr/local/lib/python2.7/dist-packages/augustus/core/pmml41.py", line 7092, in top_validate_transformationDictionary
raise PMMLValidationError("Apply function \"%s\" not recognized (not built-in and not user-defined)" % function)
XMLValidationError: Apply function "formatDateTime" not recognized (not built-in and not user-defined).
Ref:
Example I was trying: https://github.com/codersofthedark/augustus/tree/master/augustus-examples/gaslog/introductory
Augustus: https://code.google.com/p/augustus/
I got the same error. I'm not an expert at Augustus, but it looks the model file, "example_model.pmml" has the function, "formatDateTime", spelled wrong in two places. It should be "formatDatetime" (i.e., "time" should start with a lowercase "t"). When I made that correction, the example ran and produced output in the results directory.

Categories

Resources