Giter Club home page Giter Club logo

tfjs-object-detection's Introduction

Real-time object detection in the browser using TensorFlow.js

This repository is part of the tutorial Custom real-time object detection in the browser using TensorFlow.js. For a better understanding of how to create a custom object detection model, refer to the post.

This project is a simple web-app that loads a model in the TensorFlow.js layers format using javascript and performs real-time inferences ingesting videos from a PC or mobile camera.

A Kangaroo detector was trained as a demo, but any object can be recognized following the tutorial steps and it will produce results similar to the shown below:

Object detection demo

A live demo is available on Glitch:
Qries

Getting started

The model saved at models/kangaroo-detector was trained using the kangaroo-dataset available on kaggle:

Qries

You can train your own model, upload it in the model folder and load as well.

Serving the model

To make the model available, it is necessary to define how the model is going to be loaded in the function load_model (lines 10–15 in the file src>index.js). There are two choices.

The first option is to create an HTTP server locally that will make the model available in a URL allowing requests and be treated as a REST API. When loading the model, TensorFlow.js will do the following requests:

GET /model.json
GET /group1-shard1of5.bin
GET /group1-shard2of5.bin
GET /group1-shard3of5.bin
GET /group1-shardo4f5.bin
GET /group1-shardo5f5.bin

If you choose this option, define the load_model function as follows:

async function load_model() {
	// It's possible to load the model locally or from a repo
	const model = await loadGraphModel("http://127.0.0.1:8080/model.json");
	//const model = await loadGraphModel("https://raw.githubusercontent.com/hugozanini/TFJS-object-detection/master/models/kangaroo-detector/model.json");
	return model;
}

Then install the http-server:

npm install http-server -g

Go to models > kangaroo-detector and run the command below to make the model available at http://127.0.0.1:8080 . This a good choice when you want to keep the model weights in a safe place and control who can request inferences to it.

http-server -c1 --cors .

The second option is to upload the model files somewhere, in my case, I chose my own Github repo and referenced to the model.json URL in the load_model function: homepage.png

async function load_model() {
	// It's possible to load the model locally or from a repo
	//const model = await loadGraphModel("http://127.0.0.1:8080/model.json");
	const model = await loadGraphModel("https://raw.githubusercontent.com/hugozanini/TFJS-object-detection/master/models/kangaroo-detector/model.json");
	return model;
}

This is a good option because it gives more flexibility to the application and makes it easier to run on some platform as Glitch.

Running locally

To run the app locally, install the required packages:

npm install

And start:

npm start

