-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: V3 tensorflow plugin #1633
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@mrousavy cool that helped get through that part. Seems to run the model now. Brings up a fun new issue. The camera goes down to like .5 fps running the model. We are using an unofficial tflite blazepose model which might be the cause. Running an official posenet model gives us just raw data when logged but performance is much improved.
Pose detection is a pain. When I was using the tfjs packages, it was a few steps to running the detection and estimating the poses so I wonder if that is why this is the case here. Did you by chance happen to try any pose detection when building the plugin? Quick update: Found an official mediapipe pose detection model. Does the really slow camera feed as well. |
hi @eledahl you have a solution for detecting pose net ? |
@philip-bui-goldenowl No sir. The pose models I am using are slowing the cameras down or not outputting the keypoints as I intended. I may be using it wrong but that's the point I am at currently. |
@eledahl I have the same problem, I convert the frame to CGImage but the context CGBitmapContextCreateImage: invalid context 0x0. Backtrace, not get keypoints |
Hey @eledahl, can you share your .tflite model? if the model itself is slow there's nothing I can do about that. I can check if the input parsing and output conversions are throttling. Also, if you want to run something async, VisionCamera V3 introduced a new func: |
@mrousavy Sure yeah here's the few that we were trying to use. Github doesn't like the file type so let me know if you have any issues downloading them from the drive: Oh, that's fancy about the |
@mrousavy Thank you for working on this; V3 is definitively going to be game-changing. @eledahl, your pose model is not working for me, but this model is working. I'm getting between 55 and 60 fps! I tried to run it using Here is a snippet of my code running the model and plotting the nose landmark on the frame if anyone wants to use it const model = require('./assets/lite-model_movenet_singlepose_lightning_tflite_float16_4.tflite')
const plugin = useTensorflowModel(model);
if (plugin.state === 'loaded') console.log(JSON.stringify(plugin.model, null, 2));
const paint = Skia.Paint();
paint.setStyle(PaintStyle.Stroke);
paint.setStrokeWidth(20);
paint.setColor(Skia.Color('green'));
const inputShape = plugin.model?.inputs[0]?.shape;
const inputFrameSize = {
width: inputShape?.[1] ?? 0,
height: inputShape?.[2] ?? 0,
};
const frameProcessor = useFrameProcessor(
(frame) => {
'worklet';
const addition = (frame.height - frame.width)/2
const scaler = frame.width
if (plugin.state === 'loaded') {
const output = plugin.model.run(frame)
// console.log(output[0][1]*scaler, output[0][0]*scaler + addition)
frame.drawCircle(output[0][1]*scaler, output[0][0]*scaler + addition, 5,paint)
} else {
console.log(`Model state: ${plugin.state}..`);
}
},
[inputFrameSize.height, paint, plugin.model, plugin.state],
); @mrousavy two questions:
|
@dguari1 Ah thanks man. Your code seems to have fixed it for my model. It looks like my model does run if I only do the smaller console.log you did rather than logging the entire output. Do you happen to know how to extract the keypoints from the pose models this way? @mrousavy Let me know if these questions get too specific for my use case. I am happy to ask them elsewhere if that is better |
@dguari1 nice to hear you got it running at 60 FPS, this is amazing!!!!
|
@mrousavy Another issue is the data type. The TFLite Movenet works fine, this model requires unit8 input inputs": [
{
"name": "serving_default_input:0",
"dataType": "uint8",
"shape": [
1,
192,
192,
3
]
}
], However, the Mediapipe Pose (all their models are here), does not work, as this model needs float32 input and the frame data type is uint8 "inputs": [
{
"name": "input_1",
"dataType": "float32",
"shape": [
1,
256,
256,
3
]
}
], Right now, the output of the MediaPipe pose model is just random numbers. It doesn't process the image. I made a short Python script to test these models, figure out what they do, and plot the results! It is outside this forum's scope, so I won't post it here. @eledahl login the data in the terminal takes a lot of time; the MediaPipe Pose model returns a lot of data (it even returns the input image and the heatmaps) "outputs": [
{
"name": "Identity",
"dataType": "float32",
"shape": [
1,
195
]
},
{
"name": "Identity_1",
"dataType": "float32",
"shape": [
1,
1
]
},
{
"name": "Identity_2",
"dataType": "float32",
"shape": [
1,
256,
256,
1
]
},
{
"name": "Identity_3",
"dataType": "float32",
"shape": [
1,
64,
64,
39
]
},
{
"name": "Identity_4",
"dataType": "float32",
"shape": [
1,
117
]
}
], the pose should be the first component of that output. There should be 39 landmarks; you can get with something like this for (let i = 0; i < output[0].length; i+=5) {
const cx = output[0][i] * scaler
const cy = output[0][i+1] * scaler + addition
console.log(`landmark_x = ${cx}, landmark_y = ${cy}`)
} but the model doesn't work at the moment due to the data type required. |
If you can convert the model to uint8_t input that'd be better for performance as well. Converting to float32_t is a bit difficult and not sure how to even test that. |
I'm not sure if its reasonable to assume most models would have a uint8 input. How difficult would it be to convert to float32_t on the native side? We can help test with blazepose and other mediapipe models. @dguari1 |
The issue with input data type and normalization is really annoying. Some models need uint8, others float32, also some models need the data to be normalized, and others don't. @mrousavy I have been looking for ways to adjust the input data type, but I don't think that is possible without re-training the model, and these models cannot be re-trained as Google doesn't share the data. @pvedula7 the tflite models can be analyzed in Python using something like this: # Import TF and TF Hub libraries.
import tensorflow as tf
import matplotlib.pyplot as plt
from PIL import Image, ImageOps
image_path = "PathToYourImage"
im = Image.open(image_path)
im = ImageOps.exif_transpose(im)
# Load the input image.
image = tf.convert_to_tensor(im)
# image = tf.compat.v1.image.decode_jpeg(image)
image = tf.expand_dims(image, axis=0)
interpreter = tf.lite.Interpreter(model_path="PathToYourModel.tflite")
interpreter.allocate_tensors()
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()
# Resize and pad the image to keep the aspect ratio and fit the expected size.
ExpectedSize = input_details[0]['shape'][2]
imageResized = tf.image.resize_with_pad(image, ExpectedSize, ExpectedSize , antialias=True)
# Adjuste the data type
ExpectedType = input_details[0]['dtype']
input_image = tf.cast(imageResized, dtype=ExpectedType)
interpreter.set_tensor(input_details[0]['index'], input_image.numpy())
interpreter.invoke()
modelOutput = interpreter.get_tensor(output_details[0]['index'])
|
I am trying to use a text detection model, but I am getting 1 fps unfortunately. This is the model I am trying to use: https://tfhub.dev/sayakpaul/lite-model/east-text-detector/fp16/1 which is directly from the tensorflow example (https://www.tensorflow.org/lite/examples/optical_character_recognition/overview). I've also tried using both float32 and int8 versions of the model but still get 1 fps. Is there something about text models that makes them break when used in the frame processor? |
@timothygorer, your model's input type is float32; it would not work properly with the current implementation of the plugin.
Also, your model is huge, so it is probably pretty slow. |
Hello ! I comment here, since it looks the best place to do so, I'm actually trying to run models with an output set to float32. Is there any way to handle this? Models with input/output higher than float16 are common and include mediapipe models, for example. The rest looks really stable, smooth and reliable. Awesome ! Thank you ! |
Hey - all the models I worked on are uint8 or int8 - I tried to add some basic float32 conversion but I didn't really test it since that's quite tricky to do. Didn't want to spend more time on it since all the models I had were uint8/int8 :) |
Thank you for your answer and your work! |
See #1376 ## Breaking Changes * Frame Processors are now **synchronous**. Previously they ran on a separate Thread. If you want to run something on a separate Thread now, use `runAsync` inside a Frame Processor * Frame Processor Plugins are no longer in the global object with the `__` prefix, but rather stored directly in the `FrameProcessorPlugins` object exported by react-native-vision-camera. (e.g. replace `__scanQRCodes(frame)` with `FrameProcessorPlugins.scanQRCodes(frame)`) * `frameProcessorFps` no longer exists. Use `runAtTargetFps` inside a Frame Processor to throttle some calls. * `onFrameProcessorPerformanceSuggestionAvailable` no longer exists. Use the FPS display (`enableFpsGraph={true}`) to see how your Frame Processor performs over time. This is more in-line with how React Native works (Dev Tools / Perf Monitor) * VisionCamera V3 will not work on RN 0.70 or below. You need to use RN 0.71. This is because the build script got way simpler and smaller, making it faster to build and way less error prone. Backwards compatibility is just too complex here. * Reanimated is no longer used as a Worklet Runtime. Instead, VisionCamera now uses [react-native-worklets-core](https://github.com/margelo/react-native-worklets-core). ## Progress You can test the latest V3 release by creating a new RN project with RN 0.71 and installing VisionCamera + RNWorklets: ```sh yarn add react-native-vision-camera@3.0.0-rc.5 yarn add react-native-worklets-core yarn add @shopify/react-native-skia ``` Things to test: * TensorFlow Lite plugin to load any `.tflite` model!! ✨ (see [this PR for more info](#1633), will be a separate library soon) * Drawing onto a Frame using Skia!! 🎉 * Using `frame.toArrayBuffer()` to get the Frame's byte content in JS * New Android build script. This should drastically speed up the build time! 💨 * New Worklet library. This replaces Reanimated Worklets. Should be faster and more stable :) * New synchronous Frame Processors. Should be faster :) * `runAtTargetFps` and `runAsync` in Frame Processors * Using HostObjects or HostFunctions (like models from PyTorch) inside a Frame Processor. This will probably require a few native bindings on PyTorch's end to make the integration work (cc @raedle) Overall V3 is close to completion. I have a few things to do the coming days so not sure how much work I can put into this. **If anyone wants to support the development of v3, I'd appreciate donations / sponsors: https://github.com/sponsors/mrousavy** ❤️ :) ## Related issues features - resolves #1376 - fixes #281 - resolves #211 - resolves #130 - resolves #117 - fixes #76 - resolves #75 - resolves #562 - resolves #565 - fixes #570 - fixes #287 - resolves #311 - fixes #315 - resolves #323 - fixes #340 - fixes #354 - resolves #420 - fixes #434 - fixes #452 - fixes #496 - fixes #497 - resolves #499 - fixes #516 - fixes #527 - fixes #542 - fixes #548 - fixes #561 - fixes #740 - fixes #770 ...and then pretty much every Android issue lol - fixes #1675 (**maybe**, please test @PrernaBudhraja) - fixes #1671 .. maybe also (not tested): - fixes #1698 - fixes #1687 - fixes #1685 - fixes #1681 - fixes #1650 - fixes #1646 - fixes #1635 - fixes #1631 - fixes #1621 - fixes #1615 - fixes #1612 - fixes #1605 - fixes #1599 - fixes #1585 - fixes #1581 - fixes #1569 - fixes #1568 - fixes #1565 - fixes #1561 - fixes #1558 - fixes #1554 - fixes #1551 - fixes #1547 - fixes #1543 - fixes #1538 - fixes #1536 - fixes #1534 - fixes #1528 - fixes #1520 - fixes #1498 - fixes #1489 - fixes #1477 - fixes #1474 - fixes #1463 - fixes #1462 - fixes #1449 - fixes #1443 - fixes #1437 - fixes #1431 - fixes #1429 - fixes #1427 - fixes #1423 - fixes #1416 - fixes #1407 - fixes #1403 - fixes #1402 - fixes #1398 - fixes #1396 - fixes #1395 - fixes #1379 - fixes #1377 - fixes #1374 - fixes #1373 - fixes #1365 - fixes #1356 - fixes #1353 - fixes #1352 - fixes #1351 - fixes #1343 - fixes #1340 - fixes #1334 - fixes #1330 - fixes #1322 - fixes #1296 - fixes #1283 - fixes #1260 - fixes #1253 - fixes #1251 - fixes #1245 - fixes #1238 - fixes #1227 - fixes #1226 - fixes #1225 - fixes #1222 - fixes #1211 - fixes #1208 - fixes #1193 - fixes #1191 - fixes #1184 - fixes #1164 - fixes #1143 - fixes #1128 - fixes #1122 - fixes #1120 - fixes #1110 - fixes #1097 - fixes #1081 - fixes #1080 - fixes #1064 - fixes #1053 - fixes #1047 - fixes #1044 - fixes #1032 - fixes #1026 - fixes #1023 - fixes #1015 - fixes #1012 - fixes #997 - fixes #960 - fixes #959 - fixes #954 - fixes #946 - fixes #945 - fixes #922 - fixes #908 - fixes #907 - fixes #868 - fixes #855 - fixes #834 - fixes #793 - fixes #779 - fixes #746 - fixes #740 - fixes #727 - fixes #671 - fixes #613 - fixes #595 - fixes #588 - fixes #570 - fixes #569 - fixes #542 - fixes #516 - fixes #515 - fixes #434 - fixes #354 - fixes #323 - fixes #315 - fixes #281 - fixes #211 - fixes #76
See mrousavy/react-native-vision-camera#1376 ## Breaking Changes * Frame Processors are now **synchronous**. Previously they ran on a separate Thread. If you want to run something on a separate Thread now, use `runAsync` inside a Frame Processor * Frame Processor Plugins are no longer in the global object with the `__` prefix, but rather stored directly in the `FrameProcessorPlugins` object exported by react-native-vision-camera. (e.g. replace `__scanQRCodes(frame)` with `FrameProcessorPlugins.scanQRCodes(frame)`) * `frameProcessorFps` no longer exists. Use `runAtTargetFps` inside a Frame Processor to throttle some calls. * `onFrameProcessorPerformanceSuggestionAvailable` no longer exists. Use the FPS display (`enableFpsGraph={true}`) to see how your Frame Processor performs over time. This is more in-line with how React Native works (Dev Tools / Perf Monitor) * VisionCamera V3 will not work on RN 0.70 or below. You need to use RN 0.71. This is because the build script got way simpler and smaller, making it faster to build and way less error prone. Backwards compatibility is just too complex here. * Reanimated is no longer used as a Worklet Runtime. Instead, VisionCamera now uses [react-native-worklets-core](https://github.com/margelo/react-native-worklets-core). ## Progress You can test the latest V3 release by creating a new RN project with RN 0.71 and installing VisionCamera + RNWorklets: ```sh yarn add react-native-vision-camera@3.0.0-rc.5 yarn add react-native-worklets-core yarn add @shopify/react-native-skia ``` Things to test: * TensorFlow Lite plugin to load any `.tflite` model!! ✨ (see [this PR for more info](mrousavy/react-native-vision-camera#1633), will be a separate library soon) * Drawing onto a Frame using Skia!! 🎉 * Using `frame.toArrayBuffer()` to get the Frame's byte content in JS * New Android build script. This should drastically speed up the build time! 💨 * New Worklet library. This replaces Reanimated Worklets. Should be faster and more stable :) * New synchronous Frame Processors. Should be faster :) * `runAtTargetFps` and `runAsync` in Frame Processors * Using HostObjects or HostFunctions (like models from PyTorch) inside a Frame Processor. This will probably require a few native bindings on PyTorch's end to make the integration work (cc @raedle) Overall V3 is close to completion. I have a few things to do the coming days so not sure how much work I can put into this. **If anyone wants to support the development of v3, I'd appreciate donations / sponsors: https://github.com/sponsors/mrousavy** ❤️ :) ## Related issues features - resolves mrousavy/react-native-vision-camera#1376 - fixes mrousavy/react-native-vision-camera#281 - resolves mrousavy/react-native-vision-camera#211 - resolves mrousavy/react-native-vision-camera#130 - resolves mrousavy/react-native-vision-camera#117 - fixes mrousavy/react-native-vision-camera#76 - resolves mrousavy/react-native-vision-camera#75 - resolves mrousavy/react-native-vision-camera#562 - resolves mrousavy/react-native-vision-camera#565 - fixes mrousavy/react-native-vision-camera#570 - fixes mrousavy/react-native-vision-camera#287 - resolves mrousavy/react-native-vision-camera#311 - fixes mrousavy/react-native-vision-camera#315 - resolves mrousavy/react-native-vision-camera#323 - fixes mrousavy/react-native-vision-camera#340 - fixes mrousavy/react-native-vision-camera#354 - resolves mrousavy/react-native-vision-camera#420 - fixes mrousavy/react-native-vision-camera#434 - fixes mrousavy/react-native-vision-camera#452 - fixes mrousavy/react-native-vision-camera#496 - fixes mrousavy/react-native-vision-camera#497 - resolves mrousavy/react-native-vision-camera#499 - fixes mrousavy/react-native-vision-camera#516 - fixes mrousavy/react-native-vision-camera#527 - fixes mrousavy/react-native-vision-camera#542 - fixes mrousavy/react-native-vision-camera#548 - fixes mrousavy/react-native-vision-camera#561 - fixes mrousavy/react-native-vision-camera#740 - fixes mrousavy/react-native-vision-camera#770 ...and then pretty much every Android issue lol - fixes mrousavy/react-native-vision-camera#1675 (**maybe**, please test @PrernaBudhraja) - fixes mrousavy/react-native-vision-camera#1671 .. maybe also (not tested): - fixes mrousavy/react-native-vision-camera#1698 - fixes mrousavy/react-native-vision-camera#1687 - fixes mrousavy/react-native-vision-camera#1685 - fixes mrousavy/react-native-vision-camera#1681 - fixes mrousavy/react-native-vision-camera#1650 - fixes mrousavy/react-native-vision-camera#1646 - fixes mrousavy/react-native-vision-camera#1635 - fixes mrousavy/react-native-vision-camera#1631 - fixes mrousavy/react-native-vision-camera#1621 - fixes mrousavy/react-native-vision-camera#1615 - fixes mrousavy/react-native-vision-camera#1612 - fixes mrousavy/react-native-vision-camera#1605 - fixes mrousavy/react-native-vision-camera#1599 - fixes mrousavy/react-native-vision-camera#1585 - fixes mrousavy/react-native-vision-camera#1581 - fixes mrousavy/react-native-vision-camera#1569 - fixes mrousavy/react-native-vision-camera#1568 - fixes mrousavy/react-native-vision-camera#1565 - fixes mrousavy/react-native-vision-camera#1561 - fixes mrousavy/react-native-vision-camera#1558 - fixes mrousavy/react-native-vision-camera#1554 - fixes mrousavy/react-native-vision-camera#1551 - fixes mrousavy/react-native-vision-camera#1547 - fixes mrousavy/react-native-vision-camera#1543 - fixes mrousavy/react-native-vision-camera#1538 - fixes mrousavy/react-native-vision-camera#1536 - fixes mrousavy/react-native-vision-camera#1534 - fixes mrousavy/react-native-vision-camera#1528 - fixes mrousavy/react-native-vision-camera#1520 - fixes mrousavy/react-native-vision-camera#1498 - fixes mrousavy/react-native-vision-camera#1489 - fixes mrousavy/react-native-vision-camera#1477 - fixes mrousavy/react-native-vision-camera#1474 - fixes mrousavy/react-native-vision-camera#1463 - fixes mrousavy/react-native-vision-camera#1462 - fixes mrousavy/react-native-vision-camera#1449 - fixes mrousavy/react-native-vision-camera#1443 - fixes mrousavy/react-native-vision-camera#1437 - fixes mrousavy/react-native-vision-camera#1431 - fixes mrousavy/react-native-vision-camera#1429 - fixes mrousavy/react-native-vision-camera#1427 - fixes mrousavy/react-native-vision-camera#1423 - fixes mrousavy/react-native-vision-camera#1416 - fixes mrousavy/react-native-vision-camera#1407 - fixes mrousavy/react-native-vision-camera#1403 - fixes mrousavy/react-native-vision-camera#1402 - fixes mrousavy/react-native-vision-camera#1398 - fixes mrousavy/react-native-vision-camera#1396 - fixes mrousavy/react-native-vision-camera#1395 - fixes mrousavy/react-native-vision-camera#1379 - fixes mrousavy/react-native-vision-camera#1377 - fixes mrousavy/react-native-vision-camera#1374 - fixes mrousavy/react-native-vision-camera#1373 - fixes mrousavy/react-native-vision-camera#1365 - fixes mrousavy/react-native-vision-camera#1356 - fixes mrousavy/react-native-vision-camera#1353 - fixes mrousavy/react-native-vision-camera#1352 - fixes mrousavy/react-native-vision-camera#1351 - fixes mrousavy/react-native-vision-camera#1343 - fixes mrousavy/react-native-vision-camera#1340 - fixes mrousavy/react-native-vision-camera#1334 - fixes mrousavy/react-native-vision-camera#1330 - fixes mrousavy/react-native-vision-camera#1322 - fixes mrousavy/react-native-vision-camera#1296 - fixes mrousavy/react-native-vision-camera#1283 - fixes mrousavy/react-native-vision-camera#1260 - fixes mrousavy/react-native-vision-camera#1253 - fixes mrousavy/react-native-vision-camera#1251 - fixes mrousavy/react-native-vision-camera#1245 - fixes mrousavy/react-native-vision-camera#1238 - fixes mrousavy/react-native-vision-camera#1227 - fixes mrousavy/react-native-vision-camera#1226 - fixes mrousavy/react-native-vision-camera#1225 - fixes mrousavy/react-native-vision-camera#1222 - fixes mrousavy/react-native-vision-camera#1211 - fixes mrousavy/react-native-vision-camera#1208 - fixes mrousavy/react-native-vision-camera#1193 - fixes mrousavy/react-native-vision-camera#1191 - fixes mrousavy/react-native-vision-camera#1184 - fixes mrousavy/react-native-vision-camera#1164 - fixes mrousavy/react-native-vision-camera#1143 - fixes mrousavy/react-native-vision-camera#1128 - fixes mrousavy/react-native-vision-camera#1122 - fixes mrousavy/react-native-vision-camera#1120 - fixes mrousavy/react-native-vision-camera#1110 - fixes mrousavy/react-native-vision-camera#1097 - fixes mrousavy/react-native-vision-camera#1081 - fixes mrousavy/react-native-vision-camera#1080 - fixes mrousavy/react-native-vision-camera#1064 - fixes mrousavy/react-native-vision-camera#1053 - fixes mrousavy/react-native-vision-camera#1047 - fixes mrousavy/react-native-vision-camera#1044 - fixes mrousavy/react-native-vision-camera#1032 - fixes mrousavy/react-native-vision-camera#1026 - fixes mrousavy/react-native-vision-camera#1023 - fixes mrousavy/react-native-vision-camera#1015 - fixes mrousavy/react-native-vision-camera#1012 - fixes mrousavy/react-native-vision-camera#997 - fixes mrousavy/react-native-vision-camera#960 - fixes mrousavy/react-native-vision-camera#959 - fixes mrousavy/react-native-vision-camera#954 - fixes mrousavy/react-native-vision-camera#946 - fixes mrousavy/react-native-vision-camera#945 - fixes mrousavy/react-native-vision-camera#922 - fixes mrousavy/react-native-vision-camera#908 - fixes mrousavy/react-native-vision-camera#907 - fixes mrousavy/react-native-vision-camera#868 - fixes mrousavy/react-native-vision-camera#855 - fixes mrousavy/react-native-vision-camera#834 - fixes mrousavy/react-native-vision-camera#793 - fixes mrousavy/react-native-vision-camera#779 - fixes mrousavy/react-native-vision-camera#746 - fixes mrousavy/react-native-vision-camera#740 - fixes mrousavy/react-native-vision-camera#727 - fixes mrousavy/react-native-vision-camera#671 - fixes mrousavy/react-native-vision-camera#613 - fixes mrousavy/react-native-vision-camera#595 - fixes mrousavy/react-native-vision-camera#588 - fixes mrousavy/react-native-vision-camera#570 - fixes mrousavy/react-native-vision-camera#569 - fixes mrousavy/react-native-vision-camera#542 - fixes mrousavy/react-native-vision-camera#516 - fixes mrousavy/react-native-vision-camera#515 - fixes mrousavy/react-native-vision-camera#434 - fixes mrousavy/react-native-vision-camera#354 - fixes mrousavy/react-native-vision-camera#323 - fixes mrousavy/react-native-vision-camera#315 - fixes mrousavy/react-native-vision-camera#281 - fixes mrousavy/react-native-vision-camera#211 - fixes mrousavy/react-native-vision-camera#76
See mrousavy/react-native-vision-camera#1376 ## Breaking Changes * Frame Processors are now **synchronous**. Previously they ran on a separate Thread. If you want to run something on a separate Thread now, use `runAsync` inside a Frame Processor * Frame Processor Plugins are no longer in the global object with the `__` prefix, but rather stored directly in the `FrameProcessorPlugins` object exported by react-native-vision-camera. (e.g. replace `__scanQRCodes(frame)` with `FrameProcessorPlugins.scanQRCodes(frame)`) * `frameProcessorFps` no longer exists. Use `runAtTargetFps` inside a Frame Processor to throttle some calls. * `onFrameProcessorPerformanceSuggestionAvailable` no longer exists. Use the FPS display (`enableFpsGraph={true}`) to see how your Frame Processor performs over time. This is more in-line with how React Native works (Dev Tools / Perf Monitor) * VisionCamera V3 will not work on RN 0.70 or below. You need to use RN 0.71. This is because the build script got way simpler and smaller, making it faster to build and way less error prone. Backwards compatibility is just too complex here. * Reanimated is no longer used as a Worklet Runtime. Instead, VisionCamera now uses [react-native-worklets-core](https://github.com/margelo/react-native-worklets-core). ## Progress You can test the latest V3 release by creating a new RN project with RN 0.71 and installing VisionCamera + RNWorklets: ```sh yarn add react-native-vision-camera@3.0.0-rc.5 yarn add react-native-worklets-core yarn add @shopify/react-native-skia ``` Things to test: * TensorFlow Lite plugin to load any `.tflite` model!! ✨ (see [this PR for more info](mrousavy/react-native-vision-camera#1633), will be a separate library soon) * Drawing onto a Frame using Skia!! 🎉 * Using `frame.toArrayBuffer()` to get the Frame's byte content in JS * New Android build script. This should drastically speed up the build time! 💨 * New Worklet library. This replaces Reanimated Worklets. Should be faster and more stable :) * New synchronous Frame Processors. Should be faster :) * `runAtTargetFps` and `runAsync` in Frame Processors * Using HostObjects or HostFunctions (like models from PyTorch) inside a Frame Processor. This will probably require a few native bindings on PyTorch's end to make the integration work (cc @raedle) Overall V3 is close to completion. I have a few things to do the coming days so not sure how much work I can put into this. **If anyone wants to support the development of v3, I'd appreciate donations / sponsors: https://github.com/sponsors/mrousavy** ❤️ :) ## Related issues features - resolves mrousavy/react-native-vision-camera#1376 - fixes mrousavy/react-native-vision-camera#281 - resolves mrousavy/react-native-vision-camera#211 - resolves mrousavy/react-native-vision-camera#130 - resolves mrousavy/react-native-vision-camera#117 - fixes mrousavy/react-native-vision-camera#76 - resolves mrousavy/react-native-vision-camera#75 - resolves mrousavy/react-native-vision-camera#562 - resolves mrousavy/react-native-vision-camera#565 - fixes mrousavy/react-native-vision-camera#570 - fixes mrousavy/react-native-vision-camera#287 - resolves mrousavy/react-native-vision-camera#311 - fixes mrousavy/react-native-vision-camera#315 - resolves mrousavy/react-native-vision-camera#323 - fixes mrousavy/react-native-vision-camera#340 - fixes mrousavy/react-native-vision-camera#354 - resolves mrousavy/react-native-vision-camera#420 - fixes mrousavy/react-native-vision-camera#434 - fixes mrousavy/react-native-vision-camera#452 - fixes mrousavy/react-native-vision-camera#496 - fixes mrousavy/react-native-vision-camera#497 - resolves mrousavy/react-native-vision-camera#499 - fixes mrousavy/react-native-vision-camera#516 - fixes mrousavy/react-native-vision-camera#527 - fixes mrousavy/react-native-vision-camera#542 - fixes mrousavy/react-native-vision-camera#548 - fixes mrousavy/react-native-vision-camera#561 - fixes mrousavy/react-native-vision-camera#740 - fixes mrousavy/react-native-vision-camera#770 ...and then pretty much every Android issue lol - fixes mrousavy/react-native-vision-camera#1675 (**maybe**, please test @PrernaBudhraja) - fixes mrousavy/react-native-vision-camera#1671 .. maybe also (not tested): - fixes mrousavy/react-native-vision-camera#1698 - fixes mrousavy/react-native-vision-camera#1687 - fixes mrousavy/react-native-vision-camera#1685 - fixes mrousavy/react-native-vision-camera#1681 - fixes mrousavy/react-native-vision-camera#1650 - fixes mrousavy/react-native-vision-camera#1646 - fixes mrousavy/react-native-vision-camera#1635 - fixes mrousavy/react-native-vision-camera#1631 - fixes mrousavy/react-native-vision-camera#1621 - fixes mrousavy/react-native-vision-camera#1615 - fixes mrousavy/react-native-vision-camera#1612 - fixes mrousavy/react-native-vision-camera#1605 - fixes mrousavy/react-native-vision-camera#1599 - fixes mrousavy/react-native-vision-camera#1585 - fixes mrousavy/react-native-vision-camera#1581 - fixes mrousavy/react-native-vision-camera#1569 - fixes mrousavy/react-native-vision-camera#1568 - fixes mrousavy/react-native-vision-camera#1565 - fixes mrousavy/react-native-vision-camera#1561 - fixes mrousavy/react-native-vision-camera#1558 - fixes mrousavy/react-native-vision-camera#1554 - fixes mrousavy/react-native-vision-camera#1551 - fixes mrousavy/react-native-vision-camera#1547 - fixes mrousavy/react-native-vision-camera#1543 - fixes mrousavy/react-native-vision-camera#1538 - fixes mrousavy/react-native-vision-camera#1536 - fixes mrousavy/react-native-vision-camera#1534 - fixes mrousavy/react-native-vision-camera#1528 - fixes mrousavy/react-native-vision-camera#1520 - fixes mrousavy/react-native-vision-camera#1498 - fixes mrousavy/react-native-vision-camera#1489 - fixes mrousavy/react-native-vision-camera#1477 - fixes mrousavy/react-native-vision-camera#1474 - fixes mrousavy/react-native-vision-camera#1463 - fixes mrousavy/react-native-vision-camera#1462 - fixes mrousavy/react-native-vision-camera#1449 - fixes mrousavy/react-native-vision-camera#1443 - fixes mrousavy/react-native-vision-camera#1437 - fixes mrousavy/react-native-vision-camera#1431 - fixes mrousavy/react-native-vision-camera#1429 - fixes mrousavy/react-native-vision-camera#1427 - fixes mrousavy/react-native-vision-camera#1423 - fixes mrousavy/react-native-vision-camera#1416 - fixes mrousavy/react-native-vision-camera#1407 - fixes mrousavy/react-native-vision-camera#1403 - fixes mrousavy/react-native-vision-camera#1402 - fixes mrousavy/react-native-vision-camera#1398 - fixes mrousavy/react-native-vision-camera#1396 - fixes mrousavy/react-native-vision-camera#1395 - fixes mrousavy/react-native-vision-camera#1379 - fixes mrousavy/react-native-vision-camera#1377 - fixes mrousavy/react-native-vision-camera#1374 - fixes mrousavy/react-native-vision-camera#1373 - fixes mrousavy/react-native-vision-camera#1365 - fixes mrousavy/react-native-vision-camera#1356 - fixes mrousavy/react-native-vision-camera#1353 - fixes mrousavy/react-native-vision-camera#1352 - fixes mrousavy/react-native-vision-camera#1351 - fixes mrousavy/react-native-vision-camera#1343 - fixes mrousavy/react-native-vision-camera#1340 - fixes mrousavy/react-native-vision-camera#1334 - fixes mrousavy/react-native-vision-camera#1330 - fixes mrousavy/react-native-vision-camera#1322 - fixes mrousavy/react-native-vision-camera#1296 - fixes mrousavy/react-native-vision-camera#1283 - fixes mrousavy/react-native-vision-camera#1260 - fixes mrousavy/react-native-vision-camera#1253 - fixes mrousavy/react-native-vision-camera#1251 - fixes mrousavy/react-native-vision-camera#1245 - fixes mrousavy/react-native-vision-camera#1238 - fixes mrousavy/react-native-vision-camera#1227 - fixes mrousavy/react-native-vision-camera#1226 - fixes mrousavy/react-native-vision-camera#1225 - fixes mrousavy/react-native-vision-camera#1222 - fixes mrousavy/react-native-vision-camera#1211 - fixes mrousavy/react-native-vision-camera#1208 - fixes mrousavy/react-native-vision-camera#1193 - fixes mrousavy/react-native-vision-camera#1191 - fixes mrousavy/react-native-vision-camera#1184 - fixes mrousavy/react-native-vision-camera#1164 - fixes mrousavy/react-native-vision-camera#1143 - fixes mrousavy/react-native-vision-camera#1128 - fixes mrousavy/react-native-vision-camera#1122 - fixes mrousavy/react-native-vision-camera#1120 - fixes mrousavy/react-native-vision-camera#1110 - fixes mrousavy/react-native-vision-camera#1097 - fixes mrousavy/react-native-vision-camera#1081 - fixes mrousavy/react-native-vision-camera#1080 - fixes mrousavy/react-native-vision-camera#1064 - fixes mrousavy/react-native-vision-camera#1053 - fixes mrousavy/react-native-vision-camera#1047 - fixes mrousavy/react-native-vision-camera#1044 - fixes mrousavy/react-native-vision-camera#1032 - fixes mrousavy/react-native-vision-camera#1026 - fixes mrousavy/react-native-vision-camera#1023 - fixes mrousavy/react-native-vision-camera#1015 - fixes mrousavy/react-native-vision-camera#1012 - fixes mrousavy/react-native-vision-camera#997 - fixes mrousavy/react-native-vision-camera#960 - fixes mrousavy/react-native-vision-camera#959 - fixes mrousavy/react-native-vision-camera#954 - fixes mrousavy/react-native-vision-camera#946 - fixes mrousavy/react-native-vision-camera#945 - fixes mrousavy/react-native-vision-camera#922 - fixes mrousavy/react-native-vision-camera#908 - fixes mrousavy/react-native-vision-camera#907 - fixes mrousavy/react-native-vision-camera#868 - fixes mrousavy/react-native-vision-camera#855 - fixes mrousavy/react-native-vision-camera#834 - fixes mrousavy/react-native-vision-camera#793 - fixes mrousavy/react-native-vision-camera#779 - fixes mrousavy/react-native-vision-camera#746 - fixes mrousavy/react-native-vision-camera#740 - fixes mrousavy/react-native-vision-camera#727 - fixes mrousavy/react-native-vision-camera#671 - fixes mrousavy/react-native-vision-camera#613 - fixes mrousavy/react-native-vision-camera#595 - fixes mrousavy/react-native-vision-camera#588 - fixes mrousavy/react-native-vision-camera#570 - fixes mrousavy/react-native-vision-camera#569 - fixes mrousavy/react-native-vision-camera#542 - fixes mrousavy/react-native-vision-camera#516 - fixes mrousavy/react-native-vision-camera#515 - fixes mrousavy/react-native-vision-camera#434 - fixes mrousavy/react-native-vision-camera#354 - fixes mrousavy/react-native-vision-camera#323 - fixes mrousavy/react-native-vision-camera#315 - fixes mrousavy/react-native-vision-camera#281 - fixes mrousavy/react-native-vision-camera#211 - fixes mrousavy/react-native-vision-camera#76
See mrousavy#1376 ## Breaking Changes * Frame Processors are now **synchronous**. Previously they ran on a separate Thread. If you want to run something on a separate Thread now, use `runAsync` inside a Frame Processor * Frame Processor Plugins are no longer in the global object with the `__` prefix, but rather stored directly in the `FrameProcessorPlugins` object exported by react-native-vision-camera. (e.g. replace `__scanQRCodes(frame)` with `FrameProcessorPlugins.scanQRCodes(frame)`) * `frameProcessorFps` no longer exists. Use `runAtTargetFps` inside a Frame Processor to throttle some calls. * `onFrameProcessorPerformanceSuggestionAvailable` no longer exists. Use the FPS display (`enableFpsGraph={true}`) to see how your Frame Processor performs over time. This is more in-line with how React Native works (Dev Tools / Perf Monitor) * VisionCamera V3 will not work on RN 0.70 or below. You need to use RN 0.71. This is because the build script got way simpler and smaller, making it faster to build and way less error prone. Backwards compatibility is just too complex here. * Reanimated is no longer used as a Worklet Runtime. Instead, VisionCamera now uses [react-native-worklets-core](https://github.com/margelo/react-native-worklets-core). ## Progress You can test the latest V3 release by creating a new RN project with RN 0.71 and installing VisionCamera + RNWorklets: ```sh yarn add react-native-vision-camera@3.0.0-rc.5 yarn add react-native-worklets-core yarn add @shopify/react-native-skia ``` Things to test: * TensorFlow Lite plugin to load any `.tflite` model!! ✨ (see [this PR for more info](mrousavy#1633), will be a separate library soon) * Drawing onto a Frame using Skia!! 🎉 * Using `frame.toArrayBuffer()` to get the Frame's byte content in JS * New Android build script. This should drastically speed up the build time! 💨 * New Worklet library. This replaces Reanimated Worklets. Should be faster and more stable :) * New synchronous Frame Processors. Should be faster :) * `runAtTargetFps` and `runAsync` in Frame Processors * Using HostObjects or HostFunctions (like models from PyTorch) inside a Frame Processor. This will probably require a few native bindings on PyTorch's end to make the integration work (cc @raedle) Overall V3 is close to completion. I have a few things to do the coming days so not sure how much work I can put into this. **If anyone wants to support the development of v3, I'd appreciate donations / sponsors: https://github.com/sponsors/mrousavy** ❤️ :) ## Related issues features - resolves mrousavy#1376 - fixes mrousavy#281 - resolves mrousavy#211 - resolves mrousavy#130 - resolves mrousavy#117 - fixes mrousavy#76 - resolves mrousavy#75 - resolves mrousavy#562 - resolves mrousavy#565 - fixes mrousavy#570 - fixes mrousavy#287 - resolves mrousavy#311 - fixes mrousavy#315 - resolves mrousavy#323 - fixes mrousavy#340 - fixes mrousavy#354 - resolves mrousavy#420 - fixes mrousavy#434 - fixes mrousavy#452 - fixes mrousavy#496 - fixes mrousavy#497 - resolves mrousavy#499 - fixes mrousavy#516 - fixes mrousavy#527 - fixes mrousavy#542 - fixes mrousavy#548 - fixes mrousavy#561 - fixes mrousavy#740 - fixes mrousavy#770 ...and then pretty much every Android issue lol - fixes mrousavy#1675 (**maybe**, please test @PrernaBudhraja) - fixes mrousavy#1671 .. maybe also (not tested): - fixes mrousavy#1698 - fixes mrousavy#1687 - fixes mrousavy#1685 - fixes mrousavy#1681 - fixes mrousavy#1650 - fixes mrousavy#1646 - fixes mrousavy#1635 - fixes mrousavy#1631 - fixes mrousavy#1621 - fixes mrousavy#1615 - fixes mrousavy#1612 - fixes mrousavy#1605 - fixes mrousavy#1599 - fixes mrousavy#1585 - fixes mrousavy#1581 - fixes mrousavy#1569 - fixes mrousavy#1568 - fixes mrousavy#1565 - fixes mrousavy#1561 - fixes mrousavy#1558 - fixes mrousavy#1554 - fixes mrousavy#1551 - fixes mrousavy#1547 - fixes mrousavy#1543 - fixes mrousavy#1538 - fixes mrousavy#1536 - fixes mrousavy#1534 - fixes mrousavy#1528 - fixes mrousavy#1520 - fixes mrousavy#1498 - fixes mrousavy#1489 - fixes mrousavy#1477 - fixes mrousavy#1474 - fixes mrousavy#1463 - fixes mrousavy#1462 - fixes mrousavy#1449 - fixes mrousavy#1443 - fixes mrousavy#1437 - fixes mrousavy#1431 - fixes mrousavy#1429 - fixes mrousavy#1427 - fixes mrousavy#1423 - fixes mrousavy#1416 - fixes mrousavy#1407 - fixes mrousavy#1403 - fixes mrousavy#1402 - fixes mrousavy#1398 - fixes mrousavy#1396 - fixes mrousavy#1395 - fixes mrousavy#1379 - fixes mrousavy#1377 - fixes mrousavy#1374 - fixes mrousavy#1373 - fixes mrousavy#1365 - fixes mrousavy#1356 - fixes mrousavy#1353 - fixes mrousavy#1352 - fixes mrousavy#1351 - fixes mrousavy#1343 - fixes mrousavy#1340 - fixes mrousavy#1334 - fixes mrousavy#1330 - fixes mrousavy#1322 - fixes mrousavy#1296 - fixes mrousavy#1283 - fixes mrousavy#1260 - fixes mrousavy#1253 - fixes mrousavy#1251 - fixes mrousavy#1245 - fixes mrousavy#1238 - fixes mrousavy#1227 - fixes mrousavy#1226 - fixes mrousavy#1225 - fixes mrousavy#1222 - fixes mrousavy#1211 - fixes mrousavy#1208 - fixes mrousavy#1193 - fixes mrousavy#1191 - fixes mrousavy#1184 - fixes mrousavy#1164 - fixes mrousavy#1143 - fixes mrousavy#1128 - fixes mrousavy#1122 - fixes mrousavy#1120 - fixes mrousavy#1110 - fixes mrousavy#1097 - fixes mrousavy#1081 - fixes mrousavy#1080 - fixes mrousavy#1064 - fixes mrousavy#1053 - fixes mrousavy#1047 - fixes mrousavy#1044 - fixes mrousavy#1032 - fixes mrousavy#1026 - fixes mrousavy#1023 - fixes mrousavy#1015 - fixes mrousavy#1012 - fixes mrousavy#997 - fixes mrousavy#960 - fixes mrousavy#959 - fixes mrousavy#954 - fixes mrousavy#946 - fixes mrousavy#945 - fixes mrousavy#922 - fixes mrousavy#908 - fixes mrousavy#907 - fixes mrousavy#868 - fixes mrousavy#855 - fixes mrousavy#834 - fixes mrousavy#793 - fixes mrousavy#779 - fixes mrousavy#746 - fixes mrousavy#740 - fixes mrousavy#727 - fixes mrousavy#671 - fixes mrousavy#613 - fixes mrousavy#595 - fixes mrousavy#588 - fixes mrousavy#570 - fixes mrousavy#569 - fixes mrousavy#542 - fixes mrousavy#516 - fixes mrousavy#515 - fixes mrousavy#434 - fixes mrousavy#354 - fixes mrousavy#323 - fixes mrousavy#315 - fixes mrousavy#281 - fixes mrousavy#211 - fixes mrousavy#76
What
TensorFlow Lite Plugin to drop any
.tflite
model in the JS bundle (src/assets
) and just run it in VisionCamera. No native code at all.This is gonna be a game changer to the mobile camera industry
The model can be a face detector, object detector, golf swing detector, whatever
.tflite
model you train. Possibilities are endless.Example
RPReplay_Final1688135872.mov
Changes
Tested on
Related issues