Skip to content
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

For Mobilenet V4 large #821

Merged
merged 31 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
08bc86b
hacks for model small
freedomtan Nov 28, 2023
8a9e510
small -> medium
freedomtan Nov 28, 2023
cf3fa94
medium -> large
freedomtan Nov 28, 2023
4bea665
for quantized models
freedomtan Nov 28, 2023
2283422
make float model work again
freedomtan Jan 2, 2024
7317b9b
fix pixel and neuron settings
freedomtan Jan 3, 2024
bb7dda6
change preprocessing and label offset
freedomtan Jan 11, 2024
c259333
Adding changes for calibration dataset preprocessing
mohitmundhragithub Jan 8, 2024
c15f4b0
hacks
freedomtan Jan 11, 2024
b13ab62
clean up
freedomtan Feb 1, 2024
5d46760
fix pixel backend settings
freedomtan Feb 2, 2024
ccc59bf
fix pixel settings & icons for classificaton v2
freedomtan Feb 2, 2024
cffb43d
fix lint issue
freedomtan Feb 2, 2024
55c5cd0
Revert "Adding changes for calibration dataset preprocessing"
freedomtan Feb 6, 2024
74b4922
revert imagenet width and height
freedomtan Feb 6, 2024
0f3d5b9
fix offline for Pixel backend
freedomtan Feb 6, 2024
07a68fc
Merge branch '719/new-edge-tpu-model' into test_new_model_l
anhappdev Feb 6, 2024
8d2a0e0
Undo update for Windows build
anhappdev Feb 6, 2024
92d092e
update MobilenetV4 settings for TFLite, Neuron, and Pixel
freedomtan Feb 8, 2024
d9e044a
update windows setting for Mobilenet V4
freedomtan Feb 8, 2024
242990e
Merge 719/new-edge-tpu-model
anhappdev Feb 8, 2024
fe4d2d1
Use MobileNetV4 model in Apple devices
anhappdev Feb 8, 2024
d15f5a8
Fix tflite_settings_windows.pbtxt
anhappdev Feb 13, 2024
dc42a63
Update expected_accuracy
anhappdev Feb 13, 2024
f980d58
Update expected_accuracy and expected_throughput for Apple devices
anhappdev Feb 13, 2024
441cbf7
Use fp32 model for Windows
anhappdev Feb 13, 2024
73dc658
Update expected_throughput for Windows
anhappdev Feb 13, 2024
11e6c4c
Update expected_throughput for Android
anhappdev Feb 13, 2024
5c2717d
Update S3 provider in android-build-test.yml (#855)
nathanw-mlc Feb 13, 2024
ce5e74a
Reduce batch_size for image_classification_offline_v2 in Pixel 6
anhappdev Feb 21, 2024
8b39846
Merge remote-tracking branch 'origin/master' into test_new_model_l
anhappdev Feb 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .github/workflows/android-build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,23 +86,23 @@ jobs:
python3 -m pip install awscli
- name: Download Samsung libraries
env:
AWS_ACCESS_KEY_ID: ${{ secrets.READONLY_AWS_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.READONLY_AWS_KEY }}
AWS_ACCESS_KEY_ID: ${{ secrets.READONLY_R2_ACCESS_KEY }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.READONLY_R2_SECRET_KEY }}
run: |
aws s3 --endpoint-url=https://s3.us-east-1.lyvecloud.seagate.com \
aws s3 --endpoint-url=https://c2686074cb2caf5cbaf6d134bdba8b47.r2.cloudflarestorage.com \
cp --quiet s3://mlcommons-mobile-wg-private/libs/v3.1/samsung_libs_v3.1_20231116.zip /tmp/ && \
unzip /tmp/samsung_libs_v3.1_20231116.zip -d /tmp/samsung_libs_v3.1_20231116 && \
rm /tmp/samsung_libs_v3.1_20231116.zip && \
mkdir -p mobile_back_samsung/samsung/lib/internal && \
mv /tmp/samsung_libs_v3.1_20231116/* mobile_back_samsung/samsung/lib/internal/
- name: Download QTI libraries
env:
AWS_ACCESS_KEY_ID: ${{ secrets.READONLY_AWS_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.READONLY_AWS_KEY }}
AWS_ACCESS_KEY_ID: ${{ secrets.READONLY_R2_ACCESS_KEY }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.READONLY_R2_SECRET_KEY }}
run: |
aws s3 --endpoint-url=https://s3.us-east-1.lyvecloud.seagate.com \
aws s3 --endpoint-url=https://c2686074cb2caf5cbaf6d134bdba8b47.r2.cloudflarestorage.com \
cp --quiet s3://mlcommons-mobile-wg-private/libs/v3.1/qaisw-2.13.4.230831213719_60417-linux.zip /tmp/ && \
unzip -P ${AWS_SECRET_ACCESS_KEY} /tmp/qaisw-2.13.4.230831213719_60417-linux.zip -d /tmp/qaisw-2.13.4.230831213719_60417-linux && \
unzip -P ${{ secrets.READONLY_AWS_KEY }} /tmp/qaisw-2.13.4.230831213719_60417-linux.zip -d /tmp/qaisw-2.13.4.230831213719_60417-linux && \
rm /tmp/qaisw-2.13.4.230831213719_60417-linux.zip && \
mv /tmp/qaisw-2.13.4.230831213719_60417-linux/qaisw-2.13.4.230831213719_60417 mobile_back_qti/
- name: Cache bazel
Expand Down
12 changes: 6 additions & 6 deletions flutter/assets/tasks.pbtxt
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,9 @@ task {
model {
id: "MobileNetEdgeTPUv2-L"
name: "MobileNetEdgeTPUv2-L"
offset: 1
image_width: 224
image_height: 224
offset: 0
image_width: 384
image_height: 384
num_classes: 1000
}
}
Expand Down Expand Up @@ -283,9 +283,9 @@ task {
model {
id: "MobileNetEdgeTPUv2-L"
name: "MobileNetEdgeTPUv2-L"
offset: 1
image_width: 224
image_height: 224
offset: 0
image_width: 384
image_height: 384
num_classes: 1000
}
}
16 changes: 8 additions & 8 deletions flutter/integration_test/expected_accuracy.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ const Map<String, Interval> _imageClassification = {
};

const Map<String, Interval> _imageClassificationV2 = {
'cpu': Interval(min: 0.69, max: 0.71),
'npu': Interval(min: 0.69, max: 0.71),
'tpu': Interval(min: 0.69, max: 0.71),
'ane': Interval(min: 0.69, max: 0.71),
'cpu&gpu&ane': Interval(min: 0.69, max: 0.71),
'snpe_dsp': Interval(min: 0.69, max: 0.71),
'psnpe_dsp': Interval(min: 0.69, max: 0.71),
'neuron-mdla': Interval(min: 0.69, max: 0.71),
'cpu': Interval(min: 0.88, max: 0.91),
'npu': Interval(min: 0.88, max: 0.91),
'tpu': Interval(min: 0.88, max: 0.91),
'ane': Interval(min: 0.79, max: 0.91),
'cpu&gpu&ane': Interval(min: 0.79, max: 0.91),
'snpe_dsp': Interval(min: 0.88, max: 0.91),
'psnpe_dsp': Interval(min: 0.88, max: 0.91),
'neuron-mdla': Interval(min: 0.79, max: 0.81),
};

const Map<String, Interval> _objectDetection = {
Expand Down
30 changes: 15 additions & 15 deletions flutter/integration_test/expected_throughput.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,24 @@ const Map<String, Map<String, Interval>> _imageClassification = {
// TODO (anhappdev): update the expected value for _imageClassificationV2 after gathering some statistics
const Map<String, Map<String, Interval>> _imageClassificationV2 = {
_kTFLiteBackend: {
_kCloudBuildX23: Interval(min: 2, max: 11),
_kCloudBuildX28: Interval(min: 2, max: 12),
_kCloudBuildX23: Interval(min: 1, max: 9),
_kCloudBuildX28: Interval(min: 1, max: 9),
_kRyzen5600: Interval(min: 1, max: 37),
_kPixel5: Interval(min: 60, max: 75),
_kIphoneOnGitHubAction: Interval(min: 1, max: 7),
_kPixel5: Interval(min: 20, max: 75),
_kIphoneOnGitHubAction: Interval(min: 0.4, max: 7),
_kIphoneOnMacbookM1: Interval(min: 10, max: 27),
},
_kCoreMLBackend: {
_kIphoneOnGitHubAction: Interval(min: 1, max: 7),
_kIphoneOnGitHubAction: Interval(min: 0.4, max: 7),
},
_kPixelBackend: {
_kPixel6: Interval(min: 500, max: 600),
_kPixel6: Interval(min: 100, max: 600),
},
_kQtiBackend: {
_kS22Ultra: Interval(min: 1900, max: 2200),
},
_kMediatekBackend: {
_kDN2103: Interval(min: 30, max: 50),
_kDN2103: Interval(min: 5, max: 50),
},
};

Expand All @@ -89,7 +89,7 @@ const Map<String, Map<String, Interval>> _objectDetection = {
_kIphoneOnGitHubAction: Interval(min: 0.5, max: 4),
},
_kPixelBackend: {
_kPixel6: Interval(min: 250, max: 450),
_kPixel6: Interval(min: 200, max: 450),
},
_kQtiBackend: {
_kS22Ultra: Interval(min: 800, max: 1400),
Expand Down Expand Up @@ -195,24 +195,24 @@ const Map<String, Map<String, Interval>> _imageClassificationOffline = {
// TODO (anhappdev): update the expected value for _imageClassificationOfflineV2 after gathering some statistics
const Map<String, Map<String, Interval>> _imageClassificationOfflineV2 = {
_kTFLiteBackend: {
_kCloudBuildX23: Interval(min: 4, max: 14),
_kCloudBuildX28: Interval(min: 3, max: 14),
_kCloudBuildX23: Interval(min: 1, max: 9),
_kCloudBuildX28: Interval(min: 1, max: 9),
_kRyzen5600: Interval(min: 20, max: 60),
_kPixel5: Interval(min: 60, max: 180),
_kIphoneOnGitHubAction: Interval(min: 1, max: 15),
_kPixel5: Interval(min: 20, max: 180),
_kIphoneOnGitHubAction: Interval(min: 0.4, max: 15),
_kIphoneOnMacbookM1: Interval(min: 10, max: 45),
},
_kCoreMLBackend: {
_kIphoneOnGitHubAction: Interval(min: 1, max: 15),
_kIphoneOnGitHubAction: Interval(min: 0.4, max: 15),
},
_kPixelBackend: {
_kPixel6: Interval(min: 700, max: 1700),
_kPixel6: Interval(min: 100, max: 1700),
},
_kQtiBackend: {
_kS22Ultra: Interval(min: 2600, max: 3000),
},
_kMediatekBackend: {
_kDN2103: Interval(min: 75, max: 110),
_kDN2103: Interval(min: 5, max: 90),
},
};

Expand Down
24 changes: 12 additions & 12 deletions mobile_back_apple/cpp/backend_coreml/coreml_settings.pbtxt
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,22 @@ benchmark_setting {
delegate_name: "CPU & GPU & ANE"
accelerator_name: "cpu&gpu&ane"
accelerator_desc: "All compute units"
model_path: "https://github.com/mlcommons/mobile_models/raw/anh/add-MNEdgeTPU-V2-L/v3_1/CoreML/MobilenetEdgeTPUv2.mlmodel"
model_checksum: "875730de6fa07333051ca0f283fb23fd"
model_path: "https://github.com/mlcommons/mobile_models/releases/download/v4.0-coreml/MobilenetV4_Large.mlmodel"
model_checksum: "fbfba70596f74010852f22fa04721202"
}
delegate_choice: {
delegate_name: "CPU & GPU"
accelerator_name: "cpu&gpu"
accelerator_desc: "CPU and GPU"
model_path: "https://github.com/mlcommons/mobile_models/raw/anh/add-MNEdgeTPU-V2-L/v3_1/CoreML/MobilenetEdgeTPUv2.mlmodel"
model_checksum: "875730de6fa07333051ca0f283fb23fd"
model_path: "https://github.com/mlcommons/mobile_models/releases/download/v4.0-coreml/MobilenetV4_Large.mlmodel"
model_checksum: "fbfba70596f74010852f22fa04721202"
}
delegate_choice: {
delegate_name: "CPU & ANE"
accelerator_name: "cpu&ane"
accelerator_desc: "CPU and Neural Engine"
model_path: "https://github.com/mlcommons/mobile_models/raw/anh/add-MNEdgeTPU-V2-L/v3_1/CoreML/MobilenetEdgeTPUv2.mlmodel"
model_checksum: "875730de6fa07333051ca0f283fb23fd"
model_path: "https://github.com/mlcommons/mobile_models/releases/download/v4.0-coreml/MobilenetV4_Large.mlmodel"
model_checksum: "fbfba70596f74010852f22fa04721202"
}
delegate_selected: "CPU & GPU & ANE"
}
Expand All @@ -93,24 +93,24 @@ benchmark_setting {
accelerator_name: "cpu&gpu&ane"
accelerator_desc: "All compute units"
batch_size: 32
model_path: "https://github.com/mlcommons/mobile_models/raw/anh/add-MNEdgeTPU-V2-L/v3_1/CoreML/MobilenetEdgeTPUv2.mlmodel"
model_checksum: "875730de6fa07333051ca0f283fb23fd"
model_path: "https://github.com/mlcommons/mobile_models/releases/download/v4.0-coreml/MobilenetV4_Large.mlmodel"
model_checksum: "fbfba70596f74010852f22fa04721202"
}
delegate_choice: {
delegate_name: "CPU & GPU"
accelerator_name: "cpu&gpu"
accelerator_desc: "CPU and GPU"
batch_size: 32
model_path: "https://github.com/mlcommons/mobile_models/raw/anh/add-MNEdgeTPU-V2-L/v3_1/CoreML/MobilenetEdgeTPUv2.mlmodel"
model_checksum: "875730de6fa07333051ca0f283fb23fd"
model_path: "https://github.com/mlcommons/mobile_models/releases/download/v4.0-coreml/MobilenetV4_Large.mlmodel"
model_checksum: "fbfba70596f74010852f22fa04721202"
}
delegate_choice: {
delegate_name: "CPU & ANE"
accelerator_name: "cpu&ane"
accelerator_desc: "CPU and Neural Engine"
batch_size: 32
model_path: "https://github.com/mlcommons/mobile_models/raw/anh/add-MNEdgeTPU-V2-L/v3_1/CoreML/MobilenetEdgeTPUv2.mlmodel"
model_checksum: "875730de6fa07333051ca0f283fb23fd"
model_path: "https://github.com/mlcommons/mobile_models/releases/download/v4.0-coreml/MobilenetV4_Large.mlmodel"
model_checksum: "fbfba70596f74010852f22fa04721202"
}
delegate_selected: "CPU & GPU & ANE"
}
Expand Down
24 changes: 16 additions & 8 deletions mobile_back_apple/dev-utils/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,13 @@ tflite-run-ic-v2:
bazel-bin/flutter/cpp/binary/main EXTERNAL image_classification_v2 \
--mode=PerformanceOnly \
--output_dir="${REPO_ROOT_DIR}/output" \
--model_file="${REPO_ROOT_DIR}/mobile_back_apple/dev-resources/mobilenet_edgetpu/mobilenet-edgetpu-v2-L_fp32.tflite" \
--model_file="${REPO_ROOT_DIR}/mobile_back_apple/dev-resources/mobilenet_v4/MobileNetV4-Conv-Large-fp32.tflite" \
--image_width=384 \
--image_height=384 \
--lib_path="bazel-bin/mobile_back_tflite/cpp/backend_tflite/libtflitebackend.so" \
--images_directory="${REPO_ROOT_DIR}/mobile_back_apple/dev-resources/imagenet/images" \
--groundtruth_file="${REPO_ROOT_DIR}/mobile_back_apple/dev-resources/imagenet/imagenet_val.txt" \
--offset=1
--offset=0

tflite-run-ic-offline-v2:
cd ${REPO_ROOT_DIR} && \
Expand All @@ -73,11 +75,13 @@ tflite-run-ic-offline-v2:
--scenario=Offline \
--batch_size=32 \
--output_dir="${REPO_ROOT_DIR}/output" \
--model_file="${REPO_ROOT_DIR}/mobile_back_apple/dev-resources/mobilenet_edgetpu/mobilenet-edgetpu-v2-L_fp32.tflite" \
--model_file="${REPO_ROOT_DIR}/mobile_back_apple/dev-resources/mobilenet_v4/MobileNetV4-Conv-Large-fp32.tflite" \
--image_width=384 \
--image_height=384 \
--lib_path="bazel-bin/mobile_back_tflite/cpp/backend_tflite/libtflitebackend.so" \
--images_directory="${REPO_ROOT_DIR}/mobile_back_apple/dev-resources/imagenet/images" \
--groundtruth_file="${REPO_ROOT_DIR}/mobile_back_apple/dev-resources/imagenet/imagenet_val.txt" \
--offset=1
--offset=0

tflite-run-od:
cd ${REPO_ROOT_DIR} && \
Expand Down Expand Up @@ -155,11 +159,13 @@ coreml-run-ic-v2:
bazel-bin/flutter/cpp/binary/main EXTERNAL image_classification \
--mode=PerformanceOnly \
--output_dir="${REPO_ROOT_DIR}/output" \
--model_file="${REPO_ROOT_DIR}/mobile_back_apple/dev-resources/mobilenet_edgetpu/MobilenetEdgeTPUv2.mlmodel" \
--model_file="${REPO_ROOT_DIR}/mobile_back_apple/dev-resources/mobilenet_v4/MobilenetV4_Large.mlmodel" \
--image_width=384 \
--image_height=384 \
--lib_path="bazel-bin/mobile_back_apple/cpp/backend_coreml/libcoremlbackend.so" \
--images_directory="${REPO_ROOT_DIR}/mobile_back_apple/dev-resources/imagenet/images" \
--groundtruth_file="${REPO_ROOT_DIR}/mobile_back_apple/dev-resources/imagenet/imagenet_val.txt" \
--offset=1
--offset=0

coreml-run-ic-offline-v2:
cd ${REPO_ROOT_DIR} && \
Expand All @@ -168,11 +174,13 @@ coreml-run-ic-offline-v2:
--scenario=Offline \
--batch_size=32 \
--output_dir="${REPO_ROOT_DIR}/output" \
--model_file="${REPO_ROOT_DIR}/mobile_back_apple/dev-resources/mobilenet_edgetpu/MobilenetEdgeTPUv2.mlmodel" \
--model_file="${REPO_ROOT_DIR}/mobile_back_apple/dev-resources/mobilenet_v4/MobilenetV4_Large.mlmodel" \
--image_width=384 \
--image_height=384 \
--lib_path="bazel-bin/mobile_back_apple/cpp/backend_coreml/libcoremlbackend.so" \
--images_directory="${REPO_ROOT_DIR}/mobile_back_apple/dev-resources/imagenet/images" \
--groundtruth_file="${REPO_ROOT_DIR}/mobile_back_apple/dev-resources/imagenet/imagenet_val.txt" \
--offset=1
--offset=0

coreml-run-od:
cd ${REPO_ROOT_DIR} && \
Expand Down
28 changes: 13 additions & 15 deletions mobile_back_apple/models/icv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,34 @@
# limitations under the License.

import coremltools as ct
import tensorflow as tf
import tensorflow_hub as hub


def main():
print("Retrieve model from TFHub...")
keras_layer = hub.KerasLayer('https://tfhub.dev/google/edgetpu/vision/mobilenet-edgetpu-v2/l/1')
keras_model = tf.keras.Sequential([keras_layer])
keras_model.build([None, 224, 224, 3])
input_tensor = tf.ones((4, 224, 224, 3))
output_tensor = keras_model(input_tensor)
print("output_tensor.shape:", output_tensor.shape)

"""
Download the MobileNetV4-Conv-Large-fp32 from https://github.com/mlcommons/mobile_open/releases
Tested with tensorflow==2.15.0 and coremltools==7.1
"""
saved_model_dir = '../dev-resources/mobilenet_v4/MobileNetV4-Conv-Large-saved-model'
export_fpath = '../dev-resources/mobilenet_v4/MobilenetV4_Large.mlmodel'
print("Converting model...")
model = ct.convert(
keras_model,
saved_model_dir,
source="tensorflow",
convert_to="neuralnetwork",
inputs=[ct.TensorType(shape=(1, 224, 224, 3))],
inputs=[ct.TensorType(shape=(1, 384, 384, 3))],
)
model.short_description = "MobilenetEdgeTPUv2 from https://tfhub.dev/google/edgetpu/vision/mobilenet-edgetpu-v2/l/1"
model.short_description = "MobileNetV4-Conv-Large-fp32 from https://github.com/mlcommons/mobile_open"

spec = model.get_spec()
for n in (1, 1001):
spec.description.output[0].type.multiArrayType.shape.append(n)

ct.utils.rename_feature(spec, "keras_layer_input", "images")
ct.utils.rename_feature(spec, "inputs", "images")
ct.utils.rename_feature(spec, "Identity", "Softmax")
print(spec.description)

export_fpath = '../dev-resources/mobilenet_edgetpu/MobilenetEdgeTPUv2.mlmodel'
ct.models.MLModel(spec).save(export_fpath)
print("Done! Core ML model exported to:", export_fpath)


if __name__ == "__main__":
Expand Down
Loading
Loading