The application is going to run at [http://localhost:3000](http://localhost:3000) and you should see something similar to this:

App home page

The model takes from 1 to 2 seconds to load and, after that, you can show the objects images to the camera and the application is going to draw bounding boxes around them.

tfjs-object-detection's People

Contributors

hugozanini avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

tfjs-object-detection's Issues

Other class

Hello! I noticed in your repo, there's an 'Other' class (id: 2) that isn't present during training or tutorial. Can you explain where this was added in your process? Otherwise, I don't understand how the model will predict that class if it wasn't used during training.

[Solved] TensorList shape mismatch: Shapes -1 and 3 must match

After exporting the model and testing that it works properly, I've converted it to Tensorflowjs following your steps.
I've loaded it to the browser and I can't find the way to let it predict an image,

Here's the code:

const process_input = (image ) => {
const tfimg = tf.browser.fromPixels(video_frame).toInt();
const expandedimg = tfimg.transpose([0, 1, 2]).expandDims();
return expandedimg;
};
const image = document.getElementById('image');
const preImage = process_input (image);
tf.engine().startScope();
model.executeAsync(testImg).then(predictions => {
console.log(predictions);
tf.engine().endScope();
});

Right after that, I got an error saying:

Unhandled Rejection (Error): TensorList shape mismatch: Shapes -1 and 3 must match

[Solved] How to interpret the predictions

Hi, I'm very interested by this awesome project. I wish to customize it for my own project but I have some questions and issues.
I want to understand how to make prediction under TensorflowJs.
First your predictions object is an array of 8 tensors. This number of tensors depends to what?
Second, you made predictions by:

const boxes = predictions[4].arraySync();
const scores = predictions[5].arraySync();
const classes = predictions[6].dataSync();

So, why you choose 4 for boxes 5 for scores 6 for classes and not 0, 1, 2, 3, or 7.
I hope to share with me some resources to understand how to make predictions and how arraySync() or dataSynch work.

Glitch demo not working

Would love to test this out before diving into the tutorial, but the Glitch demo link seems to be broken.

Any chance you can get it up and running again?

[Solved] The model is not being loaded

After cloning the whole project and using your uploaded trained model the browser opens the webcam but it detects no kangaroos. I have tested several kangaroo images but none of them was detected. What is the problem

trouble on local master branch

@hugozanini , I tried to run the code, but I had problems with the order in my local, to fix it, it was necessary to change the order of the objects you call in src/index.js, I don't really know if it is a problem with the javascript version, but now it works with the model:
generatedBy: 2.4.0
convertedBy: Tensorflow v2.8.0

The new order is on line 118-120:

const boxes = predictions[0].arraySync();
const scores = predictions[4].arraySync();
const classes = predictions[5].dataSync();

javascript version: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36
node version: v16.17.0

can you review and comment please

Problem with training failure?

I get this message after training starts

2022-05-31 03:14:16.553617: W tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:42] Overriding orig_value setting because the TF_FORCE_GPU_ALLOW_GROWTH environment variable is set. Original config value was 0.
INFO:tensorflow:Using MirroredStrategy with devices ('/job:localhost/replica:0/task:0/device:GPU:0',)
I0531 03:14:16.559194 139653000472448 mirrored_strategy.py:374] Using MirroredStrategy with devices ('/job:localhost/replica:0/task:0/device:GPU:0',)
INFO:tensorflow:Maybe overwriting train_steps: 7500
I0531 03:14:16.563875 139653000472448 config_util.py:552] Maybe overwriting train_steps: 7500
INFO:tensorflow:Maybe overwriting use_bfloat16: False
I0531 03:14:16.564066 139653000472448 config_util.py:552] Maybe overwriting use_bfloat16: False
WARNING:tensorflow:From /usr/local/lib/python3.7/dist-packages/object_detection/model_lib_v2.py:564: StrategyBase.experimental_distribute_datasets_from_function (from tensorflow.python.distribute.distribute_lib) is deprecated and will be removed in a future version.
Instructions for updating:
rename to distribute_datasets_from_function
W0531 03:14:16.713543 139653000472448 deprecation.py:356] From /usr/local/lib/python3.7/dist-packages/object_detection/model_lib_v2.py:564: StrategyBase.experimental_distribute_datasets_from_function (from tensorflow.python.distribute.distribute_lib) is deprecated and will be removed in a future version.
Instructions for updating:
rename to distribute_datasets_from_function
INFO:tensorflow:Reading unweighted datasets: ['/content/dataset/train.record']
I0531 03:14:16.717333 139653000472448 dataset_builder.py:162] Reading unweighted datasets: ['/content/dataset/train.record']
INFO:tensorflow:Reading record datasets for input file: ['/content/dataset/train.record']
I0531 03:14:16.717543 139653000472448 dataset_builder.py:79] Reading record datasets for input file: ['/content/dataset/train.record']
INFO:tensorflow:Number of filenames to read: 1
I0531 03:14:16.717632 139653000472448 dataset_builder.py:80] Number of filenames to read: 1
WARNING:tensorflow:num_readers has been reduced to 1 to match input file shards.
W0531 03:14:16.717704 139653000472448 dataset_builder.py:87] num_readers has been reduced to 1 to match input file shards.
WARNING:tensorflow:From /usr/local/lib/python3.7/dist-packages/object_detection/builders/dataset_builder.py:104: parallel_interleave (from tensorflow.python.data.experimental.ops.interleave_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use `tf.data.Dataset.interleave(map_func, cycle_length, block_length, num_parallel_calls=tf.data.AUTOTUNE)` instead. If sloppy execution is desired, use `tf.data.Options.deterministic`.
W0531 03:14:16.719916 139653000472448 deprecation.py:356] From /usr/local/lib/python3.7/dist-packages/object_detection/builders/dataset_builder.py:104: parallel_interleave (from tensorflow.python.data.experimental.ops.interleave_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use `tf.data.Dataset.interleave(map_func, cycle_length, block_length, num_parallel_calls=tf.data.AUTOTUNE)` instead. If sloppy execution is desired, use `tf.data.Options.deterministic`.
WARNING:tensorflow:From /usr/local/lib/python3.7/dist-packages/object_detection/builders/dataset_builder.py:236: DatasetV1.map_with_legacy_function (from tensorflow.python.data.ops.dataset_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use `tf.data.Dataset.map()
W0531 03:14:16.739989 139653000472448 deprecation.py:356] From /usr/local/lib/python3.7/dist-packages/object_detection/builders/dataset_builder.py:236: DatasetV1.map_with_legacy_function (from tensorflow.python.data.ops.dataset_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use `tf.data.Dataset.map()
WARNING:tensorflow:From /usr/local/lib/python3.7/dist-packages/tensorflow/python/util/dispatch.py:1082: sparse_to_dense (from tensorflow.python.ops.sparse_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Create a `tf.sparse.SparseTensor` and use `tf.sparse.to_dense` instead.
W0531 03:14:23.329675 139653000472448 deprecation.py:356] From /usr/local/lib/python3.7/dist-packages/tensorflow/python/util/dispatch.py:1082: sparse_to_dense (from tensorflow.python.ops.sparse_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Create a `tf.sparse.SparseTensor` and use `tf.sparse.to_dense` instead.
WARNING:tensorflow:From /usr/local/lib/python3.7/dist-packages/tensorflow/python/util/dispatch.py:1082: sample_distorted_bounding_box (from tensorflow.python.ops.image_ops_impl) is deprecated and will be removed in a future version.
Instructions for updating:
`seed2` arg is deprecated.Use sample_distorted_bounding_box_v2 instead.
W0531 03:14:26.428313 139653000472448 deprecation.py:356] From /usr/local/lib/python3.7/dist-packages/tensorflow/python/util/dispatch.py:1082: sample_distorted_bounding_box (from tensorflow.python.ops.image_ops_impl) is deprecated and will be removed in a future version.
Instructions for updating:
`seed2` arg is deprecated.Use sample_distorted_bounding_box_v2 instead.
WARNING:tensorflow:From /usr/local/lib/python3.7/dist-packages/tensorflow/python/util/dispatch.py:1082: to_float (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use `tf.cast` instead.
W0531 03:14:29.292851 139653000472448 deprecation.py:356] From /usr/local/lib/python3.7/dist-packages/tensorflow/python/util/dispatch.py:1082: to_float (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use `tf.cast` instead.
2022-05-31 03:14:32.656018: W tensorflow/core/framework/cpu_allocator_impl.cc:82] Allocation of 23228928 exceeds 10% of free system memory.
2022-05-31 03:14:32.784304: W tensorflow/core/framework/cpu_allocator_impl.cc:82] Allocation of 28223235 exceeds 10% of free system memory.
2022-05-31 03:14:33.447533: W tensorflow/core/framework/cpu_allocator_impl.cc:82] Allocation of 28223235 exceeds 10% of free system memory.
2022-05-31 03:14:33.732630: W tensorflow/core/framework/cpu_allocator_impl.cc:82] Allocation of 16002000 exceeds 10% of free system memory.
2022-05-31 03:14:34.173680: W tensorflow/core/framework/cpu_allocator_impl.cc:82] Allocation of 36499968 exceeds 10% of free system memory.
/usr/local/lib/python3.7/dist-packages/keras/backend.py:450: UserWarning: `tf.keras.backend.set_learning_phase` is deprecated and will be removed after 2020-10-11. To update it, simply pass a True/False value to the `training` argument of the `__call__` method of your layer or model.
  warnings.warn('`tf.keras.backend.set_learning_phase` is deprecated and '
INFO:tensorflow:depth of additional conv before box predictor: 0
I0531 03:14:50.632984 139648196622080 convolutional_keras_box_predictor.py:153] depth of additional conv before box predictor: 0
INFO:tensorflow:depth of additional conv before box predictor: 0
I0531 03:14:50.633279 139648196622080 convolutional_keras_box_predictor.py:153] depth of additional conv before box predictor: 0
INFO:tensorflow:depth of additional conv before box predictor: 0
I0531 03:14:50.633432 139648196622080 convolutional_keras_box_predictor.py:153] depth of additional conv before box predictor: 0
INFO:tensorflow:depth of additional conv before box predictor: 0
I0531 03:14:50.633571 139648196622080 convolutional_keras_box_predictor.py:153] depth of additional conv before box predictor: 0
INFO:tensorflow:depth of additional conv before box predictor: 0
I0531 03:14:50.633706 139648196622080 convolutional_keras_box_predictor.py:153] depth of additional conv before box predictor: 0
INFO:tensorflow:depth of additional conv before box predictor: 0
I0531 03:14:50.633835 139648196622080 convolutional_keras_box_predictor.py:153] depth of additional conv before box predictor: 0
INFO:tensorflow:Reduce to /job:localhost/replica:0/task:0/device:CPU:0 then broadcast to ('/job:localhost/replica:0/task:0/device:CPU:0',).
I0531 03:15:51.371679 139653000472448 cross_device_ops.py:618] Reduce to /job:localhost/replica:0/task:0/device:CPU:0 then broadcast to ('/job:localhost/replica:0/task:0/device:CPU:0',).
INFO:tensorflow:Reduce to /job:localhost/replica:0/task:0/device:CPU:0 then broadcast to ('/job:localhost/replica:0/task:0/device:CPU:0',).
I0531 03:15:51.372889 139653000472448 cross_device_ops.py:618] Reduce to /job:localhost/replica:0/task:0/device:CPU:0 then broadcast to ('/job:localhost/replica:0/task:0/device:CPU:0',).
INFO:tensorflow:Reduce to /job:localhost/replica:0/task:0/device:CPU:0 then broadcast to ('/job:localhost/replica:0/task:0/device:CPU:0',).
I0531 03:15:51.374998 139653000472448 cross_device_ops.py:618] Reduce to /job:localhost/replica:0/task:0/device:CPU:0 then broadcast to ('/job:localhost/replica:0/task:0/device:CPU:0',).
INFO:tensorflow:Reduce to /job:localhost/replica:0/task:0/device:CPU:0 then broadcast to ('/job:localhost/replica:0/task:0/device:CPU:0',).
I0531 03:15:51.375892 139653000472448 cross_device_ops.py:618] Reduce to /job:localhost/replica:0/task:0/device:CPU:0 then broadcast to ('/job:localhost/replica:0/task:0/device:CPU:0',).
INFO:tensorflow:Reduce to /job:localhost/replica:0/task:0/device:CPU:0 then broadcast to ('/job:localhost/replica:0/task:0/device:CPU:0',).
I0531 03:15:51.377828 139653000472448 cross_device_ops.py:618] Reduce to /job:localhost/replica:0/task:0/device:CPU:0 then broadcast to ('/job:localhost/replica:0/task:0/device:CPU:0',).
INFO:tensorflow:Reduce to /job:localhost/replica:0/task:0/device:CPU:0 then broadcast to ('/job:localhost/replica:0/task:0/device:CPU:0',).
I0531 03:15:51.378676 139653000472448 cross_device_ops.py:618] Reduce to /job:localhost/replica:0/task:0/device:CPU:0 then broadcast to ('/job:localhost/replica:0/task:0/device:CPU:0',).
INFO:tensorflow:Reduce to /job:localhost/replica:0/task:0/device:CPU:0 then broadcast to ('/job:localhost/replica:0/task:0/device:CPU:0',).
I0531 03:15:51.380712 139653000472448 cross_device_ops.py:618] Reduce to /job:localhost/replica:0/task:0/device:CPU:0 then broadcast to ('/job:localhost/replica:0/task:0/device:CPU:0',).
INFO:tensorflow:Reduce to /job:localhost/replica:0/task:0/device:CPU:0 then broadcast to ('/job:localhost/replica:0/task:0/device:CPU:0',).
I0531 03:15:51.381557 139653000472448 cross_device_ops.py:618] Reduce to /job:localhost/replica:0/task:0/device:CPU:0 then broadcast to ('/job:localhost/replica:0/task:0/device:CPU:0',).
INFO:tensorflow:Reduce to /job:localhost/replica:0/task:0/device:CPU:0 then broadcast to ('/job:localhost/replica:0/task:0/device:CPU:0',).
I0531 03:15:51.383514 139653000472448 cross_device_ops.py:618] Reduce to /job:localhost/replica:0/task:0/device:CPU:0 then broadcast to ('/job:localhost/replica:0/task:0/device:CPU:0',).
INFO:tensorflow:Reduce to /job:localhost/replica:0/task:0/device:CPU:0 then broadcast to ('/job:localhost/replica:0/task:0/device:CPU:0',).
I0531 03:15:51.384363 139653000472448 cross_device_ops.py:618] Reduce to /job:localhost/replica:0/task:0/device:CPU:0 then broadcast to ('/job:localhost/replica:0/task:0/device:CPU:0',).
WARNING:tensorflow:From /usr/local/lib/python3.7/dist-packages/tensorflow/python/util/deprecation.py:629: calling map_fn_v2 (from tensorflow.python.ops.map_fn) with dtype is deprecated and will be removed in a future version.
Instructions for updating:
Use fn_output_signature instead
W0531 03:15:51.948419 139648121087744 deprecation.py:560] From /usr/local/lib/python3.7/dist-packages/tensorflow/python/util/deprecation.py:629: calling map_fn_v2 (from tensorflow.python.ops.map_fn) with dtype is deprecated and will be removed in a future version.
Instructions for updating:
Use fn_output_signature instead
^C

