Skip to content

Commit

Permalink
Merge branch 'cdiddy77:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
michellrodriguez08 authored May 23, 2024
2 parents d8807a6 + 2da104f commit 428d7e5
Show file tree
Hide file tree
Showing 11 changed files with 114 additions and 11 deletions.
3 changes: 2 additions & 1 deletion examples/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
vendor/
Pods/
Pods/
*.tflite
10 changes: 9 additions & 1 deletion examples/objectdetection/android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
apply plugin: "com.android.application"
apply plugin: "org.jetbrains.kotlin.android"
apply plugin: "com.facebook.react"
apply plugin: 'de.undercouch.download'

/**
* This is the configuration block to customize your React Native Android app.
Expand Down Expand Up @@ -76,7 +77,7 @@ android {

namespace "com.objectdetection"
defaultConfig {

applicationId "com.objectdetection"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
Expand Down Expand Up @@ -105,6 +106,13 @@ android {
}
}

// import DownloadModels task
project.ext.ASSET_DIR = projectDir.toString() + '/src/main/assets'

// Download default models; if you wish to use your own models then
// place them in the "assets" directory and comment out this line.
apply from:'download_models.gradle'

dependencies {
// The version of react-native is set by the React Native Gradle Plugin
implementation("com.facebook.react:react-android")
Expand Down
19 changes: 19 additions & 0 deletions examples/objectdetection/android/app/download_models.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
task downloadModelFile0(type: Download) {
src 'https://storage.googleapis.com/mediapipe-models/object_detector/efficientdet_lite0/float32/1/efficientdet_lite0.tflite'
dest project.ext.ASSET_DIR + '/efficientdet-lite0.tflite'
overwrite false
}

task downloadModelFile1(type: Download) {
src 'https://storage.googleapis.com/mediapipe-models/object_detector/efficientdet_lite2/float32/1/efficientdet_lite2.tflite'
dest project.ext.ASSET_DIR + '/efficientdet-lite2.tflite'
overwrite false
}

task downloadModelFile2(type: Download) {
src 'https://storage.googleapis.com/mediapipe-models/object_detector/ssd_mobilenet_v2/float32/1/ssd_mobilenet_v2.tflite'
dest project.ext.ASSET_DIR + '/ssd-mobilenet-v2.tflite'
overwrite false
}

preBuild.dependsOn downloadModelFile0, downloadModelFile1, downloadModelFile2
Binary file not shown.
1 change: 1 addition & 0 deletions examples/objectdetection/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ buildscript {
classpath("com.android.tools.build:gradle")
classpath("com.facebook.react:react-native-gradle-plugin")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin")
classpath("de.undercouch:gradle-download-task:4.1.2")
}
}

Expand Down
29 changes: 29 additions & 0 deletions examples/objectdetection/ios/RunScripts/download_models.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
echo "INFO: Downloading models for iOS."

# Download efficientnet-lite0.tflite from the internet if doesn't exist.
TFLITE_FILE=./objectdetection/efficientdet-lite0.tflite
if test -f "$TFLITE_FILE"; then
echo "INFO: efficientdet_lite0.tflite exists. Skip downloading and use the local model."
else
curl -o ${TFLITE_FILE} https://storage.googleapis.com/mediapipe-models/object_detector/efficientdet_lite0/float32/1/efficientdet_lite0.tflite
echo "INFO: Downloaded efficientdet_lite0.tflite to $TFLITE_FILE ."
fi

# Download efficientnet-lite2.tflite from the internet if doesn't exist.
TFLITE_FILE=./objectdetection/efficientdet-lite2.tflite
if test -f "$TFLITE_FILE"; then
echo "INFO: efficientdet_lite0.tflite exists. Skip downloading and use the local model."
else
curl -o ${TFLITE_FILE} https://storage.googleapis.com/mediapipe-models/object_detector/efficientdet_lite2/float32/1/efficientdet_lite2.tflite
echo "INFO: Downloaded efficientdet_lite0.tflite to $TFLITE_FILE ."
fi

# Download ssd_mobilenet-v2.tflite from the internet if doesn't exist.
TFLITE_FILE=./objectdetection/ssd-mobilenet-v2.tflite
if test -f "$TFLITE_FILE"; then
echo "INFO: ssd_mobilenet_v2.tflite exists. Skip downloading and use the local model."
else
curl -o ${TFLITE_FILE} https://storage.googleapis.com/mediapipe-models/object_detector/ssd_mobilenet_v2.tflite/float32/1/ssd_mobilenet_v2.tflite
echo "INFO: Downloaded ssd_mobilenet_v2.tflite to $TFLITE_FILE ."
fi

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; };
13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; };
37EB22B02BBC9BAB002A84F7 /* efficientdet-lite0.tflite in Resources */ = {isa = PBXBuildFile; fileRef = 37EB22AF2BBC9BAB002A84F7 /* efficientdet-lite0.tflite */; };
6326052D2BED2678009CC628 /* efficientdet-lite2.tflite in Resources */ = {isa = PBXBuildFile; fileRef = 6326052C2BED2678009CC628 /* efficientdet-lite2.tflite */; };
6326052F2BED2684009CC628 /* ssd-mobilenet-v2.tflite in Resources */ = {isa = PBXBuildFile; fileRef = 6326052E2BED2684009CC628 /* ssd-mobilenet-v2.tflite */; };
63BD745E2BED434300078A57 /* download_models.sh in Resources */ = {isa = PBXBuildFile; fileRef = 63BD745D2BED434300078A57 /* download_models.sh */; };
7699B88040F8A987B510C191 /* libPods-objectdetection-objectdetectionTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 19F6CBCC0A4E27FBF8BF4A61 /* libPods-objectdetection-objectdetectionTests.a */; };
81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */; };
/* End PBXBuildFile section */
Expand Down Expand Up @@ -43,6 +46,9 @@
5709B34CF0A7D63546082F79 /* Pods-objectdetection.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-objectdetection.release.xcconfig"; path = "Target Support Files/Pods-objectdetection/Pods-objectdetection.release.xcconfig"; sourceTree = "<group>"; };
5B7EB9410499542E8C5724F5 /* Pods-objectdetection-objectdetectionTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-objectdetection-objectdetectionTests.debug.xcconfig"; path = "Target Support Files/Pods-objectdetection-objectdetectionTests/Pods-objectdetection-objectdetectionTests.debug.xcconfig"; sourceTree = "<group>"; };
5DCACB8F33CDC322A6C60F78 /* libPods-objectdetection.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-objectdetection.a"; sourceTree = BUILT_PRODUCTS_DIR; };
6326052C2BED2678009CC628 /* efficientdet-lite2.tflite */ = {isa = PBXFileReference; lastKnownFileType = file; name = "efficientdet-lite2.tflite"; path = "objectdetection/efficientdet-lite2.tflite"; sourceTree = "<group>"; };
6326052E2BED2684009CC628 /* ssd-mobilenet-v2.tflite */ = {isa = PBXFileReference; lastKnownFileType = file; name = "ssd-mobilenet-v2.tflite"; path = "objectdetection/ssd-mobilenet-v2.tflite"; sourceTree = "<group>"; };
63BD745D2BED434300078A57 /* download_models.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = download_models.sh; sourceTree = "<group>"; };
81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = LaunchScreen.storyboard; path = objectdetection/LaunchScreen.storyboard; sourceTree = "<group>"; };
89C6BE57DB24E9ADA2F236DE /* Pods-objectdetection-objectdetectionTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-objectdetection-objectdetectionTests.release.xcconfig"; path = "Target Support Files/Pods-objectdetection-objectdetectionTests/Pods-objectdetection-objectdetectionTests.release.xcconfig"; sourceTree = "<group>"; };
ED297162215061F000B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -88,6 +94,9 @@
13B07FAE1A68108700A75B9A /* objectdetection */ = {
isa = PBXGroup;
children = (
63BD745C2BED42AB00078A57 /* RunScripts */,
6326052E2BED2684009CC628 /* ssd-mobilenet-v2.tflite */,
6326052C2BED2678009CC628 /* efficientdet-lite2.tflite */,
37EB22AF2BBC9BAB002A84F7 /* efficientdet-lite0.tflite */,
13B07FAF1A68108700A75B9A /* AppDelegate.h */,
13B07FB01A68108700A75B9A /* AppDelegate.mm */,
Expand All @@ -109,6 +118,14 @@
name = Frameworks;
sourceTree = "<group>";
};
63BD745C2BED42AB00078A57 /* RunScripts */ = {
isa = PBXGroup;
children = (
63BD745D2BED434300078A57 /* download_models.sh */,
);
path = RunScripts;
sourceTree = "<group>";
};
832341AE1AAA6A7D00B99B32 /* Libraries */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -180,6 +197,7 @@
buildConfigurationList = 13B07F931A680F5B00A75B9A /* Build configuration list for PBXNativeTarget "objectdetection" */;
buildPhases = (
C38B50BA6285516D6DCD4F65 /* [CP] Check Pods Manifest.lock */,
63A629702BED32D90074A02B /* Download models */,
13B07F871A680F5B00A75B9A /* Sources */,
13B07F8C1A680F5B00A75B9A /* Frameworks */,
13B07F8E1A680F5B00A75B9A /* Resources */,
Expand Down Expand Up @@ -246,7 +264,10 @@
files = (
81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */,
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */,
6326052D2BED2678009CC628 /* efficientdet-lite2.tflite in Resources */,
37EB22B02BBC9BAB002A84F7 /* efficientdet-lite0.tflite in Resources */,
63BD745E2BED434300078A57 /* download_models.sh in Resources */,
6326052F2BED2684009CC628 /* ssd-mobilenet-v2.tflite in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -261,6 +282,9 @@
inputPaths = (
"$(SRCROOT)/.xcode.env.local",
"$(SRCROOT)/.xcode.env",
"$(SRCROOT)/ObjectDetector/efficientdet-lite0.tflite",
"$(SRCROOT)/ObjectDetector/efficientdet-ite2.tflite",
"$(SRCROOT)/ObjectDetector/ssd_mobilenet-v2.tflite",
);
name = "Bundle React Native code and images";
outputPaths = (
Expand All @@ -286,6 +310,28 @@
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-objectdetection/Pods-objectdetection-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
63A629702BED32D90074A02B /* Download models */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
);
name = "Download models";
outputFileListPaths = (
);
outputPaths = (
"$(SRCROOT)/ObjectDetector/efficientdet-lite0.tflite",
"$(SRCROOT)/ObjectDetector/efficientdet-lite2.tflite",
"$(SRCROOT)/ObjectDetector/ssd-mobilenet-v2.tflite",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "$SRCROOT/RunScripts/download_models.sh\n";
};
A55EABD7B0C7F3A422A6CC61 /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
return [super application:application didFinishLaunchingWithOptions:launchOptions];
}


- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
return [self getBundleURL];
Expand Down
Binary file not shown.
9 changes: 4 additions & 5 deletions examples/objectdetection/src/CameraStream.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import {
import type { RootTabParamList } from "./navigation";
import type { BottomTabScreenProps } from "@react-navigation/bottom-tabs";
import { useSettings } from "./app-settings";
import Ionicons from "react-native-vector-icons/Ionicons";

import {
ObjectFrame,
convertObjectDetectionFrame,
Expand Down Expand Up @@ -101,7 +103,7 @@ export const CameraStream: React.FC<Props> = () => {
))}
</Canvas>
<Pressable style={styles.cameraSwitchButton} onPress={setActiveCamera}>
<Text style={styles.cameraSwitchButtonText}>Switch Camera</Text>
<Ionicons name="repeat-outline" />
</Pressable>
</View>
);
Expand Down Expand Up @@ -184,8 +186,5 @@ const styles = StyleSheet.create({
top: 20,
right: 20,
},
cameraSwitchButtonText: {
color: "white",
fontSize: 16,
},

});
7 changes: 3 additions & 4 deletions examples/objectdetection/src/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ export const Settings: React.FC<Props> = () => {
{ label: "CPU", value: Delegate.CPU },
]}
/>
{/* Disable Model selection temporarily
<OptionSelect
<OptionSelect
label="Model selections: "
value={settings.model}
setValue={(value) =>
Expand All @@ -94,9 +93,9 @@ export const Settings: React.FC<Props> = () => {
items={[
{ label: "EfficientDet-Lite0", value: "efficientdet-lite0" },
{ label: "EfficientDet-Lite2", value: "efficientdet-lite2" },
{ label: "SSD MobileNetV2", value: "ssd-mobilenetv2" },
{ label: "SSD MobileNetV2", value: "ssd-mobilenet-v2" },
]}
/> */}
/>
<OptionSlider
label={(value) => `Max results: ${value}`}
value={settings.maxResults}
Expand Down

0 comments on commit 428d7e5

Please sign in to comment.