Coder Social home page Coder Social logo

Comments (7)

YunYang1994 avatar YunYang1994 commented on May 11, 2024

absolutely yes !

from tensorflow2.0-examples.

jurenovic avatar jurenovic commented on May 11, 2024

@YunYang1994 would you be so kind to point me into the right direction. I created a simple python script to do the conversion, but its failing with a Fatal Python error.

import tensorflow as tf
from core.yolov3 import YOLOv3, decode

def representative_dataset_gen():
  for _ in range(num_calibration_steps):
    # Get sample input data as a numpy array in a method of your choosing.
    yield [input]

input_size   = 416

input_layer  = tf.keras.layers.Input([input_size, input_size, 3])
feature_maps = YOLOv3(input_layer)


bbox_tensors = []
for i, fm in enumerate(feature_maps):
    bbox_tensor = decode(fm, i)
    bbox_tensors.append(bbox_tensor)

model = tf.keras.Model(input_layer, bbox_tensors)
utils.load_weights(model, "./yolov3.weights")
model.summary()

# Create a converter
converter = tf.lite.TFLiteConverter.from_keras_model(model)
# Convert the model
# converter.optimizations = [tf.lite.Optimize.DEFAULT]
# converter.representative_dataset = representative_dataset_gen
# converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS_INT8]
# converter.inference_input_type = tf.uint8
# converter.inference_output_type = tf.uint8

tflite_model = converter.convert()
# Create the tflite model file
tflite_model_name = "yolov3.tflite"
open(tflite_model_name, "wb").write(tflite_model)

The exception is:

2019-12-04 22:44:51.903243: I tensorflow/core/grappler/devices.cc:60] Number of eligible GPUs (core count >= 8, compute capability >= 0.0): 0 (Note: TensorFlow was not compiled with CUDA support)
2019-12-04 22:44:51.903322: I tensorflow/core/grappler/clusters/single_machine.cc:356] Starting new session
2019-12-04 22:44:51.956138: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:716] Optimization results for grappler item: graph_to_optimize
2019-12-04 22:44:51.956163: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:718]   function_optimizer: function_optimizer did nothing. time = 0.007ms.
2019-12-04 22:44:51.956170: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:718]   function_optimizer: function_optimizer did nothing. time = 0ms.
2019-12-04 22:45:00.864649: I tensorflow/core/grappler/devices.cc:60] Number of eligible GPUs (core count >= 8, compute capability >= 0.0): 0 (Note: TensorFlow was not compiled with CUDA support)
2019-12-04 22:45:00.864756: I tensorflow/core/grappler/clusters/single_machine.cc:356] Starting new session
2019-12-04 22:45:06.669028: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:716] Optimization results for grappler item: graph_to_optimize
2019-12-04 22:45:06.669057: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:718]   constant folding: Graph size after: 884 nodes (-370), 2039 edges (-370), time = 3086.21191ms.
2019-12-04 22:45:06.669063: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:718]   constant folding: Graph size after: 884 nodes (0), 2039 edges (0), time = 1459.73096ms.
Traceback (most recent call last):
  File "convert.py", line 34, in <module>
    tflite_model = converter.convert()
  File "/workspace/sandbox/TensorFlow2.0-Examples/4-Object_Detection/YOLOV3/venv3/lib/python3.7/site-packages/tensorflow_core/lite/python/lite.py", line 446, in convert
    **converter_kwargs)
  File "/workspace/sandbox/TensorFlow2.0-Examples/4-Object_Detection/YOLOV3/venv3/lib/python3.7/site-packages/tensorflow_core/lite/python/convert.py", line 449, in toco_convert_impl
    enable_mlir_converter=enable_mlir_converter)
  File "/workspace/sandbox/TensorFlow2.0-Examples/4-Object_Detection/YOLOV3/venv3/lib/python3.7/site-packages/tensorflow_core/lite/python/convert.py", line 200, in toco_convert_protos
    raise ConverterError("See console for info.\n%s\n%s\n" % (stdout, stderr))
tensorflow.lite.python.convert.ConverterError: See console for info.
2019-12-04 22:45:13.865417: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] Before Removing unused ops: 652 operators, 1247 arrays (0 quantized)
2019-12-04 22:45:13.878738: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] Before general graph transformations: 652 operators, 1247 arrays (0 quantized)
2019-12-04 22:45:14.705331: F tensorflow/lite/toco/graph_transformations/resolve_strided_slice_attributes.cc:95] Check failed: start_indices_size <= num_input_axes (2 vs. 1)StridedSlice op requires no more than 1 start indices
Fatal Python error: Aborted

Current thread 0x000000010a9855c0 (most recent call first):
  File "/workspace/sandbox/TensorFlow2.0-Examples/4-Object_Detection/YOLOV3/venv3/lib/python3.7/site-packages/tensorflow_core/lite/toco/python/toco_from_protos.py", line 57 in execute
  File "/workspace/sandbox/TensorFlow2.0-Examples/4-Object_Detection/YOLOV3/venv3/lib/python3.7/site-packages/absl/app.py", line 250 in _run_main
  File "/workspace/sandbox/TensorFlow2.0-Examples/4-Object_Detection/YOLOV3/venv3/lib/python3.7/site-packages/absl/app.py", line 299 in run
  File "/workspace/sandbox/TensorFlow2.0-Examples/4-Object_Detection/YOLOV3/venv3/lib/python3.7/site-packages/tensorflow_core/python/platform/app.py", line 40 in run
  File "/workspace/sandbox/TensorFlow2.0-Examples/4-Object_Detection/YOLOV3/venv3/lib/python3.7/site-packages/tensorflow_core/lite/toco/python/toco_from_protos.py", line 94 in main
  File "/workspace/sandbox/TensorFlow2.0-Examples/4-Object_Detection/YOLOV3/venv3/bin/toco_from_protos", line 10 in <module>

I played around and with different options for the converter, but without much success.

# converter.optimizations = [tf.lite.Optimize.DEFAULT]
# converter.representative_dataset = representative_dataset_gen
# converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS_INT8]
# converter.inference_input_type = tf.uint8
# converter.inference_output_type = tf.uint8

And bear in mind that ML is completely new to me. 😄

Would appreciate some help, thanks

from tensorflow2.0-examples.

jurenovic avatar jurenovic commented on May 11, 2024

@YunYang1994 hey, sorry to bother you again, but would really appreciate some help

from tensorflow2.0-examples.

jurenovic avatar jurenovic commented on May 11, 2024

hello @YunYang1994, would really appreciate some help

from tensorflow2.0-examples.

jurenovic avatar jurenovic commented on May 11, 2024

@YunYang1994 any help?

from tensorflow2.0-examples.

Paranormaly avatar Paranormaly commented on May 11, 2024

up @YunYang1994

from tensorflow2.0-examples.

Namburger avatar Namburger commented on May 11, 2024

Try this: https://github.com/guichristmann/edge-tpu-tiny-yolo 👍

from tensorflow2.0-examples.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.