I had two problems before training the model

problem 1

cannot import name '_registerMatType' from 'cv2.cv2'

problem 2

Node: 'ssd_mobile_net_v2_fpn_keras_feature_extractor/model/Conv1/Conv2D'
DNN library is not found.
[[{{node ssd_mobile_net_v2_fpn_keras_feature_extractor/model/Conv1/Conv2D}}]] [Op:__inference__dummy_computation_fn_15081]

I use the following method to solve but I don't know if it is correct

!pip uninstall opencv-python-headless
!pip install opencv-python-headless==4.1.2.30

source: https://stackoverflow.com/questions/70537488/cannot-import-name-registermattype-from-cv2-cv2

!apt install --allow-change-held-packages libcudnn8=8.1.0.77-1+cuda11.2

source: googlecolab/colabtools#2600 (comment)

When the model is finally trained, you will see the above message

sorry english is not my native language

Not able to reproduce results: ops are not supported during converting to js files

Hi,
I followed your tutorial steps to reproduce trained, I was able to train the model for few steps and saved the model but while converting to tfjs files, it was showing some ops related log errors. I also tried to clone your repo on Glitch but there was not bboxes on kangaroo images through webcam, for this I used your provided models.

Can you please help me on this.
Thanks

here are the logs while converting to js files.

