Skip to content

Instantly share code, notes, and snippets.

View dkurt's full-sized avatar

Dmitry Kurtaev dkurt

View GitHub Profile
node {
name: "image_tensor"
op: "Placeholder"
attr {
key: "dtype"
value {
type: DT_UINT8
}
}
attr {
node {
name: "image_tensor"
op: "Placeholder"
attr {
key: "dtype"
value {
type: DT_UINT8
}
}
attr {
node {
name: "image_tensor"
op: "Placeholder"
attr {
key: "dtype"
value {
type: DT_UINT8
}
}
attr {
from math import sqrt
min_scale = 0.2
max_scale = 0.95
num_layers = 6
aspect_ratios = [1.0, 2.0, 0.5, 3.0, 0.333]
image_width = 300
image_height = 300
scales = [min_scale + (max_scale - min_scale) * i / (num_layers - 1) for i in range(num_layers)] + [1.0]
import cv2 as cv
import numpy as np
img = cv.imread('/home/dkurt/Pictures/download.jpeg')
inp = cv.dnn.blobFromImage(img, 0.017, (224, 224), (103.94,116.78,123.68), swapRB=False, crop=False)
net = cv.dnn.readNet('shufflenet_1x_g3_deploy.prototxt', 'shufflenet_1x_g3.caffemodel')
net.setPreferableBackend(cv.dnn.DNN_BACKEND_OPENCV)
net.setInput(inp)
out = net.forward()
  1. Download Android Studio

  2. Download Android NDK and SDK (as far as I remember SDK comes with Android Studio or might be installed from it's manager).

  3. Clone master branch of OpenCV. Create a /path/to/opencv/build folder and run cmake with the following flags. You may emit BUILD_LIST flag to build all the modules.

export ANDROID_NDK=/home/dkurtaev/Downloads/android-ndk-r14b
export ANDROID_SDK=/home/dkurtaev/Android/Sdk/
export ANDROID_HOME=/home/dkurtaev/Android/Sdk/
import cv2 as cv
import numpy as np
def getBoardPoints():
pts = []
for x in range(0, 9):
for y in range(0, 6):
pts.append([x, y, 0])
return np.array(pts, dtype=np.float32)
#include <opencv2/dnn.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
std::vector<Rect> boxes; std::vector<float> confidences; std::vector<int> classIds;
#include <opencv2/dnn/layer.details.hpp>
#include <iostream>
FROM ubuntu:18.04
RUN apt-get update && \
apt-get install -y \
git \
cmake \
wget \
unzip
RUN git clone https://github.com/intel/intel-graphics-compiler igc && \
  1. Prepare the model (tested with mobilenetv2_coco_cityscapes_trainfine from https://github.com/tensorflow/models/blob/master/research/deeplab/g3doc/model_zoo.md)
import tensorflow as tf
from tensorflow.tools.graph_transforms import TransformGraph
from tensorflow.python.tools import optimize_for_inference_lib


graph = 'deeplabv3_mnv2_cityscapes_train/frozen_inference_graph.pb'
with tf.gfile.FastGFile(graph, 'rb') as f:
 graph_def = tf.GraphDef()