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 / Dockerfile
Last active October 21, 2022 12:48
ubuntu18.04 coral minimal example
FROM ubuntu:18.04
WORKDIR /home
ENV HOME /home
RUN cd ~
RUN apt-get update
RUN apt-get install -y git nano python3-pip python-dev pkg-config wget usbutils curl
RUN echo "deb https://packages.cloud.google.com/apt coral-edgetpu-stable main" \
| tee /etc/apt/sources.list.d/coral-edgetpu.list
@Namburger
Namburger / minimal-devboard-tflite-dockerfile
Created November 19, 2020 15:26
Minimal Dockerfile for Coral Dev Board with tflite API
FROM arm64v8/debian:latest
WORKDIR /home
ENV HOME /home
RUN cd ~
RUN apt-get update
RUN apt-get install -y git nano python3-pip python-dev pkg-config wget usbutils curl
RUN echo "deb https://packages.cloud.google.com/apt coral-edgetpu-stable main" \
| tee /etc/apt/sources.list.d/coral-edgetpu.list
@Namburger
Namburger / disable-hdmi-mendel.dts
Created August 28, 2020 22:51
disable-hdmi-mendel.dts
/dts-v1/;
/plugin/;
/ {
compatible = "fsl,imx8mq-hdmi";
fragment@0 {
target-path = "/hdmi@32c00000";
__overlay__ {
status = "disabled";
@Namburger
Namburger / classify_camera.py
Created August 20, 2020 13:51
classify_camera.py
# Taken from here: https://github.com/googlecreativelab/teachablemachine-community/blob/master/snippets/markdown/image/edgetpu/python.md just fixed some bugs
from edgetpu.classification.engine import ClassificationEngine
from PIL import Image
import cv2
import re
import os
import sys
# the TFLite converted to be used with edgetpu
# Install the edgetpu compiler.
!curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
!echo "deb https://packages.cloud.google.com/apt coral-edgetpu-stable main" | sudo tee /etc/apt/sources.list.d/coral-edgetpu.list
!sudo apt-get update
!sudo apt-get install edgetpu-compiler
# Compile our model and make a tarball of the finished trained model.
%cd /content/output_model
!edgetpu_compiler -s ssdlite_mobiledet_custom.tflite
%cd /content/
@Namburger
Namburger / evaluate_tflite.py
Created August 15, 2020 02:11
evaluate_tflite.py
# Install tflite_runtime package to evaluate the model.
!pip3 install https://dl.google.com/coral/python/tflite_runtime-2.1.0.post1-cp36-cp36m-linux_x86_64.whl
# Now we do evaluation on the tflite model.
import os
import numpy as np
from tflite_runtime.interpreter import Interpreter
from tflite_runtime.interpreter import load_delegate
from PIL import Image
from PIL import ImageDraw
# Now we can convert this custom trained model to a CPU tflite model
!tflite_convert \
--output_file="/content/output_model/ssdlite_mobiledet_dog_vs_cat.tflite" \
--graph_def_file="/content/output_model/tflite_graph.pb" \
--inference_type=QUANTIZED_UINT8 \
--input_arrays="normalized_input_image_tensor" \
--output_arrays="TFLite_Detection_PostProcess,TFLite_Detection_PostProcess:1,TFLite_Detection_PostProcess:2,TFLite_Detection_PostProcess:3" \
--mean_values=128 \
--std_dev_values=128 \
--input_shapes=1,320,320,3 \
# Now we export this model to tflite_graph format.
%cd /content/models/research
!mkdir /content/output_model
!python3 object_detection/export_tflite_ssd_graph.py \
--pipeline_config_path=/content/models/research/object_detection/samples/configs/ssdlite_mobiledet_edgetpu_320x320_coco_sync_4x4.config \
--trained_checkpoint_prefix=/content/train/model.ckpt-25000 \
--output_directory=/content/output_model \
--add_postprocessing_op=true
# Make sure to change the model-ckpt-# to match the checkpoint number you used.
# Do a Quick Evaluation on the inference graph model.
import numpy as np
import os
import sys
import tensorflow as tf
from collections import defaultdict
from matplotlib import pyplot as plt
from PIL import Image
# Let's download some test data from flickr.
!mkdir /content/test
!cd /content/test
!wget https://live.staticflickr.com/7921/46683787864_86c9501c24_c_d.jpg -O /content/test/image1.jpg
!wget https://live.staticflickr.com/4/8451898_8bedb2ae53_c_d.jpg -O /content/test/image2.jpg
!wget https://live.staticflickr.com/2654/3997966238_f454845087_c_d.jpg -O /content/test/image3.jpg
!wget https://live.staticflickr.com/2818/34032378096_5309537c9f_c_d.jpg -O /content/test/image4.jpg
!wget https://live.staticflickr.com/8682/28214087384_4c7711584d_c_d.jpg -O /content/test/image5.jpg