"Traceback (most recent call last):
  File "/home/avaretail/miniconda3/envs/myenv/lib/python3.6/site-packages/tensorflowjs/converters/wizard.py", line 562, in run
    converter.convert(arguments)
  File "/home/avaretail/miniconda3/envs/myenv/lib/python3.6/site-packages/tensorflowjs/converters/converter.py", line 618, in convert
    weight_shard_size_bytes=weight_shard_size_bytes)
  File "/home/avaretail/miniconda3/envs/myenv/lib/python3.6/site-packages/tensorflowjs/converters/tf_saved_model_conversion_v2.py", line 462, in convert_tf_saved_model
    weight_shard_size_bytes=weight_shard_size_bytes)
  File "/home/avaretail/miniconda3/envs/myenv/lib/python3.6/site-packages/tensorflowjs/converters/tf_saved_model_conversion_v2.py", line 142, in optimize_graph
    ', '.join(unsupported))
ValueError: Unsupported Ops in the model before optimization
TensorListStack, TensorListSetItem, TensorListReserve, TensorListFromTensor, TensorListGetItem
Traceback (most recent call last):
  File "/home/avaretail/miniconda3/envs/myenv/lib/python3.6/site-packages/tensorflowjs/converters/wizard.py", line 562, in run
    converter.convert(arguments)
  File "/home/avaretail/miniconda3/envs/myenv/lib/python3.6/site-packages/tensorflowjs/converters/converter.py", line 618, in convert
    weight_shard_size_bytes=weight_shard_size_bytes)
  File "/home/avaretail/miniconda3/envs/myenv/lib/python3.6/site-packages/tensorflowjs/converters/tf_saved_model_conversion_v2.py", line 462, in convert_tf_saved_model
    weight_shard_size_bytes=weight_shard_size_bytes)
  File "/home/avaretail/miniconda3/envs/myenv/lib/python3.6/site-packages/tensorflowjs/converters/tf_saved_model_conversion_v2.py", line 142, in optimize_graph
    ', '.join(unsupported))
