Skip to content

Commit

Permalink
Add MediaPipe face detection back camera model
Browse files Browse the repository at this point in the history
  • Loading branch information
ocastan committed Feb 10, 2021
1 parent 5af71b6 commit d2f8c9e
Show file tree
Hide file tree
Showing 6 changed files with 1,868 additions and 312 deletions.
101 changes: 89 additions & 12 deletions Anchors.ipynb
Expand Up @@ -6,12 +6,24 @@
"source": [
"# Create anchor boxes\n",
"\n",
"This is the **SsdAnchorsCalculator** stage from the MediaPipe graph. It computes a list of anchor boxes. This only needs to be done once, so we will store these anchors into a lookup table."
"This is the **SsdAnchorsCalculator** stage from the MediaPipe graph. It computes a list of anchor boxes. This only needs to be done once, so we will store these anchors into a lookup table.\n",
"\n",
"\n",
"Using conda environnement:\n",
"```\n",
"conda create -c pytorch -c conda-forge -n BlazeConv 'pytorch=1.6' jupyter opencv matplotlib\n",
"```\n",
"```\n",
"conda activate BlazeConv\n",
"```\n",
"```\n",
"pip install tflite\n",
"```"
]
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -29,7 +41,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -49,6 +61,35 @@
"}"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"These are the options from [face_detection_back_mobile_gpu.pbtxt](https://github.com/google/mediapipe/blob/master/mediapipe/graphs/face_detection/face_detection_back_mobile_gpu.pbtxt)."
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"anchor_back_options = {\n",
" \"num_layers\": 4,\n",
" \"min_scale\": 0.15625,\n",
" \"max_scale\": 0.75,\n",
" \"input_size_height\": 256,\n",
" \"input_size_width\": 256,\n",
" \"anchor_offset_x\": 0.5,\n",
" \"anchor_offset_y\": 0.5,\n",
" \"strides\": [16, 32, 32, 32],\n",
" \"aspect_ratios\": [1.0],\n",
" \"reduce_boxes_in_lowest_layer\": False,\n",
" \"interpolated_scale_aspect_ratio\": 1.0,\n",
" \"fixed_anchor_size\": True,\n",
"}"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -58,7 +99,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -142,13 +183,17 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"anchors = generate_anchors(anchor_options)\n",
"\n",
"assert len(anchors) == 896"
"assert len(anchors) == 896\n",
"\n",
"anchors_back = generate_anchors(anchor_back_options)\n",
"\n",
"assert len(anchors_back) == 896\n"
]
},
{
Expand All @@ -160,8 +205,10 @@
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"execution_count": 8,
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
Expand All @@ -178,7 +225,7 @@
" [0.28125, 0.03125, 1.0, 1.0]]"
]
},
"execution_count": 5,
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -187,6 +234,35 @@
"anchors[:10]"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[[0.03125, 0.03125, 1.0, 1.0],\n",
" [0.03125, 0.03125, 1.0, 1.0],\n",
" [0.09375, 0.03125, 1.0, 1.0],\n",
" [0.09375, 0.03125, 1.0, 1.0],\n",
" [0.15625, 0.03125, 1.0, 1.0],\n",
" [0.15625, 0.03125, 1.0, 1.0],\n",
" [0.21875, 0.03125, 1.0, 1.0],\n",
" [0.21875, 0.03125, 1.0, 1.0],\n",
" [0.28125, 0.03125, 1.0, 1.0],\n",
" [0.28125, 0.03125, 1.0, 1.0]]"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"anchors_back[:10]"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -282,11 +358,12 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"np.save(\"anchors.npy\", anchors)"
"np.save(\"anchors.npy\", anchors)\n",
"np.save(\"anchorsback.npy\", anchors_back)"
]
},
{
Expand All @@ -313,7 +390,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.0"
"version": "3.8.5"
}
},
"nbformat": 4,
Expand Down

0 comments on commit d2f8c9e

Please sign in to comment.