Skip to content

Instantly share code, notes, and snippets.

View Namburger's full-sized avatar
😃
segfault

Nam Vu Namburger

😃
segfault
View GitHub Profile
@Namburger
Namburger / multi_crash.py
Created October 30, 2019 15:52
crashing Edgetpu Accelerator with multi-thread access
import argparse
from edgetpu.classification.engine import ClassificationEngine
from edgetpu.utils import dataset_utils
from PIL import Image
import multiprocessing
from multiprocessing import Process
def main():
parser = argparse.ArgumentParser()
parser.add_argument(
@Namburger
Namburger / Makefile
Created November 5, 2019 15:19
This makefile for edgetpu will include the minimal.cc example as well as the glibc_compat.h needed for the build
# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
@Namburger
Namburger / switch.py
Last active November 8, 2019 17:08
roughly measuring the "switch" time between 2 models
import threading
import time
import cv2
import cv2 as cv
import tensorflow as tf
from tensorflow.lite.python.interpreter import load_delegate
from edgetpu.basic import edgetpu_utils
from collections import namedtuple
import numpy as np
@Namburger
Namburger / converting_keras_model.py
Last active April 5, 2024 13:22
Example of creating a dummy keras model and convert it to tflite with tensorflow1.15
import tensorflow as tf
if not str(tf.__version__).startswith('1.15'):
print('please use tensorflow 1.15')
exit()
from tensorflow.keras.models import Model
from tensorflow.keras.layers import Input, Conv2D
tf.enable_eager_execution()
image_shape = (64,64,3)
@Namburger
Namburger / quantize_frozen_graph.py
Last active May 26, 2020 14:12
Example code for post training quantization with tensorflow from_frozen_graph API (deprecated in tensorflow2.0).
# More infro here on Post Training Quantization here:
# https://www.tensorflow.org/lite/performance/post_training_quantization
# from_frozen_graph api is not n tf2.0 but can still be use with tf.compat.v1.lite, more on this api:
# https://www.tensorflow.org/api_docs/python/tf/compat/v1/lite/TFLiteConverter#from_frozen_graph
# This is an example for converting a frozen graph model to a fully quantized tflite model
# The model used here is http://download.tensorflow.org/models/mobilenet_v1_2018_08_02/mobilenet_v1_0.25_192.tgz
# Note that with post training quantization, sometimes it is not guarantee that the model will be fully quantized.
import sys, os, glob
import tensorflow as tf
@Namburger
Namburger / Dockerfile
Last active March 24, 2020 18:31
minimal Dockerfile for running some edgetpu demos
# 1) create this dockerfile
# 2) build: docker build -t "coral-edgetpu" .
# 3) run: docker run -it --privileged -v /dev/bus/usb:/dev/bus/usb coral-edgetpu /bin/bash
# 4) download install requriements: cd ~/tflite/python/examples/classification/ && bash install_requirements.sh
# 5) run example: python3 classify_image.py \
# > --model models/mobilenet_v2_1.0_224_inat_bird_quant_edgetpu.tflite \
# > --labels models/inat_bird_labels.txt \
# > --input images/parrot.jpg
FROM tensorflow/tensorflow:1.15.0-py3
@Namburger
Namburger / Dockerfile.edgetpu.tensorflow.1.15.0-py3
Last active January 31, 2020 17:37
minimal Dockerfile for running some edgetpu demos
# 1) create this dockerfile
# 2) build: docker build -t "coral-edgetpu" .
# 3) run: docker run -it --privileged -v /dev/bus/usb:/dev/bus/usb coral-edgetpu /bin/bash
# 4) download install requriements: cd ~/tflite/python/examples/classification/ && bash install_requirements.sh
# 5) run example: python3 classify_image.py \
# > --model models/mobilenet_v2_1.0_224_inat_bird_quant_edgetpu.tflite \
# > --labels models/inat_bird_labels.txt \
# > --input images/parrot.jpg
FROM tensorflow/tensorflow:1.15.0-py3
@Namburger
Namburger / Dockerfile.edgetpu-example.devboard
Last active November 19, 2020 15:19
minimal Dockerfile for running some edgetpu demos on the dev board using the arm64 debian image
THIS IS DEPRECATED
# docker can be installed on the dev board following these instructions:
# https://github.com/f0cal/google-coral/issues/32#issuecomment-571629174
# 1) create this dockerfile
# 2) build: docker build -t "coral" .
# 3) run: docker run -it --device /dev/apex_0:/dev/apex_0 coral /bin/bash
# 4) Try the classify_image demo:
# apt-get install edgetpu-examples
@Namburger
Namburger / classify.py
Last active January 29, 2020 17:58
classify image with tensorflow's load delegate
# https://www.apache.org/licenses/LICENSE-2.0
# Copyright 2019 Google LLC
# Modified by Nam Vu
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
r""" Example using tf.compat.v2.lite to classify
@Namburger
Namburger / detects.service
Last active May 31, 2022 23:23
An example systemd service for object detection in the coral dev board.
# This is an example of starting a systemd object detection service on boot on the Coral Dev Board.
# 1) create a file call detects.service with the following contents:
[Unit]
Description=systemd object detection service
After=weston.target
[Service]
PAMName=login