ValueError: Unsupported Ops in the model before optimization
TensorListFromTensor, TensorListStack, TensorListReserve, TensorListGetItem, TensorListSetItem
Traceback (most recent call last):
  File "/home/avaretail/miniconda3/envs/myenv/lib/python3.6/site-packages/tensorflowjs/converters/wizard.py", line 562, in run
    converter.convert(arguments)
  File "/home/avaretail/miniconda3/envs/myenv/lib/python3.6/site-packages/tensorflowjs/converters/converter.py", line 618, in convert
    weight_shard_size_bytes=weight_shard_size_bytes)
  File "/home/avaretail/miniconda3/envs/myenv/lib/python3.6/site-packages/tensorflowjs/converters/tf_saved_model_conversion_v2.py", line 462, in convert_tf_saved_model
    weight_shard_size_bytes=weight_shard_size_bytes)
  File "/home/avaretail/miniconda3/envs/myenv/lib/python3.6/site-packages/tensorflowjs/converters/tf_saved_model_conversion_v2.py", line 142, in optimize_graph
    ', '.join(unsupported))
ValueError: Unsupported Ops in the model before optimization
TensorListStack, TensorListSetItem, TensorListReserve, TensorListGetItem, TensorListFromTensor
Traceback (most recent call last):
  File "/home/avaretail/miniconda3/envs/myenv/lib/python3.6/site-packages/tensorflowjs/converters/wizard.py", line 562, in run
    converter.convert(arguments)
  File "/home/avaretail/miniconda3/envs/myenv/lib/python3.6/site-packages/tensorflowjs/converters/converter.py", line 618, in convert
    weight_shard_size_bytes=weight_shard_size_bytes)
  File "/home/avaretail/miniconda3/envs/myenv/lib/python3.6/site-packages/tensorflowjs/converters/tf_saved_model_conversion_v2.py", line 462, in convert_tf_saved_model
    weight_shard_size_bytes=weight_shard_size_bytes)
  File "/home/avaretail/miniconda3/envs/myenv/lib/python3.6/site-packages/tensorflowjs/converters/tf_saved_model_conversion_v2.py", line 142, in optimize_graph
    ', '.join(unsupported))
