Skip to content

Instantly share code, notes, and snippets.

View dkurt's full-sized avatar

Dmitry Kurtaev dkurt

View GitHub Profile
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]
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 {
# http://answers.opencv.org/s/answers/186571
node {
name: "input_image"
op: "Placeholder"
attr {
key: "dtype"
value {
type: DT_FLOAT
}
}
// Wiki page about how to create .pbtxt files: https://github.com/opencv/opencv/wiki/TensorFlow-Object-Detection-API
// This page is referenced to a single script https://github.com/opencv/opencv/blob/master/samples/dnn/tf_text_graph_ssd.py
#include <opencv2/opencv.hpp>
#include <opencv2/dnn.hpp>
using namespace cv;
using namespace dnn;
const char* classes[] = {"background", "person", "bicycle", "car", "motorcycle",
"airplane", "bus", "train", "truck", "boat", "traffic light", "fire hydrant",
node {
name: "image_tensor"
op: "Placeholder"
attr {
key: "dtype"
value {
type: DT_UINT8
}
}
attr {
node {
name: "image_tensor"
op: "Placeholder"
}
node {
name: "FeatureExtractor/MobilenetV1/MobilenetV1/Conv2d_0/convolution"
op: "Conv2D"
input: "image_tensor"
input: "FeatureExtractor/MobilenetV1/Conv2d_0/weights"
attr {
@dkurt
dkurt / dnn.tf.md
Last active August 15, 2018 07:35

Let's discuss how to deploy deep learning models trained in TensorFlow framework both in TensorFlow and using OpenCV.

Requirements

  • TensorFlow
  • TensorBoard (optional but hardly recommended)
  • OpenCV with python bindings

Define a graph

This is how we define a network with a single convolution layer followed by ReLU activation function:

@dkurt
dkurt / tmp.cpp
Last active November 19, 2017 11:48
cv::Mat img = cv::imread("toucan.jpg");
cv::resize(img, img, cv::Size(224, 224));
img.convertTo(img, CV_32F);
cv::subtract(img, cv::Scalar(104.0f, 117.0f, 123.0f), img);
cv::divide(img, cv::Scalar(127.5f, 127.5f, 127.5f), img);
std::vector<cv::Mat> channels(3);
cv::split(img, channels);
cv::Mat blob({1, 3, 224, 224}, CV_32F);
for (int i = 0; i < 3; ++i) {
cv::Mat dst(224, 224, CV_32F, blob.ptr<float>(0, i));