Tensorflow object detection API:Sample program not working as expected - tensorflow

I am running sample program which comes packaged with Tensorflow object detection API(object_detection_tutorial.ipynb).
Program runs fine with no error, but bounding boxes are not diaplayed at all.
My environment is as follows:
Windows 10
Python 3.6.3
What can be the reason?
With regards
Manish

It seems that the latest version of the model ssd_mobilenet_v1_coco_2017_11_08 doesn't work and outputs abnormally low value. Replacing it in the Jupyter Notebook with an older version of the model works fine for me:
# What model to download.
MODEL_NAME = 'ssd_mobilenet_v1_coco_11_06_2017'
Ref: https://github.com/tensorflow/models/issues/2773

Please try updated SSD models in the detection zoo : https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/detection_model_zoo.md. This should be fixed.

Related

TensorFlow Lite Error: "(RESHAPE) failed to prepare" when running converted RepNet model in TFLite in Flutter

I'm trying to run a converted RepNet model in TFLite on mobile (iOS and Android) using Flutter, and the tf_lite_flutter package.
I have successfully converted the model to TFLite by adapting the colab provided by the authors. The notebook I used can be found in this repository, along with the converted model.
To make sure everything was working before attempting to run on an edge device, I checked everything with the Python TFLite API (this notebook). Everything indeed worked well - the output for the TFLite model matches the output of the Google colab provided by the authors.
I created a Flutter project to get the model running on mobile. I've tried passing in the default input and output, resulting from calls to interpreter.getInputTensors() and interpreter.getOutputTensors() respectively. When using this project to try to run the model, I encounter the following error:
E/tflite (26540): tensorflow/lite/kernels/reshape.cc:69 num_input_elements != num_output_elements (1 != 0)
E/tflite (26540): Node number 1 (RESHAPE) failed to prepare.
I'm admittedly pretty new to Tensorflow and Tensorflow Lite, so my debugging ability is somewhat limited. It does seem strange to me that the expected output shape is 0. Considering it is working with the Python API, I'm not sure why it isn't working on-device. The only thing I might suspect it could be is the batch_size not being configured properly. Using the shape_signature field, as in interpreter.get_input_details()[0]['shape_signature'], I can see that the batch size is dynamic (value -1).
The model was converted using Tensorflow==2.5 in Python, and is being run using the standard TFLite 2.5 binaries (no GPUDelegate).
Any suggestions for fixing this error would be appreciated!

Runtime Error: Found no NVIDIA driver on your system

I am facing issue while loading the model using torch which was trained using GPU, I am trying to load that model using CPU. however I am successfully able to load the model but while predicting the results I am getting error. However if I use GPU machine I am able to predict the output but not on the CPU:
My code:
****To save the model I am using :****
PATH = "model.pt"
torch.save(model, PATH)
**To Load the Model**
import torch
PATH = "model.pt"
device = torch.device('cpu')
loaded_model=torch.load(PATH, map_location=device)
I am able to successfully load the model. but while predicting I am getting runtime error
**Predicting the loaded model using CPU**
predicted_title = loaded_model.predict([abstract])
Runtime Error: Found no NVIDIA driver on your system. Please check that you have an NVIDIA GPU and installed a driver
I am sorry if the error might turn out very simple but I am not able to rectify this.
You can output the models device with
print(loaded_model.device)
if it is not cpu, do
model = model.to('cpu')

Loading saved model trained in an earlier tensorflow version

I recently use Google AutoML service to create a model.
Its output seems to be in a saved model format. However,when I attempt to load it via tf.saved_model.load ,it display following error
Op type not registered 'TreeEnsembleSerialize' in binary ...
When I look up this op,I find that this op exists in tf.contrib.boosted_trees in Tensorflow 1.15,but since Tensorflow 2 removes tf.contrib,this op has be renamed to BoostedTreesSerializeEnsemble in tf.raw_ops.
My question is:Is there any way to duplicate the op and rename it to TreeEnsembleSerialize ,so the saved model could be loaded without errors.
Thanks.
There are no significant compatibility concerns for saved models.
TensorFlow 1.x saved_models work in TensorFlow 2.x.
TensorFlow 2.x
saved_models work in TensorFlow 1.x if all the ops are supported.
For more information visit Tensorflow doc

Project with object detection on raspberry pi (tensorflow)

I am doing a research project that consists in an object detection AI, capable of detecting by a webcam 7 classes of objects.
Using google colab, I successfully trained the ssd_mobilenet_v2_quantized_300x300_coco model, using tensorflow 1.15.
The objective is to run the model in a Raspberry Pi 3b+, using the official camera and Google Coral EdgeTPU device, so the model must be quantized in order to use it.
The issue comes with the testing part; so after training the model, converted it to tflite using:
!python export_tflite_ssd_graph.py --pipeline_config_path="/content/drive/My Drive/Colab Data/models/research/object_detection/training/ssd_mobilenet_v2_quantized_300x300_coco.config" --trained_checkpoint_prefix=training/model.ckpt-28523 --output_directory=compiler/ --add_postprocessing_op=true
and
!tflite_convert --graph_def_file=compiler/tflite_graph.pb --output_file=compiler/detect.tflite --output_format=TFLITE --input_shapes=1,300,300,3 --input_arrays=normalized_input_image_tensor --output_arrays='TFLite_Detection_PostProcess','TFLite_Detection_PostProcess:1','TFLite_Detection_PostProcess:2','TFLite_Detection_PostProcess:3' --inference_type=QUANTIZED_UINT8 --mean_values=128 --std_dev_values=128 --change_concat_input_ranges=false --allow_custom_ops
Converted model: https://gofile.io/d/kOe2Ac
Tried to test the model using Edje Electronics webcam script. found here
And outputs this error:
RuntimeError: tensorflow/lite/kernels/detection_postprocess.cc:404 ValidateBoxes(decoded_boxes, num_boxes) was not true.Node number 98 (TFLite_Detection_PostProcess) failed to invoke.
The weirdest thing is that if I try to run the same script in my current workstation (with tensorflow 1.15.1), the code runs flawlessly, so there should be something wrong with the rpi.
The rpi is running tensorflow 1.15.2, built from the WHL source. Actually y tried with all the versions that I can, but always the same error.
I will be so grateful with any help that could bring to me. Thanks in advance.
Ok, thanks for the info! But how is that it works flawlessly on other pc and not on the rpi? Do i need to install tf-nightly instead of tensorflow? This might be of the cpu architecture?
ValidateBoxes verifies if the the xmin, xmax, ymin, ymax of the detected box makes sense or not. And the issue is usually caused by detected boxes with the same xmin/xmax or ymin/ymax, which should not be flagged as an issue, and the rest of the code and tolerant with the case very well. The issue has been fixed in TFLite and it is now available through the tf-nightly build.
If you'd like to build TF from source, here is a workaround solution.

TensorBoard 2.0.0 not updating train scalars

I am running the following in a docker container:
tensorflow-gpu 2.0.0
tensorboard 2.0.0
jupyterlab 1.1.4
Unfortunately, during the training Tensorboard is only updating the validation scalars graph (accuracy and loss), but not those of the training data. The directories for train and validation are both selected to be displayed within the graph.
I found out, that when I stop Tensorboard and restart it, the train scalars currently available until this time step get displayed. Unfortunately, these do not get updated, although the validation scalars do get updated with each epocch.
Does someone know the solution to this problem?
It's probably related to https://github.com/tensorflow/tensorboard/issues/2412.
Adding profile_batch=0 to the callback should solve the problem.
I had the exact same issue and solved it by starting my tensorboard with :
--reload_multifile True