ValueError: Unsupported Ops in the model before optimization
TensorListFromTensor, TensorListSetItem, TensorListStack, TensorListReserve, TensorListGetItem"

Cannot read property 'children' of undefined with using Tensorflow Object Detection API model in tfjs

System information

  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow.js): Yes
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Windows 10
  • Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device: N/A
  • TensorFlow.js installed from (npm or script link): npm install @tensorflow/tfjs
  • TensorFlow.js version (use command below): 3.6.0
  • Browser version: Chrome 90 on Windows 10
  • Tensorflow.js Converter Version: 3.6.0

Hyperlinks are capitalized to prevent confusion(because the color settings(and blue filter) on my monitor make it hard to see the difference between them)

Describe the current behavior
I used transfer learning using a pretrained model from the Tensorflow Object Detection API, which i converted to tensorflow-js using the tensorflow-converter API in python. View the ipynb notebook HERE. I then followed @hugozanini's REPO which had a template for using your tensorflow object detection models in javascript; I copied the index.json file and put it into a sandbox, replacing his model.json file with mine. The repo which contains it can be found here

Describe the expected behavior
I was expecting the model to work and the program to run normally, like it did in this DEMO. Instead, I got

index.js:1437 TypeError: Cannot read property 'children' of undefined
    at operation_mapper.js:409
    at Array.forEach (<anonymous>)
    at operation_mapper.js:403
    at Array.forEach (<anonymous>)
    at OperationMapper.mapFunction (operation_mapper.js:401)
    at operation_mapper.js:163
    at Array.reduce (<anonymous>)
    at OperationMapper.transformGraph (operation_mapper.js:162)
    at GraphModel.loadSync (graph_model.js:159)
    at GraphModel._callee$ (graph_model.js:119)
    at tryCatch (runtime.js:62)
    at Generator.invoke [as _invoke] (runtime.js:288)
    at Generator.prototype.<computed> [as next] (runtime.js:114)
    at asyncGeneratorStep (asyncToGenerator.js:3)
    at _next (asyncToGenerator.js:25)

Standalone code to reproduce the issue
Provide a reproducible test case that is the bare minimum necessary to generate
the problem. If possible, please share a link to Colab/CodePen/any notebook.

HERE is the colab notebook I used to train my model
HERE is the sandbox where I tried to use the tensorflow.js model

Other info / logs Include any logs or source code that would be helpful to
diagnose the problem. If including tracebacks, please include the full
traceback. Large logs and files should be attached.

Error Message:

index.js:1437 TypeError: Cannot read property 'children' of undefined
    at operation_mapper.js:409
    at Array.forEach (<anonymous>)
    at operation_mapper.js:403
    at Array.forEach (<anonymous>)
    at OperationMapper.mapFunction (operation_mapper.js:401)
    at operation_mapper.js:163
    at Array.reduce (<anonymous>)
    at OperationMapper.transformGraph (operation_mapper.js:162)
    at GraphModel.loadSync (graph_model.js:159)
    at GraphModel._callee$ (graph_model.js:119)
    at tryCatch (runtime.js:62)
    at Generator.invoke [as _invoke] (runtime.js:288)
    at Generator.prototype.<computed> [as next] (runtime.js:114)
    at asyncGeneratorStep (asyncToGenerator.js:3)
    at _next (asyncToGenerator.js:25)

[Solved] Unknown op 'TensorListFromTensor'

Unhandled Rejection (TypeError): Unknown op 'TensorListFromTensor'. File an issue at https://github.com/tensorflow/tfjs/issues so we can add it, or register a custom execution with tf.registerOp()
▼ 22 stack frames were expanded.
(anonymous function)
node_modules/@tensorflow/tfjs-converter/dist/tf-converter.esm.js:5048
executeOp$16
node_modules/@tensorflow/tfjs-converter/dist/tf-converter.esm.js:5050
l
node_modules/@tensorflow/tfjs-converter/dist/tf-converter.esm.js:5420
e.processStack
node_modules/@tensorflow/tfjs-converter/dist/tf-converter.esm.js:5428
e.<anonymous>
node_modules/@tensorflow/tfjs-converter/dist/tf-converter.esm.js:5398
(anonymous function)
node_modules/@tensorflow/tfjs-converter/dist/tf-converter.esm.js:137
next
node_modules/@tensorflow/tfjs-converter/dist/tf-converter.esm.js:150
(anonymous function)
node_modules/@tensorflow/tfjs-converter/dist/tf-converter.esm.js:57
__awaiter
node_modules/@tensorflow/tfjs-converter/dist/tf-converter.esm.js:34
e.executeWithControlFlow
node_modules/@tensorflow/tfjs-converter/dist/tf-converter.esm.js:5360
e.<anonymous>
node_modules/@tensorflow/tfjs-converter/dist/tf-converter.esm.js:5342
(anonymous function)
node_modules/@tensorflow/tfjs-converter/dist/tf-converter.esm.js:137
next
node_modules/@tensorflow/tfjs-converter/dist/tf-converter.esm.js:150
(anonymous function)
node_modules/@tensorflow/tfjs-converter/dist/tf-converter.esm.js:57
__awaiter
node_modules/@tensorflow/tfjs-converter/dist/tf-converter.esm.js:34
e.executeAsync
node_modules/@tensorflow/tfjs-converter/dist/tf-converter.esm.js:5331
e.<anonymous>
node_modules/@tensorflow/tfjs-converter/dist/tf-converter.esm.js:5601
(anonymous function)
node_modules/@tensorflow/tfjs-converter/dist/tf-converter.esm.js:137
next
node_modules/@tensorflow/tfjs-converter/dist/tf-converter.esm.js:150
(anonymous function)
node_modules/@tensorflow/tfjs-converter/dist/tf-converter.esm.js:57
__awaiter
node_modules/@tensorflow/tfjs-converter/dist/tf-converter.esm.js:34
e.executeAsync
node_modules/@tensorflow/tfjs-converter/dist/tf-converter.esm.js:5596
▲ 22 stack frames were expanded.
App._this.detectFrame
src/index.js:67
  64 | 
  65 | detectFrame = (video, model) => {
  66 |     tf.engine().startScope();
> 67 |     model.executeAsync(this.process_input(video)).then(predictions => {
     | ^  68 |     this.renderPredictions(predictions, video);
  69 |     requestAnimationFrame(() => {
  70 |       this.detectFrame(video, model);
View compiled
(anonymous function)
src/index.js:57
  54 | 
  55 | Promise.all([modelPromise, webCamPromise])
  56 |   .then(values => {
> 57 |     this.detectFrame(this.videoRef.current, values[0]);
     | ^  58 |   })
  59 |   .catch(error => {
  60 |     console.error(error);
View compiled

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.