mirror of
https://github.com/serengil/deepface.git
synced 2025-06-05 19:15:23 +00:00
init
This commit is contained in:
commit
850baea44a
26
.github/workflows/pythonpublish.yml
vendored
Normal file
26
.github/workflows/pythonpublish.yml
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
name: Upload Python Package
|
||||
|
||||
on:
|
||||
release:
|
||||
types: [created]
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v1
|
||||
with:
|
||||
python-version: '3.x'
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install setuptools wheel twine
|
||||
- name: Build and publish
|
||||
env:
|
||||
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
|
||||
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
|
||||
run: |
|
||||
python setup.py sdist bdist_wheel
|
||||
twine upload dist/*
|
14
.gitignore
vendored
Normal file
14
.gitignore
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
__pycache__/*
|
||||
basemodels/__pycache__/*
|
||||
configurations/__pycache__/*
|
||||
build/
|
||||
dist/
|
||||
Pipfile
|
||||
Pipfile.lock
|
||||
.mypy_cache/
|
||||
.vscode/
|
||||
.idea/
|
||||
deepface.egg-info/
|
||||
deepface/__pycache__/*
|
||||
deepface/commons/__pycache__/*
|
||||
deepface/basemodels/__pycache__/*
|
21
LICENSE
Normal file
21
LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2019 Sefik Ilkin Serengil
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
91
README.md
Normal file
91
README.md
Normal file
@ -0,0 +1,91 @@
|
||||
# deepface
|
||||
|
||||
**deepface** is a lightweight facial recognition framework. You can verify faces with just a few lines of codes.
|
||||
|
||||
```python
|
||||
from deepface import DeepFace
|
||||
result = DeepFace.verify("img1.jpg", "img2.jpg")
|
||||
```
|
||||
|
||||
# Face recognition models
|
||||
|
||||
Face recognition can be handled by different models. Currently, [`VGG-Face`](https://sefiks.com/2018/08/06/deep-face-recognition-with-keras/) , [`Facenet`](https://sefiks.com/2018/09/03/face-recognition-with-facenet-in-keras/) and [`OpenFace`](https://sefiks.com/2019/07/21/face-recognition-with-openface-in-keras/) models are supported in deepface. The default configuration verifies faces with **VGG-Face** model. You can set the base model while verification as illustared below. Accuracy and speed show difference based on the performing model.
|
||||
|
||||
```python
|
||||
vggface_result = DeepFace.verify("img1.jpg", "img2.jpg")
|
||||
#vggface_result = DeepFace.verify("img1.jpg", "img2.jpg", model_name = "VGG-Face")
|
||||
facenet_result = DeepFace.verify("img1.jpg", "img2.jpg", model_name = "Facenet")
|
||||
openface_result = DeepFace.verify("img1.jpg", "img2.jpg", model_name = "OpenFace")
|
||||
```
|
||||
|
||||
# Similarity
|
||||
|
||||
These models actually find the vector embeddings of faces. Decision of verification is based on the distance between vectors. Distance could be found by different metrics such as [`Cosine Similarity`](https://sefiks.com/2018/08/13/cosine-similarity-in-machine-learning/), Euclidean Distance and L2 form. The default configuration finds the **cosine similarity**. You can alternatively set the similarity metric while verification as demostratred below.
|
||||
|
||||
```python
|
||||
result = DeepFace.verify("img1.jpg", "img2.jpg", model_name = "VGG-Face", distance_metric = "cosine")
|
||||
result = DeepFace.verify("img1.jpg", "img2.jpg", model_name = "VGG-Face", distance_metric = "euclidean")
|
||||
result = DeepFace.verify("img1.jpg", "img2.jpg", model_name = "VGG-Face", distance_metric = "euclidean_l2")
|
||||
```
|
||||
|
||||
# Verification
|
||||
|
||||
Verification function returns a tuple including boolean verification result, distance between two faces and max threshold to identify.
|
||||
|
||||
```
|
||||
(True, 0.281734, 0.30)
|
||||
```
|
||||
|
||||
You can just check the verification result to decide that two images are same person or not. Thresholds for distance metrics are already tuned in the framework for face recognition models and distance metrics.
|
||||
|
||||
```python
|
||||
verified = result[0] #returns True if images are same person's face
|
||||
```
|
||||
|
||||
Instead of using pre-tuned threshold values, you can alternatively check the distance by yourself.
|
||||
|
||||
```python
|
||||
distance = result[1] #the less the better
|
||||
|
||||
threshold = 0.30 #threshold for VGG-Face and Cosine Similarity
|
||||
|
||||
if distance < threshold:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
```
|
||||
|
||||
# Installation
|
||||
|
||||
The easiest way to install deepface is to download it from PyPI.
|
||||
|
||||
```
|
||||
pip install deepface
|
||||
```
|
||||
|
||||
Alternatively, you can directly download the source code from this repository. GitHub repo might be newer than the PyPI version.
|
||||
|
||||
```
|
||||
git clone https://github.com/serengil/chefboost.git
|
||||
cd chefboost
|
||||
pip install -e .
|
||||
```
|
||||
|
||||
Initial tests are run for Python 3.5.5 on Windows 10 but this is an OS-independent framework. Even though pip handles to install dependent libraries, the framework basically needs the following dependencies. You might need the following library requirements if you install the source code from github.
|
||||
|
||||
```
|
||||
pip install numpy==1.14.0
|
||||
pip install matplotlib==2.2.2
|
||||
pip install gdown==3.10.1
|
||||
pip install opencv-python==3.4.4
|
||||
pip install tensorflow==1.9.0
|
||||
pip install keras==2.2.0
|
||||
```
|
||||
|
||||
# Support
|
||||
|
||||
There are many ways to support a project - starring⭐️ the GitHub repos is just one.
|
||||
|
||||
# Licence
|
||||
|
||||
Chefboost is licensed under the MIT License - see [`LICENSE`](https://github.com/serengil/deepface/blob/master/LICENSE) for more details.
|
111
deepface/DeepFace.py
Normal file
111
deepface/DeepFace.py
Normal file
@ -0,0 +1,111 @@
|
||||
import matplotlib.pyplot as plt
|
||||
from keras.preprocessing import image
|
||||
import warnings
|
||||
warnings.filterwarnings("ignore")
|
||||
import time
|
||||
import os
|
||||
|
||||
from deepface.basemodels import VGGFace, OpenFace, Facenet
|
||||
from deepface.commons import functions, distance as dst
|
||||
|
||||
def verify(img1_path, img2_path
|
||||
, model_name ='VGG-Face', distance_metric = 'cosine'):
|
||||
|
||||
tic = time.time()
|
||||
|
||||
if os.path.isfile(img1_path) != True:
|
||||
raise ValueError("Confirm that ",img1_path," exists")
|
||||
|
||||
if os.path.isfile(img2_path) != True:
|
||||
raise ValueError("Confirm that ",img2_path," exists")
|
||||
|
||||
#-------------------------
|
||||
|
||||
#print("Face verification will be applied on ",model_name," model and ",distance_metric," metric")
|
||||
|
||||
functions.validateInputs(model_name, distance_metric)
|
||||
|
||||
#-------------------------
|
||||
|
||||
#tuned thresholds for model and metric pair
|
||||
threshold = functions.findThreshold(model_name, distance_metric)
|
||||
|
||||
#-------------------------
|
||||
|
||||
if model_name == 'VGG-Face':
|
||||
model = VGGFace.loadModel()
|
||||
input_shape = (224, 224)
|
||||
|
||||
elif model_name == 'OpenFace':
|
||||
model = OpenFace.loadModel()
|
||||
input_shape = (96, 96)
|
||||
|
||||
elif model_name == 'Facenet':
|
||||
model = Facenet.loadModel()
|
||||
input_shape = (160, 160)
|
||||
|
||||
#-------------------------
|
||||
#crop face
|
||||
|
||||
img1 = functions.detectFace(img1_path, input_shape)
|
||||
img2 = functions.detectFace(img2_path, input_shape)
|
||||
|
||||
#-------------------------
|
||||
#TO-DO: Apply face alignment here. Experiments show that aligment increases accuracy 1%.
|
||||
|
||||
#-------------------------
|
||||
#find embeddings
|
||||
|
||||
img1_representation = model.predict(img1)[0,:]
|
||||
img2_representation = model.predict(img2)[0,:]
|
||||
|
||||
#-------------------------
|
||||
#find distances between embeddings
|
||||
|
||||
if distance_metric == 'cosine':
|
||||
distance = dst.findCosineDistance(img1_representation, img2_representation)
|
||||
elif distance_metric == 'euclidean':
|
||||
distance = dst.findEuclideanDistance(img1_representation, img2_representation)
|
||||
elif distance_metric == 'euclidean_l2':
|
||||
distance = dst.findEuclideanDistance(dst.l2_normalize(img1_representation), dst.l2_normalize(img2_representation))
|
||||
|
||||
#-------------------------
|
||||
#decision
|
||||
|
||||
if distance <= threshold:
|
||||
identified = True
|
||||
else:
|
||||
identified = False
|
||||
|
||||
#-------------------------
|
||||
|
||||
plot = False
|
||||
|
||||
if plot:
|
||||
label = "Distance is "+str(round(distance, 2))
|
||||
|
||||
fig = plt.figure()
|
||||
fig.add_subplot(1,2, 1)
|
||||
plt.imshow(img1[0][:, :, ::-1])
|
||||
plt.xticks([]); plt.yticks([])
|
||||
fig.add_subplot(1,2, 2)
|
||||
plt.imshow(img2[0][:, :, ::-1])
|
||||
plt.xticks([]); plt.yticks([])
|
||||
fig.suptitle(label, fontsize=17)
|
||||
plt.show(block=True)
|
||||
|
||||
#-------------------------
|
||||
|
||||
toc = time.time()
|
||||
|
||||
#print("identification lasts ",toc-tic," seconds")
|
||||
|
||||
#Return a tuple. First item is the identification result based on tuned threshold.
|
||||
#Second item is the threshold. You might want to customize this threshold to identify faces.
|
||||
return (identified, distance, threshold)
|
||||
|
||||
#---------------------------
|
||||
|
||||
functions.initializeFolder()
|
||||
|
||||
#---------------------------
|
0
deepface/__init__.py
Normal file
0
deepface/__init__.py
Normal file
553
deepface/basemodels/Facenet.py
Normal file
553
deepface/basemodels/Facenet.py
Normal file
@ -0,0 +1,553 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
import gdown
|
||||
from functools import partial
|
||||
|
||||
from keras.models import Model
|
||||
from keras.layers import Activation
|
||||
from keras.layers import BatchNormalization
|
||||
from keras.layers import Concatenate
|
||||
from keras.layers import Conv2D
|
||||
from keras.layers import Dense
|
||||
from keras.layers import Dropout
|
||||
from keras.layers import GlobalAveragePooling2D
|
||||
from keras.layers import Input
|
||||
from keras.layers import Lambda
|
||||
from keras.layers import MaxPooling2D
|
||||
from keras.layers import add
|
||||
from keras import backend as K
|
||||
|
||||
def scaling(x, scale):
|
||||
return x * scale
|
||||
|
||||
def InceptionResNetV2():
|
||||
|
||||
inputs = Input(shape=(160, 160, 3))
|
||||
x = Conv2D(32, 3, strides=2, padding='valid', use_bias=False, name= 'Conv2d_1a_3x3') (inputs)
|
||||
x = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Conv2d_1a_3x3_BatchNorm')(x)
|
||||
x = Activation('relu', name='Conv2d_1a_3x3_Activation')(x)
|
||||
x = Conv2D(32, 3, strides=1, padding='valid', use_bias=False, name= 'Conv2d_2a_3x3') (x)
|
||||
x = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Conv2d_2a_3x3_BatchNorm')(x)
|
||||
x = Activation('relu', name='Conv2d_2a_3x3_Activation')(x)
|
||||
x = Conv2D(64, 3, strides=1, padding='same', use_bias=False, name= 'Conv2d_2b_3x3') (x)
|
||||
x = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Conv2d_2b_3x3_BatchNorm')(x)
|
||||
x = Activation('relu', name='Conv2d_2b_3x3_Activation')(x)
|
||||
x = MaxPooling2D(3, strides=2, name='MaxPool_3a_3x3')(x)
|
||||
x = Conv2D(80, 1, strides=1, padding='valid', use_bias=False, name= 'Conv2d_3b_1x1') (x)
|
||||
x = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Conv2d_3b_1x1_BatchNorm')(x)
|
||||
x = Activation('relu', name='Conv2d_3b_1x1_Activation')(x)
|
||||
x = Conv2D(192, 3, strides=1, padding='valid', use_bias=False, name= 'Conv2d_4a_3x3') (x)
|
||||
x = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Conv2d_4a_3x3_BatchNorm')(x)
|
||||
x = Activation('relu', name='Conv2d_4a_3x3_Activation')(x)
|
||||
x = Conv2D(256, 3, strides=2, padding='valid', use_bias=False, name= 'Conv2d_4b_3x3') (x)
|
||||
x = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Conv2d_4b_3x3_BatchNorm')(x)
|
||||
x = Activation('relu', name='Conv2d_4b_3x3_Activation')(x)
|
||||
|
||||
# 5x Block35 (Inception-ResNet-A block):
|
||||
branch_0 = Conv2D(32, 1, strides=1, padding='same', use_bias=False, name= 'Block35_1_Branch_0_Conv2d_1x1') (x)
|
||||
branch_0 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block35_1_Branch_0_Conv2d_1x1_BatchNorm')(branch_0)
|
||||
branch_0 = Activation('relu', name='Block35_1_Branch_0_Conv2d_1x1_Activation')(branch_0)
|
||||
branch_1 = Conv2D(32, 1, strides=1, padding='same', use_bias=False, name= 'Block35_1_Branch_1_Conv2d_0a_1x1') (x)
|
||||
branch_1 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block35_1_Branch_1_Conv2d_0a_1x1_BatchNorm')(branch_1)
|
||||
branch_1 = Activation('relu', name='Block35_1_Branch_1_Conv2d_0a_1x1_Activation')(branch_1)
|
||||
branch_1 = Conv2D(32, 3, strides=1, padding='same', use_bias=False, name= 'Block35_1_Branch_1_Conv2d_0b_3x3') (branch_1)
|
||||
branch_1 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block35_1_Branch_1_Conv2d_0b_3x3_BatchNorm')(branch_1)
|
||||
branch_1 = Activation('relu', name='Block35_1_Branch_1_Conv2d_0b_3x3_Activation')(branch_1)
|
||||
branch_2 = Conv2D(32, 1, strides=1, padding='same', use_bias=False, name= 'Block35_1_Branch_2_Conv2d_0a_1x1') (x)
|
||||
branch_2 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block35_1_Branch_2_Conv2d_0a_1x1_BatchNorm')(branch_2)
|
||||
branch_2 = Activation('relu', name='Block35_1_Branch_2_Conv2d_0a_1x1_Activation')(branch_2)
|
||||
branch_2 = Conv2D(32, 3, strides=1, padding='same', use_bias=False, name= 'Block35_1_Branch_2_Conv2d_0b_3x3') (branch_2)
|
||||
branch_2 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block35_1_Branch_2_Conv2d_0b_3x3_BatchNorm')(branch_2)
|
||||
branch_2 = Activation('relu', name='Block35_1_Branch_2_Conv2d_0b_3x3_Activation')(branch_2)
|
||||
branch_2 = Conv2D(32, 3, strides=1, padding='same', use_bias=False, name= 'Block35_1_Branch_2_Conv2d_0c_3x3') (branch_2)
|
||||
branch_2 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block35_1_Branch_2_Conv2d_0c_3x3_BatchNorm')(branch_2)
|
||||
branch_2 = Activation('relu', name='Block35_1_Branch_2_Conv2d_0c_3x3_Activation')(branch_2)
|
||||
branches = [branch_0, branch_1, branch_2]
|
||||
mixed = Concatenate(axis=3, name='Block35_1_Concatenate')(branches)
|
||||
up = Conv2D(256, 1, strides=1, padding='same', use_bias=True, name= 'Block35_1_Conv2d_1x1') (mixed)
|
||||
up = Lambda(scaling, output_shape=K.int_shape(up)[1:], arguments={'scale': 0.17})(up)
|
||||
x = add([x, up])
|
||||
x = Activation('relu', name='Block35_1_Activation')(x)
|
||||
|
||||
branch_0 = Conv2D(32, 1, strides=1, padding='same', use_bias=False, name= 'Block35_2_Branch_0_Conv2d_1x1') (x)
|
||||
branch_0 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block35_2_Branch_0_Conv2d_1x1_BatchNorm')(branch_0)
|
||||
branch_0 = Activation('relu', name='Block35_2_Branch_0_Conv2d_1x1_Activation')(branch_0)
|
||||
branch_1 = Conv2D(32, 1, strides=1, padding='same', use_bias=False, name= 'Block35_2_Branch_1_Conv2d_0a_1x1') (x)
|
||||
branch_1 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block35_2_Branch_1_Conv2d_0a_1x1_BatchNorm')(branch_1)
|
||||
branch_1 = Activation('relu', name='Block35_2_Branch_1_Conv2d_0a_1x1_Activation')(branch_1)
|
||||
branch_1 = Conv2D(32, 3, strides=1, padding='same', use_bias=False, name= 'Block35_2_Branch_1_Conv2d_0b_3x3') (branch_1)
|
||||
branch_1 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block35_2_Branch_1_Conv2d_0b_3x3_BatchNorm')(branch_1)
|
||||
branch_1 = Activation('relu', name='Block35_2_Branch_1_Conv2d_0b_3x3_Activation')(branch_1)
|
||||
branch_2 = Conv2D(32, 1, strides=1, padding='same', use_bias=False, name= 'Block35_2_Branch_2_Conv2d_0a_1x1') (x)
|
||||
branch_2 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block35_2_Branch_2_Conv2d_0a_1x1_BatchNorm')(branch_2)
|
||||
branch_2 = Activation('relu', name='Block35_2_Branch_2_Conv2d_0a_1x1_Activation')(branch_2)
|
||||
branch_2 = Conv2D(32, 3, strides=1, padding='same', use_bias=False, name= 'Block35_2_Branch_2_Conv2d_0b_3x3') (branch_2)
|
||||
branch_2 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block35_2_Branch_2_Conv2d_0b_3x3_BatchNorm')(branch_2)
|
||||
branch_2 = Activation('relu', name='Block35_2_Branch_2_Conv2d_0b_3x3_Activation')(branch_2)
|
||||
branch_2 = Conv2D(32, 3, strides=1, padding='same', use_bias=False, name= 'Block35_2_Branch_2_Conv2d_0c_3x3') (branch_2)
|
||||
branch_2 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block35_2_Branch_2_Conv2d_0c_3x3_BatchNorm')(branch_2)
|
||||
branch_2 = Activation('relu', name='Block35_2_Branch_2_Conv2d_0c_3x3_Activation')(branch_2)
|
||||
branches = [branch_0, branch_1, branch_2]
|
||||
mixed = Concatenate(axis=3, name='Block35_2_Concatenate')(branches)
|
||||
up = Conv2D(256, 1, strides=1, padding='same', use_bias=True, name= 'Block35_2_Conv2d_1x1') (mixed)
|
||||
up = Lambda(scaling, output_shape=K.int_shape(up)[1:], arguments={'scale': 0.17})(up)
|
||||
x = add([x, up])
|
||||
x = Activation('relu', name='Block35_2_Activation')(x)
|
||||
|
||||
branch_0 = Conv2D(32, 1, strides=1, padding='same', use_bias=False, name= 'Block35_3_Branch_0_Conv2d_1x1') (x)
|
||||
branch_0 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block35_3_Branch_0_Conv2d_1x1_BatchNorm')(branch_0)
|
||||
branch_0 = Activation('relu', name='Block35_3_Branch_0_Conv2d_1x1_Activation')(branch_0)
|
||||
branch_1 = Conv2D(32, 1, strides=1, padding='same', use_bias=False, name= 'Block35_3_Branch_1_Conv2d_0a_1x1') (x)
|
||||
branch_1 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block35_3_Branch_1_Conv2d_0a_1x1_BatchNorm')(branch_1)
|
||||
branch_1 = Activation('relu', name='Block35_3_Branch_1_Conv2d_0a_1x1_Activation')(branch_1)
|
||||
branch_1 = Conv2D(32, 3, strides=1, padding='same', use_bias=False, name= 'Block35_3_Branch_1_Conv2d_0b_3x3') (branch_1)
|
||||
branch_1 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block35_3_Branch_1_Conv2d_0b_3x3_BatchNorm')(branch_1)
|
||||
branch_1 = Activation('relu', name='Block35_3_Branch_1_Conv2d_0b_3x3_Activation')(branch_1)
|
||||
branch_2 = Conv2D(32, 1, strides=1, padding='same', use_bias=False, name= 'Block35_3_Branch_2_Conv2d_0a_1x1') (x)
|
||||
branch_2 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block35_3_Branch_2_Conv2d_0a_1x1_BatchNorm')(branch_2)
|
||||
branch_2 = Activation('relu', name='Block35_3_Branch_2_Conv2d_0a_1x1_Activation')(branch_2)
|
||||
branch_2 = Conv2D(32, 3, strides=1, padding='same', use_bias=False, name= 'Block35_3_Branch_2_Conv2d_0b_3x3') (branch_2)
|
||||
branch_2 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block35_3_Branch_2_Conv2d_0b_3x3_BatchNorm')(branch_2)
|
||||
branch_2 = Activation('relu', name='Block35_3_Branch_2_Conv2d_0b_3x3_Activation')(branch_2)
|
||||
branch_2 = Conv2D(32, 3, strides=1, padding='same', use_bias=False, name= 'Block35_3_Branch_2_Conv2d_0c_3x3') (branch_2)
|
||||
branch_2 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block35_3_Branch_2_Conv2d_0c_3x3_BatchNorm')(branch_2)
|
||||
branch_2 = Activation('relu', name='Block35_3_Branch_2_Conv2d_0c_3x3_Activation')(branch_2)
|
||||
branches = [branch_0, branch_1, branch_2]
|
||||
mixed = Concatenate(axis=3, name='Block35_3_Concatenate')(branches)
|
||||
up = Conv2D(256, 1, strides=1, padding='same', use_bias=True, name= 'Block35_3_Conv2d_1x1') (mixed)
|
||||
up = Lambda(scaling, output_shape=K.int_shape(up)[1:], arguments={'scale': 0.17})(up)
|
||||
x = add([x, up])
|
||||
x = Activation('relu', name='Block35_3_Activation')(x)
|
||||
|
||||
branch_0 = Conv2D(32, 1, strides=1, padding='same', use_bias=False, name= 'Block35_4_Branch_0_Conv2d_1x1') (x)
|
||||
branch_0 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block35_4_Branch_0_Conv2d_1x1_BatchNorm')(branch_0)
|
||||
branch_0 = Activation('relu', name='Block35_4_Branch_0_Conv2d_1x1_Activation')(branch_0)
|
||||
branch_1 = Conv2D(32, 1, strides=1, padding='same', use_bias=False, name= 'Block35_4_Branch_1_Conv2d_0a_1x1') (x)
|
||||
branch_1 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block35_4_Branch_1_Conv2d_0a_1x1_BatchNorm')(branch_1)
|
||||
branch_1 = Activation('relu', name='Block35_4_Branch_1_Conv2d_0a_1x1_Activation')(branch_1)
|
||||
branch_1 = Conv2D(32, 3, strides=1, padding='same', use_bias=False, name= 'Block35_4_Branch_1_Conv2d_0b_3x3') (branch_1)
|
||||
branch_1 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block35_4_Branch_1_Conv2d_0b_3x3_BatchNorm')(branch_1)
|
||||
branch_1 = Activation('relu', name='Block35_4_Branch_1_Conv2d_0b_3x3_Activation')(branch_1)
|
||||
branch_2 = Conv2D(32, 1, strides=1, padding='same', use_bias=False, name= 'Block35_4_Branch_2_Conv2d_0a_1x1') (x)
|
||||
branch_2 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block35_4_Branch_2_Conv2d_0a_1x1_BatchNorm')(branch_2)
|
||||
branch_2 = Activation('relu', name='Block35_4_Branch_2_Conv2d_0a_1x1_Activation')(branch_2)
|
||||
branch_2 = Conv2D(32, 3, strides=1, padding='same', use_bias=False, name= 'Block35_4_Branch_2_Conv2d_0b_3x3') (branch_2)
|
||||
branch_2 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block35_4_Branch_2_Conv2d_0b_3x3_BatchNorm')(branch_2)
|
||||
branch_2 = Activation('relu', name='Block35_4_Branch_2_Conv2d_0b_3x3_Activation')(branch_2)
|
||||
branch_2 = Conv2D(32, 3, strides=1, padding='same', use_bias=False, name= 'Block35_4_Branch_2_Conv2d_0c_3x3') (branch_2)
|
||||
branch_2 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block35_4_Branch_2_Conv2d_0c_3x3_BatchNorm')(branch_2)
|
||||
branch_2 = Activation('relu', name='Block35_4_Branch_2_Conv2d_0c_3x3_Activation')(branch_2)
|
||||
branches = [branch_0, branch_1, branch_2]
|
||||
mixed = Concatenate(axis=3, name='Block35_4_Concatenate')(branches)
|
||||
up = Conv2D(256, 1, strides=1, padding='same', use_bias=True, name= 'Block35_4_Conv2d_1x1') (mixed)
|
||||
up = Lambda(scaling, output_shape=K.int_shape(up)[1:], arguments={'scale': 0.17})(up)
|
||||
x = add([x, up])
|
||||
x = Activation('relu', name='Block35_4_Activation')(x)
|
||||
|
||||
branch_0 = Conv2D(32, 1, strides=1, padding='same', use_bias=False, name= 'Block35_5_Branch_0_Conv2d_1x1') (x)
|
||||
branch_0 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block35_5_Branch_0_Conv2d_1x1_BatchNorm')(branch_0)
|
||||
branch_0 = Activation('relu', name='Block35_5_Branch_0_Conv2d_1x1_Activation')(branch_0)
|
||||
branch_1 = Conv2D(32, 1, strides=1, padding='same', use_bias=False, name= 'Block35_5_Branch_1_Conv2d_0a_1x1') (x)
|
||||
branch_1 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block35_5_Branch_1_Conv2d_0a_1x1_BatchNorm')(branch_1)
|
||||
branch_1 = Activation('relu', name='Block35_5_Branch_1_Conv2d_0a_1x1_Activation')(branch_1)
|
||||
branch_1 = Conv2D(32, 3, strides=1, padding='same', use_bias=False, name= 'Block35_5_Branch_1_Conv2d_0b_3x3') (branch_1)
|
||||
branch_1 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block35_5_Branch_1_Conv2d_0b_3x3_BatchNorm')(branch_1)
|
||||
branch_1 = Activation('relu', name='Block35_5_Branch_1_Conv2d_0b_3x3_Activation')(branch_1)
|
||||
branch_2 = Conv2D(32, 1, strides=1, padding='same', use_bias=False, name= 'Block35_5_Branch_2_Conv2d_0a_1x1') (x)
|
||||
branch_2 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block35_5_Branch_2_Conv2d_0a_1x1_BatchNorm')(branch_2)
|
||||
branch_2 = Activation('relu', name='Block35_5_Branch_2_Conv2d_0a_1x1_Activation')(branch_2)
|
||||
branch_2 = Conv2D(32, 3, strides=1, padding='same', use_bias=False, name= 'Block35_5_Branch_2_Conv2d_0b_3x3') (branch_2)
|
||||
branch_2 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block35_5_Branch_2_Conv2d_0b_3x3_BatchNorm')(branch_2)
|
||||
branch_2 = Activation('relu', name='Block35_5_Branch_2_Conv2d_0b_3x3_Activation')(branch_2)
|
||||
branch_2 = Conv2D(32, 3, strides=1, padding='same', use_bias=False, name= 'Block35_5_Branch_2_Conv2d_0c_3x3') (branch_2)
|
||||
branch_2 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block35_5_Branch_2_Conv2d_0c_3x3_BatchNorm')(branch_2)
|
||||
branch_2 = Activation('relu', name='Block35_5_Branch_2_Conv2d_0c_3x3_Activation')(branch_2)
|
||||
branches = [branch_0, branch_1, branch_2]
|
||||
mixed = Concatenate(axis=3, name='Block35_5_Concatenate')(branches)
|
||||
up = Conv2D(256, 1, strides=1, padding='same', use_bias=True, name= 'Block35_5_Conv2d_1x1') (mixed)
|
||||
up = Lambda(scaling, output_shape=K.int_shape(up)[1:], arguments={'scale': 0.17})(up)
|
||||
x = add([x, up])
|
||||
x = Activation('relu', name='Block35_5_Activation')(x)
|
||||
|
||||
# Mixed 6a (Reduction-A block):
|
||||
branch_0 = Conv2D(384, 3, strides=2, padding='valid', use_bias=False, name= 'Mixed_6a_Branch_0_Conv2d_1a_3x3') (x)
|
||||
branch_0 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Mixed_6a_Branch_0_Conv2d_1a_3x3_BatchNorm')(branch_0)
|
||||
branch_0 = Activation('relu', name='Mixed_6a_Branch_0_Conv2d_1a_3x3_Activation')(branch_0)
|
||||
branch_1 = Conv2D(192, 1, strides=1, padding='same', use_bias=False, name= 'Mixed_6a_Branch_1_Conv2d_0a_1x1') (x)
|
||||
branch_1 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Mixed_6a_Branch_1_Conv2d_0a_1x1_BatchNorm')(branch_1)
|
||||
branch_1 = Activation('relu', name='Mixed_6a_Branch_1_Conv2d_0a_1x1_Activation')(branch_1)
|
||||
branch_1 = Conv2D(192, 3, strides=1, padding='same', use_bias=False, name= 'Mixed_6a_Branch_1_Conv2d_0b_3x3') (branch_1)
|
||||
branch_1 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Mixed_6a_Branch_1_Conv2d_0b_3x3_BatchNorm')(branch_1)
|
||||
branch_1 = Activation('relu', name='Mixed_6a_Branch_1_Conv2d_0b_3x3_Activation')(branch_1)
|
||||
branch_1 = Conv2D(256, 3, strides=2, padding='valid', use_bias=False, name= 'Mixed_6a_Branch_1_Conv2d_1a_3x3') (branch_1)
|
||||
branch_1 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Mixed_6a_Branch_1_Conv2d_1a_3x3_BatchNorm')(branch_1)
|
||||
branch_1 = Activation('relu', name='Mixed_6a_Branch_1_Conv2d_1a_3x3_Activation')(branch_1)
|
||||
branch_pool = MaxPooling2D(3, strides=2, padding='valid', name='Mixed_6a_Branch_2_MaxPool_1a_3x3')(x)
|
||||
branches = [branch_0, branch_1, branch_pool]
|
||||
x = Concatenate(axis=3, name='Mixed_6a')(branches)
|
||||
|
||||
# 10x Block17 (Inception-ResNet-B block):
|
||||
branch_0 = Conv2D(128, 1, strides=1, padding='same', use_bias=False, name= 'Block17_1_Branch_0_Conv2d_1x1') (x)
|
||||
branch_0 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block17_1_Branch_0_Conv2d_1x1_BatchNorm')(branch_0)
|
||||
branch_0 = Activation('relu', name='Block17_1_Branch_0_Conv2d_1x1_Activation')(branch_0)
|
||||
branch_1 = Conv2D(128, 1, strides=1, padding='same', use_bias=False, name= 'Block17_1_Branch_1_Conv2d_0a_1x1') (x)
|
||||
branch_1 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block17_1_Branch_1_Conv2d_0a_1x1_BatchNorm')(branch_1)
|
||||
branch_1 = Activation('relu', name='Block17_1_Branch_1_Conv2d_0a_1x1_Activation')(branch_1)
|
||||
branch_1 = Conv2D(128, [1, 7], strides=1, padding='same', use_bias=False, name= 'Block17_1_Branch_1_Conv2d_0b_1x7') (branch_1)
|
||||
branch_1 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block17_1_Branch_1_Conv2d_0b_1x7_BatchNorm')(branch_1)
|
||||
branch_1 = Activation('relu', name='Block17_1_Branch_1_Conv2d_0b_1x7_Activation')(branch_1)
|
||||
branch_1 = Conv2D(128, [7, 1], strides=1, padding='same', use_bias=False, name= 'Block17_1_Branch_1_Conv2d_0c_7x1') (branch_1)
|
||||
branch_1 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block17_1_Branch_1_Conv2d_0c_7x1_BatchNorm')(branch_1)
|
||||
branch_1 = Activation('relu', name='Block17_1_Branch_1_Conv2d_0c_7x1_Activation')(branch_1)
|
||||
branches = [branch_0, branch_1]
|
||||
mixed = Concatenate(axis=3, name='Block17_1_Concatenate')(branches)
|
||||
up = Conv2D(896, 1, strides=1, padding='same', use_bias=True, name= 'Block17_1_Conv2d_1x1') (mixed)
|
||||
up = Lambda(scaling, output_shape=K.int_shape(up)[1:], arguments={'scale': 0.1})(up)
|
||||
x = add([x, up])
|
||||
x = Activation('relu', name='Block17_1_Activation')(x)
|
||||
|
||||
branch_0 = Conv2D(128, 1, strides=1, padding='same', use_bias=False, name= 'Block17_2_Branch_0_Conv2d_1x1') (x)
|
||||
branch_0 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block17_2_Branch_0_Conv2d_1x1_BatchNorm')(branch_0)
|
||||
branch_0 = Activation('relu', name='Block17_2_Branch_0_Conv2d_1x1_Activation')(branch_0)
|
||||
branch_1 = Conv2D(128, 1, strides=1, padding='same', use_bias=False, name= 'Block17_2_Branch_2_Conv2d_0a_1x1') (x)
|
||||
branch_1 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block17_2_Branch_2_Conv2d_0a_1x1_BatchNorm')(branch_1)
|
||||
branch_1 = Activation('relu', name='Block17_2_Branch_2_Conv2d_0a_1x1_Activation')(branch_1)
|
||||
branch_1 = Conv2D(128, [1, 7], strides=1, padding='same', use_bias=False, name= 'Block17_2_Branch_2_Conv2d_0b_1x7') (branch_1)
|
||||
branch_1 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block17_2_Branch_2_Conv2d_0b_1x7_BatchNorm')(branch_1)
|
||||
branch_1 = Activation('relu', name='Block17_2_Branch_2_Conv2d_0b_1x7_Activation')(branch_1)
|
||||
branch_1 = Conv2D(128, [7, 1], strides=1, padding='same', use_bias=False, name= 'Block17_2_Branch_2_Conv2d_0c_7x1') (branch_1)
|
||||
branch_1 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block17_2_Branch_2_Conv2d_0c_7x1_BatchNorm')(branch_1)
|
||||
branch_1 = Activation('relu', name='Block17_2_Branch_2_Conv2d_0c_7x1_Activation')(branch_1)
|
||||
branches = [branch_0, branch_1]
|
||||
mixed = Concatenate(axis=3, name='Block17_2_Concatenate')(branches)
|
||||
up = Conv2D(896, 1, strides=1, padding='same', use_bias=True, name= 'Block17_2_Conv2d_1x1') (mixed)
|
||||
up = Lambda(scaling, output_shape=K.int_shape(up)[1:], arguments={'scale': 0.1})(up)
|
||||
x = add([x, up])
|
||||
x = Activation('relu', name='Block17_2_Activation')(x)
|
||||
|
||||
branch_0 = Conv2D(128, 1, strides=1, padding='same', use_bias=False, name= 'Block17_3_Branch_0_Conv2d_1x1') (x)
|
||||
branch_0 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block17_3_Branch_0_Conv2d_1x1_BatchNorm')(branch_0)
|
||||
branch_0 = Activation('relu', name='Block17_3_Branch_0_Conv2d_1x1_Activation')(branch_0)
|
||||
branch_1 = Conv2D(128, 1, strides=1, padding='same', use_bias=False, name= 'Block17_3_Branch_3_Conv2d_0a_1x1') (x)
|
||||
branch_1 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block17_3_Branch_3_Conv2d_0a_1x1_BatchNorm')(branch_1)
|
||||
branch_1 = Activation('relu', name='Block17_3_Branch_3_Conv2d_0a_1x1_Activation')(branch_1)
|
||||
branch_1 = Conv2D(128, [1, 7], strides=1, padding='same', use_bias=False, name= 'Block17_3_Branch_3_Conv2d_0b_1x7') (branch_1)
|
||||
branch_1 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block17_3_Branch_3_Conv2d_0b_1x7_BatchNorm')(branch_1)
|
||||
branch_1 = Activation('relu', name='Block17_3_Branch_3_Conv2d_0b_1x7_Activation')(branch_1)
|
||||
branch_1 = Conv2D(128, [7, 1], strides=1, padding='same', use_bias=False, name= 'Block17_3_Branch_3_Conv2d_0c_7x1') (branch_1)
|
||||
branch_1 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block17_3_Branch_3_Conv2d_0c_7x1_BatchNorm')(branch_1)
|
||||
branch_1 = Activation('relu', name='Block17_3_Branch_3_Conv2d_0c_7x1_Activation')(branch_1)
|
||||
branches = [branch_0, branch_1]
|
||||
mixed = Concatenate(axis=3, name='Block17_3_Concatenate')(branches)
|
||||
up = Conv2D(896, 1, strides=1, padding='same', use_bias=True, name= 'Block17_3_Conv2d_1x1') (mixed)
|
||||
up = Lambda(scaling, output_shape=K.int_shape(up)[1:], arguments={'scale': 0.1})(up)
|
||||
x = add([x, up])
|
||||
x = Activation('relu', name='Block17_3_Activation')(x)
|
||||
|
||||
branch_0 = Conv2D(128, 1, strides=1, padding='same', use_bias=False, name= 'Block17_4_Branch_0_Conv2d_1x1') (x)
|
||||
branch_0 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block17_4_Branch_0_Conv2d_1x1_BatchNorm')(branch_0)
|
||||
branch_0 = Activation('relu', name='Block17_4_Branch_0_Conv2d_1x1_Activation')(branch_0)
|
||||
branch_1 = Conv2D(128, 1, strides=1, padding='same', use_bias=False, name= 'Block17_4_Branch_4_Conv2d_0a_1x1') (x)
|
||||
branch_1 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block17_4_Branch_4_Conv2d_0a_1x1_BatchNorm')(branch_1)
|
||||
branch_1 = Activation('relu', name='Block17_4_Branch_4_Conv2d_0a_1x1_Activation')(branch_1)
|
||||
branch_1 = Conv2D(128, [1, 7], strides=1, padding='same', use_bias=False, name= 'Block17_4_Branch_4_Conv2d_0b_1x7') (branch_1)
|
||||
branch_1 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block17_4_Branch_4_Conv2d_0b_1x7_BatchNorm')(branch_1)
|
||||
branch_1 = Activation('relu', name='Block17_4_Branch_4_Conv2d_0b_1x7_Activation')(branch_1)
|
||||
branch_1 = Conv2D(128, [7, 1], strides=1, padding='same', use_bias=False, name= 'Block17_4_Branch_4_Conv2d_0c_7x1') (branch_1)
|
||||
branch_1 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block17_4_Branch_4_Conv2d_0c_7x1_BatchNorm')(branch_1)
|
||||
branch_1 = Activation('relu', name='Block17_4_Branch_4_Conv2d_0c_7x1_Activation')(branch_1)
|
||||
branches = [branch_0, branch_1]
|
||||
mixed = Concatenate(axis=3, name='Block17_4_Concatenate')(branches)
|
||||
up = Conv2D(896, 1, strides=1, padding='same', use_bias=True, name= 'Block17_4_Conv2d_1x1') (mixed)
|
||||
up = Lambda(scaling, output_shape=K.int_shape(up)[1:], arguments={'scale': 0.1})(up)
|
||||
x = add([x, up])
|
||||
x = Activation('relu', name='Block17_4_Activation')(x)
|
||||
|
||||
branch_0 = Conv2D(128, 1, strides=1, padding='same', use_bias=False, name= 'Block17_5_Branch_0_Conv2d_1x1') (x)
|
||||
branch_0 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block17_5_Branch_0_Conv2d_1x1_BatchNorm')(branch_0)
|
||||
branch_0 = Activation('relu', name='Block17_5_Branch_0_Conv2d_1x1_Activation')(branch_0)
|
||||
branch_1 = Conv2D(128, 1, strides=1, padding='same', use_bias=False, name= 'Block17_5_Branch_5_Conv2d_0a_1x1') (x)
|
||||
branch_1 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block17_5_Branch_5_Conv2d_0a_1x1_BatchNorm')(branch_1)
|
||||
branch_1 = Activation('relu', name='Block17_5_Branch_5_Conv2d_0a_1x1_Activation')(branch_1)
|
||||
branch_1 = Conv2D(128, [1, 7], strides=1, padding='same', use_bias=False, name= 'Block17_5_Branch_5_Conv2d_0b_1x7') (branch_1)
|
||||
branch_1 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block17_5_Branch_5_Conv2d_0b_1x7_BatchNorm')(branch_1)
|
||||
branch_1 = Activation('relu', name='Block17_5_Branch_5_Conv2d_0b_1x7_Activation')(branch_1)
|
||||
branch_1 = Conv2D(128, [7, 1], strides=1, padding='same', use_bias=False, name= 'Block17_5_Branch_5_Conv2d_0c_7x1') (branch_1)
|
||||
branch_1 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block17_5_Branch_5_Conv2d_0c_7x1_BatchNorm')(branch_1)
|
||||
branch_1 = Activation('relu', name='Block17_5_Branch_5_Conv2d_0c_7x1_Activation')(branch_1)
|
||||
branches = [branch_0, branch_1]
|
||||
mixed = Concatenate(axis=3, name='Block17_5_Concatenate')(branches)
|
||||
up = Conv2D(896, 1, strides=1, padding='same', use_bias=True, name= 'Block17_5_Conv2d_1x1') (mixed)
|
||||
up = Lambda(scaling, output_shape=K.int_shape(up)[1:], arguments={'scale': 0.1})(up)
|
||||
x = add([x, up])
|
||||
x = Activation('relu', name='Block17_5_Activation')(x)
|
||||
|
||||
branch_0 = Conv2D(128, 1, strides=1, padding='same', use_bias=False, name= 'Block17_6_Branch_0_Conv2d_1x1') (x)
|
||||
branch_0 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block17_6_Branch_0_Conv2d_1x1_BatchNorm')(branch_0)
|
||||
branch_0 = Activation('relu', name='Block17_6_Branch_0_Conv2d_1x1_Activation')(branch_0)
|
||||
branch_1 = Conv2D(128, 1, strides=1, padding='same', use_bias=False, name= 'Block17_6_Branch_6_Conv2d_0a_1x1') (x)
|
||||
branch_1 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block17_6_Branch_6_Conv2d_0a_1x1_BatchNorm')(branch_1)
|
||||
branch_1 = Activation('relu', name='Block17_6_Branch_6_Conv2d_0a_1x1_Activation')(branch_1)
|
||||
branch_1 = Conv2D(128, [1, 7], strides=1, padding='same', use_bias=False, name= 'Block17_6_Branch_6_Conv2d_0b_1x7') (branch_1)
|
||||
branch_1 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block17_6_Branch_6_Conv2d_0b_1x7_BatchNorm')(branch_1)
|
||||
branch_1 = Activation('relu', name='Block17_6_Branch_6_Conv2d_0b_1x7_Activation')(branch_1)
|
||||
branch_1 = Conv2D(128, [7, 1], strides=1, padding='same', use_bias=False, name= 'Block17_6_Branch_6_Conv2d_0c_7x1') (branch_1)
|
||||
branch_1 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block17_6_Branch_6_Conv2d_0c_7x1_BatchNorm')(branch_1)
|
||||
branch_1 = Activation('relu', name='Block17_6_Branch_6_Conv2d_0c_7x1_Activation')(branch_1)
|
||||
branches = [branch_0, branch_1]
|
||||
mixed = Concatenate(axis=3, name='Block17_6_Concatenate')(branches)
|
||||
up = Conv2D(896, 1, strides=1, padding='same', use_bias=True, name= 'Block17_6_Conv2d_1x1') (mixed)
|
||||
up = Lambda(scaling, output_shape=K.int_shape(up)[1:], arguments={'scale': 0.1})(up)
|
||||
x = add([x, up])
|
||||
x = Activation('relu', name='Block17_6_Activation')(x)
|
||||
|
||||
branch_0 = Conv2D(128, 1, strides=1, padding='same', use_bias=False, name= 'Block17_7_Branch_0_Conv2d_1x1') (x)
|
||||
branch_0 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block17_7_Branch_0_Conv2d_1x1_BatchNorm')(branch_0)
|
||||
branch_0 = Activation('relu', name='Block17_7_Branch_0_Conv2d_1x1_Activation')(branch_0)
|
||||
branch_1 = Conv2D(128, 1, strides=1, padding='same', use_bias=False, name= 'Block17_7_Branch_7_Conv2d_0a_1x1') (x)
|
||||
branch_1 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block17_7_Branch_7_Conv2d_0a_1x1_BatchNorm')(branch_1)
|
||||
branch_1 = Activation('relu', name='Block17_7_Branch_7_Conv2d_0a_1x1_Activation')(branch_1)
|
||||
branch_1 = Conv2D(128, [1, 7], strides=1, padding='same', use_bias=False, name= 'Block17_7_Branch_7_Conv2d_0b_1x7') (branch_1)
|
||||
branch_1 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block17_7_Branch_7_Conv2d_0b_1x7_BatchNorm')(branch_1)
|
||||
branch_1 = Activation('relu', name='Block17_7_Branch_7_Conv2d_0b_1x7_Activation')(branch_1)
|
||||
branch_1 = Conv2D(128, [7, 1], strides=1, padding='same', use_bias=False, name= 'Block17_7_Branch_7_Conv2d_0c_7x1') (branch_1)
|
||||
branch_1 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block17_7_Branch_7_Conv2d_0c_7x1_BatchNorm')(branch_1)
|
||||
branch_1 = Activation('relu', name='Block17_7_Branch_7_Conv2d_0c_7x1_Activation')(branch_1)
|
||||
branches = [branch_0, branch_1]
|
||||
mixed = Concatenate(axis=3, name='Block17_7_Concatenate')(branches)
|
||||
up = Conv2D(896, 1, strides=1, padding='same', use_bias=True, name= 'Block17_7_Conv2d_1x1') (mixed)
|
||||
up = Lambda(scaling, output_shape=K.int_shape(up)[1:], arguments={'scale': 0.1})(up)
|
||||
x = add([x, up])
|
||||
x = Activation('relu', name='Block17_7_Activation')(x)
|
||||
|
||||
branch_0 = Conv2D(128, 1, strides=1, padding='same', use_bias=False, name= 'Block17_8_Branch_0_Conv2d_1x1') (x)
|
||||
branch_0 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block17_8_Branch_0_Conv2d_1x1_BatchNorm')(branch_0)
|
||||
branch_0 = Activation('relu', name='Block17_8_Branch_0_Conv2d_1x1_Activation')(branch_0)
|
||||
branch_1 = Conv2D(128, 1, strides=1, padding='same', use_bias=False, name= 'Block17_8_Branch_8_Conv2d_0a_1x1') (x)
|
||||
branch_1 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block17_8_Branch_8_Conv2d_0a_1x1_BatchNorm')(branch_1)
|
||||
branch_1 = Activation('relu', name='Block17_8_Branch_8_Conv2d_0a_1x1_Activation')(branch_1)
|
||||
branch_1 = Conv2D(128, [1, 7], strides=1, padding='same', use_bias=False, name= 'Block17_8_Branch_8_Conv2d_0b_1x7') (branch_1)
|
||||
branch_1 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block17_8_Branch_8_Conv2d_0b_1x7_BatchNorm')(branch_1)
|
||||
branch_1 = Activation('relu', name='Block17_8_Branch_8_Conv2d_0b_1x7_Activation')(branch_1)
|
||||
branch_1 = Conv2D(128, [7, 1], strides=1, padding='same', use_bias=False, name= 'Block17_8_Branch_8_Conv2d_0c_7x1') (branch_1)
|
||||
branch_1 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block17_8_Branch_8_Conv2d_0c_7x1_BatchNorm')(branch_1)
|
||||
branch_1 = Activation('relu', name='Block17_8_Branch_8_Conv2d_0c_7x1_Activation')(branch_1)
|
||||
branches = [branch_0, branch_1]
|
||||
mixed = Concatenate(axis=3, name='Block17_8_Concatenate')(branches)
|
||||
up = Conv2D(896, 1, strides=1, padding='same', use_bias=True, name= 'Block17_8_Conv2d_1x1') (mixed)
|
||||
up = Lambda(scaling, output_shape=K.int_shape(up)[1:], arguments={'scale': 0.1})(up)
|
||||
x = add([x, up])
|
||||
x = Activation('relu', name='Block17_8_Activation')(x)
|
||||
|
||||
branch_0 = Conv2D(128, 1, strides=1, padding='same', use_bias=False, name= 'Block17_9_Branch_0_Conv2d_1x1') (x)
|
||||
branch_0 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block17_9_Branch_0_Conv2d_1x1_BatchNorm')(branch_0)
|
||||
branch_0 = Activation('relu', name='Block17_9_Branch_0_Conv2d_1x1_Activation')(branch_0)
|
||||
branch_1 = Conv2D(128, 1, strides=1, padding='same', use_bias=False, name= 'Block17_9_Branch_9_Conv2d_0a_1x1') (x)
|
||||
branch_1 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block17_9_Branch_9_Conv2d_0a_1x1_BatchNorm')(branch_1)
|
||||
branch_1 = Activation('relu', name='Block17_9_Branch_9_Conv2d_0a_1x1_Activation')(branch_1)
|
||||
branch_1 = Conv2D(128, [1, 7], strides=1, padding='same', use_bias=False, name= 'Block17_9_Branch_9_Conv2d_0b_1x7') (branch_1)
|
||||
branch_1 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block17_9_Branch_9_Conv2d_0b_1x7_BatchNorm')(branch_1)
|
||||
branch_1 = Activation('relu', name='Block17_9_Branch_9_Conv2d_0b_1x7_Activation')(branch_1)
|
||||
branch_1 = Conv2D(128, [7, 1], strides=1, padding='same', use_bias=False, name= 'Block17_9_Branch_9_Conv2d_0c_7x1') (branch_1)
|
||||
branch_1 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block17_9_Branch_9_Conv2d_0c_7x1_BatchNorm')(branch_1)
|
||||
branch_1 = Activation('relu', name='Block17_9_Branch_9_Conv2d_0c_7x1_Activation')(branch_1)
|
||||
branches = [branch_0, branch_1]
|
||||
mixed = Concatenate(axis=3, name='Block17_9_Concatenate')(branches)
|
||||
up = Conv2D(896, 1, strides=1, padding='same', use_bias=True, name= 'Block17_9_Conv2d_1x1') (mixed)
|
||||
up = Lambda(scaling, output_shape=K.int_shape(up)[1:], arguments={'scale': 0.1})(up)
|
||||
x = add([x, up])
|
||||
x = Activation('relu', name='Block17_9_Activation')(x)
|
||||
|
||||
branch_0 = Conv2D(128, 1, strides=1, padding='same', use_bias=False, name= 'Block17_10_Branch_0_Conv2d_1x1') (x)
|
||||
branch_0 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block17_10_Branch_0_Conv2d_1x1_BatchNorm')(branch_0)
|
||||
branch_0 = Activation('relu', name='Block17_10_Branch_0_Conv2d_1x1_Activation')(branch_0)
|
||||
branch_1 = Conv2D(128, 1, strides=1, padding='same', use_bias=False, name= 'Block17_10_Branch_10_Conv2d_0a_1x1') (x)
|
||||
branch_1 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block17_10_Branch_10_Conv2d_0a_1x1_BatchNorm')(branch_1)
|
||||
branch_1 = Activation('relu', name='Block17_10_Branch_10_Conv2d_0a_1x1_Activation')(branch_1)
|
||||
branch_1 = Conv2D(128, [1, 7], strides=1, padding='same', use_bias=False, name= 'Block17_10_Branch_10_Conv2d_0b_1x7') (branch_1)
|
||||
branch_1 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block17_10_Branch_10_Conv2d_0b_1x7_BatchNorm')(branch_1)
|
||||
branch_1 = Activation('relu', name='Block17_10_Branch_10_Conv2d_0b_1x7_Activation')(branch_1)
|
||||
branch_1 = Conv2D(128, [7, 1], strides=1, padding='same', use_bias=False, name= 'Block17_10_Branch_10_Conv2d_0c_7x1') (branch_1)
|
||||
branch_1 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block17_10_Branch_10_Conv2d_0c_7x1_BatchNorm')(branch_1)
|
||||
branch_1 = Activation('relu', name='Block17_10_Branch_10_Conv2d_0c_7x1_Activation')(branch_1)
|
||||
branches = [branch_0, branch_1]
|
||||
mixed = Concatenate(axis=3, name='Block17_10_Concatenate')(branches)
|
||||
up = Conv2D(896, 1, strides=1, padding='same', use_bias=True, name= 'Block17_10_Conv2d_1x1') (mixed)
|
||||
up = Lambda(scaling, output_shape=K.int_shape(up)[1:], arguments={'scale': 0.1})(up)
|
||||
x = add([x, up])
|
||||
x = Activation('relu', name='Block17_10_Activation')(x)
|
||||
|
||||
# Mixed 7a (Reduction-B block): 8 x 8 x 2080
|
||||
branch_0 = Conv2D(256, 1, strides=1, padding='same', use_bias=False, name= 'Mixed_7a_Branch_0_Conv2d_0a_1x1') (x)
|
||||
branch_0 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Mixed_7a_Branch_0_Conv2d_0a_1x1_BatchNorm')(branch_0)
|
||||
branch_0 = Activation('relu', name='Mixed_7a_Branch_0_Conv2d_0a_1x1_Activation')(branch_0)
|
||||
branch_0 = Conv2D(384, 3, strides=2, padding='valid', use_bias=False, name= 'Mixed_7a_Branch_0_Conv2d_1a_3x3') (branch_0)
|
||||
branch_0 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Mixed_7a_Branch_0_Conv2d_1a_3x3_BatchNorm')(branch_0)
|
||||
branch_0 = Activation('relu', name='Mixed_7a_Branch_0_Conv2d_1a_3x3_Activation')(branch_0)
|
||||
branch_1 = Conv2D(256, 1, strides=1, padding='same', use_bias=False, name= 'Mixed_7a_Branch_1_Conv2d_0a_1x1') (x)
|
||||
branch_1 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Mixed_7a_Branch_1_Conv2d_0a_1x1_BatchNorm')(branch_1)
|
||||
branch_1 = Activation('relu', name='Mixed_7a_Branch_1_Conv2d_0a_1x1_Activation')(branch_1)
|
||||
branch_1 = Conv2D(256, 3, strides=2, padding='valid', use_bias=False, name= 'Mixed_7a_Branch_1_Conv2d_1a_3x3') (branch_1)
|
||||
branch_1 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Mixed_7a_Branch_1_Conv2d_1a_3x3_BatchNorm')(branch_1)
|
||||
branch_1 = Activation('relu', name='Mixed_7a_Branch_1_Conv2d_1a_3x3_Activation')(branch_1)
|
||||
branch_2 = Conv2D(256, 1, strides=1, padding='same', use_bias=False, name= 'Mixed_7a_Branch_2_Conv2d_0a_1x1') (x)
|
||||
branch_2 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Mixed_7a_Branch_2_Conv2d_0a_1x1_BatchNorm')(branch_2)
|
||||
branch_2 = Activation('relu', name='Mixed_7a_Branch_2_Conv2d_0a_1x1_Activation')(branch_2)
|
||||
branch_2 = Conv2D(256, 3, strides=1, padding='same', use_bias=False, name= 'Mixed_7a_Branch_2_Conv2d_0b_3x3') (branch_2)
|
||||
branch_2 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Mixed_7a_Branch_2_Conv2d_0b_3x3_BatchNorm')(branch_2)
|
||||
branch_2 = Activation('relu', name='Mixed_7a_Branch_2_Conv2d_0b_3x3_Activation')(branch_2)
|
||||
branch_2 = Conv2D(256, 3, strides=2, padding='valid', use_bias=False, name= 'Mixed_7a_Branch_2_Conv2d_1a_3x3') (branch_2)
|
||||
branch_2 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Mixed_7a_Branch_2_Conv2d_1a_3x3_BatchNorm')(branch_2)
|
||||
branch_2 = Activation('relu', name='Mixed_7a_Branch_2_Conv2d_1a_3x3_Activation')(branch_2)
|
||||
branch_pool = MaxPooling2D(3, strides=2, padding='valid', name='Mixed_7a_Branch_3_MaxPool_1a_3x3')(x)
|
||||
branches = [branch_0, branch_1, branch_2, branch_pool]
|
||||
x = Concatenate(axis=3, name='Mixed_7a')(branches)
|
||||
|
||||
# 5x Block8 (Inception-ResNet-C block):
|
||||
|
||||
branch_0 = Conv2D(192, 1, strides=1, padding='same', use_bias=False, name= 'Block8_1_Branch_0_Conv2d_1x1') (x)
|
||||
branch_0 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block8_1_Branch_0_Conv2d_1x1_BatchNorm')(branch_0)
|
||||
branch_0 = Activation('relu', name='Block8_1_Branch_0_Conv2d_1x1_Activation')(branch_0)
|
||||
branch_1 = Conv2D(192, 1, strides=1, padding='same', use_bias=False, name= 'Block8_1_Branch_1_Conv2d_0a_1x1') (x)
|
||||
branch_1 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block8_1_Branch_1_Conv2d_0a_1x1_BatchNorm')(branch_1)
|
||||
branch_1 = Activation('relu', name='Block8_1_Branch_1_Conv2d_0a_1x1_Activation')(branch_1)
|
||||
branch_1 = Conv2D(192, [1, 3], strides=1, padding='same', use_bias=False, name= 'Block8_1_Branch_1_Conv2d_0b_1x3') (branch_1)
|
||||
branch_1 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block8_1_Branch_1_Conv2d_0b_1x3_BatchNorm')(branch_1)
|
||||
branch_1 = Activation('relu', name='Block8_1_Branch_1_Conv2d_0b_1x3_Activation')(branch_1)
|
||||
branch_1 = Conv2D(192, [3, 1], strides=1, padding='same', use_bias=False, name= 'Block8_1_Branch_1_Conv2d_0c_3x1') (branch_1)
|
||||
branch_1 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block8_1_Branch_1_Conv2d_0c_3x1_BatchNorm')(branch_1)
|
||||
branch_1 = Activation('relu', name='Block8_1_Branch_1_Conv2d_0c_3x1_Activation')(branch_1)
|
||||
branches = [branch_0, branch_1]
|
||||
mixed = Concatenate(axis=3, name='Block8_1_Concatenate')(branches)
|
||||
up = Conv2D(1792, 1, strides=1, padding='same', use_bias=True, name= 'Block8_1_Conv2d_1x1') (mixed)
|
||||
up = Lambda(scaling, output_shape=K.int_shape(up)[1:], arguments={'scale': 0.2})(up)
|
||||
x = add([x, up])
|
||||
x = Activation('relu', name='Block8_1_Activation')(x)
|
||||
|
||||
branch_0 = Conv2D(192, 1, strides=1, padding='same', use_bias=False, name= 'Block8_2_Branch_0_Conv2d_1x1') (x)
|
||||
branch_0 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block8_2_Branch_0_Conv2d_1x1_BatchNorm')(branch_0)
|
||||
branch_0 = Activation('relu', name='Block8_2_Branch_0_Conv2d_1x1_Activation')(branch_0)
|
||||
branch_1 = Conv2D(192, 1, strides=1, padding='same', use_bias=False, name= 'Block8_2_Branch_2_Conv2d_0a_1x1') (x)
|
||||
branch_1 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block8_2_Branch_2_Conv2d_0a_1x1_BatchNorm')(branch_1)
|
||||
branch_1 = Activation('relu', name='Block8_2_Branch_2_Conv2d_0a_1x1_Activation')(branch_1)
|
||||
branch_1 = Conv2D(192, [1, 3], strides=1, padding='same', use_bias=False, name= 'Block8_2_Branch_2_Conv2d_0b_1x3') (branch_1)
|
||||
branch_1 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block8_2_Branch_2_Conv2d_0b_1x3_BatchNorm')(branch_1)
|
||||
branch_1 = Activation('relu', name='Block8_2_Branch_2_Conv2d_0b_1x3_Activation')(branch_1)
|
||||
branch_1 = Conv2D(192, [3, 1], strides=1, padding='same', use_bias=False, name= 'Block8_2_Branch_2_Conv2d_0c_3x1') (branch_1)
|
||||
branch_1 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block8_2_Branch_2_Conv2d_0c_3x1_BatchNorm')(branch_1)
|
||||
branch_1 = Activation('relu', name='Block8_2_Branch_2_Conv2d_0c_3x1_Activation')(branch_1)
|
||||
branches = [branch_0, branch_1]
|
||||
mixed = Concatenate(axis=3, name='Block8_2_Concatenate')(branches)
|
||||
up = Conv2D(1792, 1, strides=1, padding='same', use_bias=True, name= 'Block8_2_Conv2d_1x1') (mixed)
|
||||
up = Lambda(scaling, output_shape=K.int_shape(up)[1:], arguments={'scale': 0.2})(up)
|
||||
x = add([x, up])
|
||||
x = Activation('relu', name='Block8_2_Activation')(x)
|
||||
|
||||
branch_0 = Conv2D(192, 1, strides=1, padding='same', use_bias=False, name= 'Block8_3_Branch_0_Conv2d_1x1') (x)
|
||||
branch_0 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block8_3_Branch_0_Conv2d_1x1_BatchNorm')(branch_0)
|
||||
branch_0 = Activation('relu', name='Block8_3_Branch_0_Conv2d_1x1_Activation')(branch_0)
|
||||
branch_1 = Conv2D(192, 1, strides=1, padding='same', use_bias=False, name= 'Block8_3_Branch_3_Conv2d_0a_1x1') (x)
|
||||
branch_1 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block8_3_Branch_3_Conv2d_0a_1x1_BatchNorm')(branch_1)
|
||||
branch_1 = Activation('relu', name='Block8_3_Branch_3_Conv2d_0a_1x1_Activation')(branch_1)
|
||||
branch_1 = Conv2D(192, [1, 3], strides=1, padding='same', use_bias=False, name= 'Block8_3_Branch_3_Conv2d_0b_1x3') (branch_1)
|
||||
branch_1 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block8_3_Branch_3_Conv2d_0b_1x3_BatchNorm')(branch_1)
|
||||
branch_1 = Activation('relu', name='Block8_3_Branch_3_Conv2d_0b_1x3_Activation')(branch_1)
|
||||
branch_1 = Conv2D(192, [3, 1], strides=1, padding='same', use_bias=False, name= 'Block8_3_Branch_3_Conv2d_0c_3x1') (branch_1)
|
||||
branch_1 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block8_3_Branch_3_Conv2d_0c_3x1_BatchNorm')(branch_1)
|
||||
branch_1 = Activation('relu', name='Block8_3_Branch_3_Conv2d_0c_3x1_Activation')(branch_1)
|
||||
branches = [branch_0, branch_1]
|
||||
mixed = Concatenate(axis=3, name='Block8_3_Concatenate')(branches)
|
||||
up = Conv2D(1792, 1, strides=1, padding='same', use_bias=True, name= 'Block8_3_Conv2d_1x1') (mixed)
|
||||
up = Lambda(scaling, output_shape=K.int_shape(up)[1:], arguments={'scale': 0.2})(up)
|
||||
x = add([x, up])
|
||||
x = Activation('relu', name='Block8_3_Activation')(x)
|
||||
|
||||
branch_0 = Conv2D(192, 1, strides=1, padding='same', use_bias=False, name= 'Block8_4_Branch_0_Conv2d_1x1') (x)
|
||||
branch_0 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block8_4_Branch_0_Conv2d_1x1_BatchNorm')(branch_0)
|
||||
branch_0 = Activation('relu', name='Block8_4_Branch_0_Conv2d_1x1_Activation')(branch_0)
|
||||
branch_1 = Conv2D(192, 1, strides=1, padding='same', use_bias=False, name= 'Block8_4_Branch_4_Conv2d_0a_1x1') (x)
|
||||
branch_1 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block8_4_Branch_4_Conv2d_0a_1x1_BatchNorm')(branch_1)
|
||||
branch_1 = Activation('relu', name='Block8_4_Branch_4_Conv2d_0a_1x1_Activation')(branch_1)
|
||||
branch_1 = Conv2D(192, [1, 3], strides=1, padding='same', use_bias=False, name= 'Block8_4_Branch_4_Conv2d_0b_1x3') (branch_1)
|
||||
branch_1 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block8_4_Branch_4_Conv2d_0b_1x3_BatchNorm')(branch_1)
|
||||
branch_1 = Activation('relu', name='Block8_4_Branch_4_Conv2d_0b_1x3_Activation')(branch_1)
|
||||
branch_1 = Conv2D(192, [3, 1], strides=1, padding='same', use_bias=False, name= 'Block8_4_Branch_4_Conv2d_0c_3x1') (branch_1)
|
||||
branch_1 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block8_4_Branch_4_Conv2d_0c_3x1_BatchNorm')(branch_1)
|
||||
branch_1 = Activation('relu', name='Block8_4_Branch_4_Conv2d_0c_3x1_Activation')(branch_1)
|
||||
branches = [branch_0, branch_1]
|
||||
mixed = Concatenate(axis=3, name='Block8_4_Concatenate')(branches)
|
||||
up = Conv2D(1792, 1, strides=1, padding='same', use_bias=True, name= 'Block8_4_Conv2d_1x1') (mixed)
|
||||
up = Lambda(scaling, output_shape=K.int_shape(up)[1:], arguments={'scale': 0.2})(up)
|
||||
x = add([x, up])
|
||||
x = Activation('relu', name='Block8_4_Activation')(x)
|
||||
|
||||
branch_0 = Conv2D(192, 1, strides=1, padding='same', use_bias=False, name= 'Block8_5_Branch_0_Conv2d_1x1') (x)
|
||||
branch_0 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block8_5_Branch_0_Conv2d_1x1_BatchNorm')(branch_0)
|
||||
branch_0 = Activation('relu', name='Block8_5_Branch_0_Conv2d_1x1_Activation')(branch_0)
|
||||
branch_1 = Conv2D(192, 1, strides=1, padding='same', use_bias=False, name= 'Block8_5_Branch_5_Conv2d_0a_1x1') (x)
|
||||
branch_1 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block8_5_Branch_5_Conv2d_0a_1x1_BatchNorm')(branch_1)
|
||||
branch_1 = Activation('relu', name='Block8_5_Branch_5_Conv2d_0a_1x1_Activation')(branch_1)
|
||||
branch_1 = Conv2D(192, [1, 3], strides=1, padding='same', use_bias=False, name= 'Block8_5_Branch_5_Conv2d_0b_1x3') (branch_1)
|
||||
branch_1 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block8_5_Branch_5_Conv2d_0b_1x3_BatchNorm')(branch_1)
|
||||
branch_1 = Activation('relu', name='Block8_5_Branch_5_Conv2d_0b_1x3_Activation')(branch_1)
|
||||
branch_1 = Conv2D(192, [3, 1], strides=1, padding='same', use_bias=False, name= 'Block8_5_Branch_5_Conv2d_0c_3x1') (branch_1)
|
||||
branch_1 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block8_5_Branch_5_Conv2d_0c_3x1_BatchNorm')(branch_1)
|
||||
branch_1 = Activation('relu', name='Block8_5_Branch_5_Conv2d_0c_3x1_Activation')(branch_1)
|
||||
branches = [branch_0, branch_1]
|
||||
mixed = Concatenate(axis=3, name='Block8_5_Concatenate')(branches)
|
||||
up = Conv2D(1792, 1, strides=1, padding='same', use_bias=True, name= 'Block8_5_Conv2d_1x1') (mixed)
|
||||
up = Lambda(scaling, output_shape=K.int_shape(up)[1:], arguments={'scale': 0.2})(up)
|
||||
x = add([x, up])
|
||||
x = Activation('relu', name='Block8_5_Activation')(x)
|
||||
|
||||
branch_0 = Conv2D(192, 1, strides=1, padding='same', use_bias=False, name= 'Block8_6_Branch_0_Conv2d_1x1') (x)
|
||||
branch_0 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block8_6_Branch_0_Conv2d_1x1_BatchNorm')(branch_0)
|
||||
branch_0 = Activation('relu', name='Block8_6_Branch_0_Conv2d_1x1_Activation')(branch_0)
|
||||
branch_1 = Conv2D(192, 1, strides=1, padding='same', use_bias=False, name= 'Block8_6_Branch_1_Conv2d_0a_1x1') (x)
|
||||
branch_1 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block8_6_Branch_1_Conv2d_0a_1x1_BatchNorm')(branch_1)
|
||||
branch_1 = Activation('relu', name='Block8_6_Branch_1_Conv2d_0a_1x1_Activation')(branch_1)
|
||||
branch_1 = Conv2D(192, [1, 3], strides=1, padding='same', use_bias=False, name= 'Block8_6_Branch_1_Conv2d_0b_1x3') (branch_1)
|
||||
branch_1 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block8_6_Branch_1_Conv2d_0b_1x3_BatchNorm')(branch_1)
|
||||
branch_1 = Activation('relu', name='Block8_6_Branch_1_Conv2d_0b_1x3_Activation')(branch_1)
|
||||
branch_1 = Conv2D(192, [3, 1], strides=1, padding='same', use_bias=False, name= 'Block8_6_Branch_1_Conv2d_0c_3x1') (branch_1)
|
||||
branch_1 = BatchNormalization(axis=3, momentum=0.995, epsilon=0.001, scale=False, name='Block8_6_Branch_1_Conv2d_0c_3x1_BatchNorm')(branch_1)
|
||||
branch_1 = Activation('relu', name='Block8_6_Branch_1_Conv2d_0c_3x1_Activation')(branch_1)
|
||||
branches = [branch_0, branch_1]
|
||||
mixed = Concatenate(axis=3, name='Block8_6_Concatenate')(branches)
|
||||
up = Conv2D(1792, 1, strides=1, padding='same', use_bias=True, name= 'Block8_6_Conv2d_1x1') (mixed)
|
||||
up = Lambda(scaling, output_shape=K.int_shape(up)[1:], arguments={'scale': 1})(up)
|
||||
x = add([x, up])
|
||||
|
||||
# Classification block
|
||||
x = GlobalAveragePooling2D(name='AvgPool')(x)
|
||||
x = Dropout(1.0 - 0.8, name='Dropout')(x)
|
||||
# Bottleneck
|
||||
x = Dense(128, use_bias=False, name='Bottleneck')(x)
|
||||
x = BatchNormalization(momentum=0.995, epsilon=0.001, scale=False, name='Bottleneck_BatchNorm')(x)
|
||||
|
||||
# Create model
|
||||
model = Model(inputs, x, name='inception_resnet_v1')
|
||||
|
||||
return model
|
||||
|
||||
def loadModel():
|
||||
model = InceptionResNetV2()
|
||||
|
||||
#-----------------------------------
|
||||
|
||||
home = str(Path.home())
|
||||
|
||||
if os.path.isfile(home+'/.deepface/weights/facenet_weights.h5') != True:
|
||||
print("facenet_weights.h5 will be downloaded...")
|
||||
|
||||
url = 'https://drive.google.com/file/d/1971Xk5RwedbudGgTIrGAL4F7Aifu7id1/view?usp=sharing'
|
||||
output = home+'/.deepface/weights/facenet_weights.h5'
|
||||
gdown.download(url, output, quiet=False)
|
||||
|
||||
#-----------------------------------
|
||||
|
||||
model.load_weights(home+'/.deepface/weights/facenet_weights.h5')
|
||||
|
||||
#-----------------------------------
|
||||
|
||||
return model
|
250
deepface/basemodels/OpenFace.py
Normal file
250
deepface/basemodels/OpenFace.py
Normal file
@ -0,0 +1,250 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
import gdown
|
||||
|
||||
import tensorflow as tf
|
||||
import keras
|
||||
from keras.models import Model, Sequential
|
||||
from keras.layers import Conv2D, ZeroPadding2D, Activation, Input, concatenate
|
||||
from keras.layers.core import Dense, Activation, Lambda, Flatten
|
||||
from keras.layers.pooling import MaxPooling2D, AveragePooling2D
|
||||
from keras.layers.merge import Concatenate
|
||||
from keras.layers.normalization import BatchNormalization
|
||||
from keras.models import load_model
|
||||
from keras import backend as K
|
||||
|
||||
#---------------------------------------
|
||||
|
||||
def loadModel():
|
||||
myInput = Input(shape=(96, 96, 3))
|
||||
|
||||
x = ZeroPadding2D(padding=(3, 3), input_shape=(96, 96, 3))(myInput)
|
||||
x = Conv2D(64, (7, 7), strides=(2, 2), name='conv1')(x)
|
||||
x = BatchNormalization(axis=3, epsilon=0.00001, name='bn1')(x)
|
||||
x = Activation('relu')(x)
|
||||
x = ZeroPadding2D(padding=(1, 1))(x)
|
||||
x = MaxPooling2D(pool_size=3, strides=2)(x)
|
||||
x = Lambda(lambda x: tf.nn.lrn(x, alpha=1e-4, beta=0.75), name='lrn_1')(x)
|
||||
x = Conv2D(64, (1, 1), name='conv2')(x)
|
||||
x = BatchNormalization(axis=3, epsilon=0.00001, name='bn2')(x)
|
||||
x = Activation('relu')(x)
|
||||
x = ZeroPadding2D(padding=(1, 1))(x)
|
||||
x = Conv2D(192, (3, 3), name='conv3')(x)
|
||||
x = BatchNormalization(axis=3, epsilon=0.00001, name='bn3')(x)
|
||||
x = Activation('relu')(x)
|
||||
Lambda(lambda x: tf.nn.lrn(x, alpha=1e-4, beta=0.75), name='lrn_2')(x)
|
||||
x = ZeroPadding2D(padding=(1, 1))(x)
|
||||
x = MaxPooling2D(pool_size=3, strides=2)(x)
|
||||
|
||||
# Inception3a
|
||||
inception_3a_3x3 = Conv2D(96, (1, 1), name='inception_3a_3x3_conv1')(x)
|
||||
inception_3a_3x3 = BatchNormalization(axis=3, epsilon=0.00001, name='inception_3a_3x3_bn1')(inception_3a_3x3)
|
||||
inception_3a_3x3 = Activation('relu')(inception_3a_3x3)
|
||||
inception_3a_3x3 = ZeroPadding2D(padding=(1, 1))(inception_3a_3x3)
|
||||
inception_3a_3x3 = Conv2D(128, (3, 3), name='inception_3a_3x3_conv2')(inception_3a_3x3)
|
||||
inception_3a_3x3 = BatchNormalization(axis=3, epsilon=0.00001, name='inception_3a_3x3_bn2')(inception_3a_3x3)
|
||||
inception_3a_3x3 = Activation('relu')(inception_3a_3x3)
|
||||
|
||||
inception_3a_5x5 = Conv2D(16, (1, 1), name='inception_3a_5x5_conv1')(x)
|
||||
inception_3a_5x5 = BatchNormalization(axis=3, epsilon=0.00001, name='inception_3a_5x5_bn1')(inception_3a_5x5)
|
||||
inception_3a_5x5 = Activation('relu')(inception_3a_5x5)
|
||||
inception_3a_5x5 = ZeroPadding2D(padding=(2, 2))(inception_3a_5x5)
|
||||
inception_3a_5x5 = Conv2D(32, (5, 5), name='inception_3a_5x5_conv2')(inception_3a_5x5)
|
||||
inception_3a_5x5 = BatchNormalization(axis=3, epsilon=0.00001, name='inception_3a_5x5_bn2')(inception_3a_5x5)
|
||||
inception_3a_5x5 = Activation('relu')(inception_3a_5x5)
|
||||
|
||||
inception_3a_pool = MaxPooling2D(pool_size=3, strides=2)(x)
|
||||
inception_3a_pool = Conv2D(32, (1, 1), name='inception_3a_pool_conv')(inception_3a_pool)
|
||||
inception_3a_pool = BatchNormalization(axis=3, epsilon=0.00001, name='inception_3a_pool_bn')(inception_3a_pool)
|
||||
inception_3a_pool = Activation('relu')(inception_3a_pool)
|
||||
inception_3a_pool = ZeroPadding2D(padding=((3, 4), (3, 4)))(inception_3a_pool)
|
||||
|
||||
inception_3a_1x1 = Conv2D(64, (1, 1), name='inception_3a_1x1_conv')(x)
|
||||
inception_3a_1x1 = BatchNormalization(axis=3, epsilon=0.00001, name='inception_3a_1x1_bn')(inception_3a_1x1)
|
||||
inception_3a_1x1 = Activation('relu')(inception_3a_1x1)
|
||||
|
||||
inception_3a = concatenate([inception_3a_3x3, inception_3a_5x5, inception_3a_pool, inception_3a_1x1], axis=3)
|
||||
|
||||
# Inception3b
|
||||
inception_3b_3x3 = Conv2D(96, (1, 1), name='inception_3b_3x3_conv1')(inception_3a)
|
||||
inception_3b_3x3 = BatchNormalization(axis=3, epsilon=0.00001, name='inception_3b_3x3_bn1')(inception_3b_3x3)
|
||||
inception_3b_3x3 = Activation('relu')(inception_3b_3x3)
|
||||
inception_3b_3x3 = ZeroPadding2D(padding=(1, 1))(inception_3b_3x3)
|
||||
inception_3b_3x3 = Conv2D(128, (3, 3), name='inception_3b_3x3_conv2')(inception_3b_3x3)
|
||||
inception_3b_3x3 = BatchNormalization(axis=3, epsilon=0.00001, name='inception_3b_3x3_bn2')(inception_3b_3x3)
|
||||
inception_3b_3x3 = Activation('relu')(inception_3b_3x3)
|
||||
|
||||
inception_3b_5x5 = Conv2D(32, (1, 1), name='inception_3b_5x5_conv1')(inception_3a)
|
||||
inception_3b_5x5 = BatchNormalization(axis=3, epsilon=0.00001, name='inception_3b_5x5_bn1')(inception_3b_5x5)
|
||||
inception_3b_5x5 = Activation('relu')(inception_3b_5x5)
|
||||
inception_3b_5x5 = ZeroPadding2D(padding=(2, 2))(inception_3b_5x5)
|
||||
inception_3b_5x5 = Conv2D(64, (5, 5), name='inception_3b_5x5_conv2')(inception_3b_5x5)
|
||||
inception_3b_5x5 = BatchNormalization(axis=3, epsilon=0.00001, name='inception_3b_5x5_bn2')(inception_3b_5x5)
|
||||
inception_3b_5x5 = Activation('relu')(inception_3b_5x5)
|
||||
|
||||
inception_3b_pool = Lambda(lambda x: x**2, name='power2_3b')(inception_3a)
|
||||
inception_3b_pool = AveragePooling2D(pool_size=(3, 3), strides=(3, 3))(inception_3b_pool)
|
||||
inception_3b_pool = Lambda(lambda x: x*9, name='mult9_3b')(inception_3b_pool)
|
||||
inception_3b_pool = Lambda(lambda x: K.sqrt(x), name='sqrt_3b')(inception_3b_pool)
|
||||
inception_3b_pool = Conv2D(64, (1, 1), name='inception_3b_pool_conv')(inception_3b_pool)
|
||||
inception_3b_pool = BatchNormalization(axis=3, epsilon=0.00001, name='inception_3b_pool_bn')(inception_3b_pool)
|
||||
inception_3b_pool = Activation('relu')(inception_3b_pool)
|
||||
inception_3b_pool = ZeroPadding2D(padding=(4, 4))(inception_3b_pool)
|
||||
|
||||
inception_3b_1x1 = Conv2D(64, (1, 1), name='inception_3b_1x1_conv')(inception_3a)
|
||||
inception_3b_1x1 = BatchNormalization(axis=3, epsilon=0.00001, name='inception_3b_1x1_bn')(inception_3b_1x1)
|
||||
inception_3b_1x1 = Activation('relu')(inception_3b_1x1)
|
||||
|
||||
inception_3b = concatenate([inception_3b_3x3, inception_3b_5x5, inception_3b_pool, inception_3b_1x1], axis=3)
|
||||
|
||||
# Inception3c
|
||||
inception_3c_3x3 = Conv2D(128, (1, 1), strides=(1, 1), name='inception_3c_3x3_conv1')(inception_3b)
|
||||
inception_3c_3x3 = BatchNormalization(axis=3, epsilon=0.00001, name='inception_3c_3x3_bn1')(inception_3c_3x3)
|
||||
inception_3c_3x3 = Activation('relu')(inception_3c_3x3)
|
||||
inception_3c_3x3 = ZeroPadding2D(padding=(1, 1))(inception_3c_3x3)
|
||||
inception_3c_3x3 = Conv2D(256, (3, 3), strides=(2, 2), name='inception_3c_3x3_conv'+'2')(inception_3c_3x3)
|
||||
inception_3c_3x3 = BatchNormalization(axis=3, epsilon=0.00001, name='inception_3c_3x3_bn'+'2')(inception_3c_3x3)
|
||||
inception_3c_3x3 = Activation('relu')(inception_3c_3x3)
|
||||
|
||||
inception_3c_5x5 = Conv2D(32, (1, 1), strides=(1, 1), name='inception_3c_5x5_conv1')(inception_3b)
|
||||
inception_3c_5x5 = BatchNormalization(axis=3, epsilon=0.00001, name='inception_3c_5x5_bn1')(inception_3c_5x5)
|
||||
inception_3c_5x5 = Activation('relu')(inception_3c_5x5)
|
||||
inception_3c_5x5 = ZeroPadding2D(padding=(2, 2))(inception_3c_5x5)
|
||||
inception_3c_5x5 = Conv2D(64, (5, 5), strides=(2, 2), name='inception_3c_5x5_conv'+'2')(inception_3c_5x5)
|
||||
inception_3c_5x5 = BatchNormalization(axis=3, epsilon=0.00001, name='inception_3c_5x5_bn'+'2')(inception_3c_5x5)
|
||||
inception_3c_5x5 = Activation('relu')(inception_3c_5x5)
|
||||
|
||||
inception_3c_pool = MaxPooling2D(pool_size=3, strides=2)(inception_3b)
|
||||
inception_3c_pool = ZeroPadding2D(padding=((0, 1), (0, 1)))(inception_3c_pool)
|
||||
|
||||
inception_3c = concatenate([inception_3c_3x3, inception_3c_5x5, inception_3c_pool], axis=3)
|
||||
|
||||
#inception 4a
|
||||
inception_4a_3x3 = Conv2D(96, (1, 1), strides=(1, 1), name='inception_4a_3x3_conv'+'1')(inception_3c)
|
||||
inception_4a_3x3 = BatchNormalization(axis=3, epsilon=0.00001, name='inception_4a_3x3_bn'+'1')(inception_4a_3x3)
|
||||
inception_4a_3x3 = Activation('relu')(inception_4a_3x3)
|
||||
inception_4a_3x3 = ZeroPadding2D(padding=(1, 1))(inception_4a_3x3)
|
||||
inception_4a_3x3 = Conv2D(192, (3, 3), strides=(1, 1), name='inception_4a_3x3_conv'+'2')(inception_4a_3x3)
|
||||
inception_4a_3x3 = BatchNormalization(axis=3, epsilon=0.00001, name='inception_4a_3x3_bn'+'2')(inception_4a_3x3)
|
||||
inception_4a_3x3 = Activation('relu')(inception_4a_3x3)
|
||||
|
||||
inception_4a_5x5 = Conv2D(32, (1,1), strides=(1,1), name='inception_4a_5x5_conv1')(inception_3c)
|
||||
inception_4a_5x5 = BatchNormalization(axis=3, epsilon=0.00001, name='inception_4a_5x5_bn1')(inception_4a_5x5)
|
||||
inception_4a_5x5 = Activation('relu')(inception_4a_5x5)
|
||||
inception_4a_5x5 = ZeroPadding2D(padding=(2,2))(inception_4a_5x5)
|
||||
inception_4a_5x5 = Conv2D(64, (5,5), strides=(1,1), name='inception_4a_5x5_conv'+'2')(inception_4a_5x5)
|
||||
inception_4a_5x5 = BatchNormalization(axis=3, epsilon=0.00001, name='inception_4a_5x5_bn'+'2')(inception_4a_5x5)
|
||||
inception_4a_5x5 = Activation('relu')(inception_4a_5x5)
|
||||
|
||||
inception_4a_pool = Lambda(lambda x: x**2, name='power2_4a')(inception_3c)
|
||||
inception_4a_pool = AveragePooling2D(pool_size=(3, 3), strides=(3, 3))(inception_4a_pool)
|
||||
inception_4a_pool = Lambda(lambda x: x*9, name='mult9_4a')(inception_4a_pool)
|
||||
inception_4a_pool = Lambda(lambda x: K.sqrt(x), name='sqrt_4a')(inception_4a_pool)
|
||||
|
||||
inception_4a_pool = Conv2D(128, (1,1), strides=(1,1), name='inception_4a_pool_conv'+'')(inception_4a_pool)
|
||||
inception_4a_pool = BatchNormalization(axis=3, epsilon=0.00001, name='inception_4a_pool_bn'+'')(inception_4a_pool)
|
||||
inception_4a_pool = Activation('relu')(inception_4a_pool)
|
||||
inception_4a_pool = ZeroPadding2D(padding=(2, 2))(inception_4a_pool)
|
||||
|
||||
inception_4a_1x1 = Conv2D(256, (1, 1), strides=(1, 1), name='inception_4a_1x1_conv'+'')(inception_3c)
|
||||
inception_4a_1x1 = BatchNormalization(axis=3, epsilon=0.00001, name='inception_4a_1x1_bn'+'')(inception_4a_1x1)
|
||||
inception_4a_1x1 = Activation('relu')(inception_4a_1x1)
|
||||
|
||||
inception_4a = concatenate([inception_4a_3x3, inception_4a_5x5, inception_4a_pool, inception_4a_1x1], axis=3)
|
||||
|
||||
#inception4e
|
||||
inception_4e_3x3 = Conv2D(160, (1,1), strides=(1,1), name='inception_4e_3x3_conv'+'1')(inception_4a)
|
||||
inception_4e_3x3 = BatchNormalization(axis=3, epsilon=0.00001, name='inception_4e_3x3_bn'+'1')(inception_4e_3x3)
|
||||
inception_4e_3x3 = Activation('relu')(inception_4e_3x3)
|
||||
inception_4e_3x3 = ZeroPadding2D(padding=(1, 1))(inception_4e_3x3)
|
||||
inception_4e_3x3 = Conv2D(256, (3,3), strides=(2,2), name='inception_4e_3x3_conv'+'2')(inception_4e_3x3)
|
||||
inception_4e_3x3 = BatchNormalization(axis=3, epsilon=0.00001, name='inception_4e_3x3_bn'+'2')(inception_4e_3x3)
|
||||
inception_4e_3x3 = Activation('relu')(inception_4e_3x3)
|
||||
|
||||
inception_4e_5x5 = Conv2D(64, (1,1), strides=(1,1), name='inception_4e_5x5_conv'+'1')(inception_4a)
|
||||
inception_4e_5x5 = BatchNormalization(axis=3, epsilon=0.00001, name='inception_4e_5x5_bn'+'1')(inception_4e_5x5)
|
||||
inception_4e_5x5 = Activation('relu')(inception_4e_5x5)
|
||||
inception_4e_5x5 = ZeroPadding2D(padding=(2, 2))(inception_4e_5x5)
|
||||
inception_4e_5x5 = Conv2D(128, (5,5), strides=(2,2), name='inception_4e_5x5_conv'+'2')(inception_4e_5x5)
|
||||
inception_4e_5x5 = BatchNormalization(axis=3, epsilon=0.00001, name='inception_4e_5x5_bn'+'2')(inception_4e_5x5)
|
||||
inception_4e_5x5 = Activation('relu')(inception_4e_5x5)
|
||||
|
||||
inception_4e_pool = MaxPooling2D(pool_size=3, strides=2)(inception_4a)
|
||||
inception_4e_pool = ZeroPadding2D(padding=((0, 1), (0, 1)))(inception_4e_pool)
|
||||
|
||||
inception_4e = concatenate([inception_4e_3x3, inception_4e_5x5, inception_4e_pool], axis=3)
|
||||
|
||||
#inception5a
|
||||
inception_5a_3x3 = Conv2D(96, (1,1), strides=(1,1), name='inception_5a_3x3_conv'+'1')(inception_4e)
|
||||
inception_5a_3x3 = BatchNormalization(axis=3, epsilon=0.00001, name='inception_5a_3x3_bn'+'1')(inception_5a_3x3)
|
||||
inception_5a_3x3 = Activation('relu')(inception_5a_3x3)
|
||||
inception_5a_3x3 = ZeroPadding2D(padding=(1, 1))(inception_5a_3x3)
|
||||
inception_5a_3x3 = Conv2D(384, (3,3), strides=(1,1), name='inception_5a_3x3_conv'+'2')(inception_5a_3x3)
|
||||
inception_5a_3x3 = BatchNormalization(axis=3, epsilon=0.00001, name='inception_5a_3x3_bn'+'2')(inception_5a_3x3)
|
||||
inception_5a_3x3 = Activation('relu')(inception_5a_3x3)
|
||||
|
||||
inception_5a_pool = Lambda(lambda x: x**2, name='power2_5a')(inception_4e)
|
||||
inception_5a_pool = AveragePooling2D(pool_size=(3, 3), strides=(3, 3))(inception_5a_pool)
|
||||
inception_5a_pool = Lambda(lambda x: x*9, name='mult9_5a')(inception_5a_pool)
|
||||
inception_5a_pool = Lambda(lambda x: K.sqrt(x), name='sqrt_5a')(inception_5a_pool)
|
||||
|
||||
inception_5a_pool = Conv2D(96, (1,1), strides=(1,1), name='inception_5a_pool_conv'+'')(inception_5a_pool)
|
||||
inception_5a_pool = BatchNormalization(axis=3, epsilon=0.00001, name='inception_5a_pool_bn'+'')(inception_5a_pool)
|
||||
inception_5a_pool = Activation('relu')(inception_5a_pool)
|
||||
inception_5a_pool = ZeroPadding2D(padding=(1,1))(inception_5a_pool)
|
||||
|
||||
inception_5a_1x1 = Conv2D(256, (1,1), strides=(1,1), name='inception_5a_1x1_conv'+'')(inception_4e)
|
||||
inception_5a_1x1 = BatchNormalization(axis=3, epsilon=0.00001, name='inception_5a_1x1_bn'+'')(inception_5a_1x1)
|
||||
inception_5a_1x1 = Activation('relu')(inception_5a_1x1)
|
||||
|
||||
inception_5a = concatenate([inception_5a_3x3, inception_5a_pool, inception_5a_1x1], axis=3)
|
||||
|
||||
#inception_5b
|
||||
inception_5b_3x3 = Conv2D(96, (1,1), strides=(1,1), name='inception_5b_3x3_conv'+'1')(inception_5a)
|
||||
inception_5b_3x3 = BatchNormalization(axis=3, epsilon=0.00001, name='inception_5b_3x3_bn'+'1')(inception_5b_3x3)
|
||||
inception_5b_3x3 = Activation('relu')(inception_5b_3x3)
|
||||
inception_5b_3x3 = ZeroPadding2D(padding=(1,1))(inception_5b_3x3)
|
||||
inception_5b_3x3 = Conv2D(384, (3,3), strides=(1,1), name='inception_5b_3x3_conv'+'2')(inception_5b_3x3)
|
||||
inception_5b_3x3 = BatchNormalization(axis=3, epsilon=0.00001, name='inception_5b_3x3_bn'+'2')(inception_5b_3x3)
|
||||
inception_5b_3x3 = Activation('relu')(inception_5b_3x3)
|
||||
|
||||
inception_5b_pool = MaxPooling2D(pool_size=3, strides=2)(inception_5a)
|
||||
|
||||
inception_5b_pool = Conv2D(96, (1,1), strides=(1,1), name='inception_5b_pool_conv'+'')(inception_5b_pool)
|
||||
inception_5b_pool = BatchNormalization(axis=3, epsilon=0.00001, name='inception_5b_pool_bn'+'')(inception_5b_pool)
|
||||
inception_5b_pool = Activation('relu')(inception_5b_pool)
|
||||
|
||||
inception_5b_pool = ZeroPadding2D(padding=(1, 1))(inception_5b_pool)
|
||||
|
||||
inception_5b_1x1 = Conv2D(256, (1,1), strides=(1,1), name='inception_5b_1x1_conv'+'')(inception_5a)
|
||||
inception_5b_1x1 = BatchNormalization(axis=3, epsilon=0.00001, name='inception_5b_1x1_bn'+'')(inception_5b_1x1)
|
||||
inception_5b_1x1 = Activation('relu')(inception_5b_1x1)
|
||||
|
||||
inception_5b = concatenate([inception_5b_3x3, inception_5b_pool, inception_5b_1x1], axis=3)
|
||||
|
||||
av_pool = AveragePooling2D(pool_size=(3, 3), strides=(1, 1))(inception_5b)
|
||||
reshape_layer = Flatten()(av_pool)
|
||||
dense_layer = Dense(128, name='dense_layer')(reshape_layer)
|
||||
norm_layer = Lambda(lambda x: K.l2_normalize(x, axis=1), name='norm_layer')(dense_layer)
|
||||
|
||||
# Final Model
|
||||
model = Model(inputs=[myInput], outputs=norm_layer)
|
||||
|
||||
#-----------------------------------
|
||||
|
||||
home = str(Path.home())
|
||||
|
||||
if os.path.isfile(home+'/.deepface/weights/openface_weights.h5') != True:
|
||||
print("openface_weights.h5 will be downloaded...")
|
||||
|
||||
url = 'https://drive.google.com/file/d/1LSe1YCV1x-BfNnfb7DFZTNpv_Q9jITxn'
|
||||
output = home+'/.deepface/weights/openface_weights.h5'
|
||||
gdown.download(url, output, quiet=False)
|
||||
|
||||
#-----------------------------------
|
||||
|
||||
model.load_weights(home+'/.deepface/weights/openface_weights.h5')
|
||||
|
||||
#-----------------------------------
|
||||
|
||||
return model
|
74
deepface/basemodels/VGGFace.py
Normal file
74
deepface/basemodels/VGGFace.py
Normal file
@ -0,0 +1,74 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
from keras.models import Model, Sequential
|
||||
from keras.layers import Input, Convolution2D, ZeroPadding2D, MaxPooling2D, Flatten, Dense, Dropout, Activation
|
||||
import gdown
|
||||
|
||||
#---------------------------------------
|
||||
|
||||
def loadModel():
|
||||
model = Sequential()
|
||||
model.add(ZeroPadding2D((1,1),input_shape=(224,224, 3)))
|
||||
model.add(Convolution2D(64, (3, 3), activation='relu'))
|
||||
model.add(ZeroPadding2D((1,1)))
|
||||
model.add(Convolution2D(64, (3, 3), activation='relu'))
|
||||
model.add(MaxPooling2D((2,2), strides=(2,2)))
|
||||
|
||||
model.add(ZeroPadding2D((1,1)))
|
||||
model.add(Convolution2D(128, (3, 3), activation='relu'))
|
||||
model.add(ZeroPadding2D((1,1)))
|
||||
model.add(Convolution2D(128, (3, 3), activation='relu'))
|
||||
model.add(MaxPooling2D((2,2), strides=(2,2)))
|
||||
|
||||
model.add(ZeroPadding2D((1,1)))
|
||||
model.add(Convolution2D(256, (3, 3), activation='relu'))
|
||||
model.add(ZeroPadding2D((1,1)))
|
||||
model.add(Convolution2D(256, (3, 3), activation='relu'))
|
||||
model.add(ZeroPadding2D((1,1)))
|
||||
model.add(Convolution2D(256, (3, 3), activation='relu'))
|
||||
model.add(MaxPooling2D((2,2), strides=(2,2)))
|
||||
|
||||
model.add(ZeroPadding2D((1,1)))
|
||||
model.add(Convolution2D(512, (3, 3), activation='relu'))
|
||||
model.add(ZeroPadding2D((1,1)))
|
||||
model.add(Convolution2D(512, (3, 3), activation='relu'))
|
||||
model.add(ZeroPadding2D((1,1)))
|
||||
model.add(Convolution2D(512, (3, 3), activation='relu'))
|
||||
model.add(MaxPooling2D((2,2), strides=(2,2)))
|
||||
|
||||
model.add(ZeroPadding2D((1,1)))
|
||||
model.add(Convolution2D(512, (3, 3), activation='relu'))
|
||||
model.add(ZeroPadding2D((1,1)))
|
||||
model.add(Convolution2D(512, (3, 3), activation='relu'))
|
||||
model.add(ZeroPadding2D((1,1)))
|
||||
model.add(Convolution2D(512, (3, 3), activation='relu'))
|
||||
model.add(MaxPooling2D((2,2), strides=(2,2)))
|
||||
|
||||
model.add(Convolution2D(4096, (7, 7), activation='relu'))
|
||||
model.add(Dropout(0.5))
|
||||
model.add(Convolution2D(4096, (1, 1), activation='relu'))
|
||||
model.add(Dropout(0.5))
|
||||
model.add(Convolution2D(2622, (1, 1)))
|
||||
model.add(Flatten())
|
||||
model.add(Activation('softmax'))
|
||||
|
||||
#-----------------------------------
|
||||
|
||||
home = str(Path.home())
|
||||
|
||||
if os.path.isfile(home+'/.deepface/weights/vgg_face_weights.h5') != True:
|
||||
print("vgg_face_weights.h5 will be downloaded...")
|
||||
|
||||
url = 'https://drive.google.com/uc?id=1CPSeum3HpopfomUEK1gybeuIVoeJT_Eo'
|
||||
output = home+'/.deepface/weights/vgg_face_weights.h5'
|
||||
gdown.download(url, output, quiet=False)
|
||||
|
||||
#-----------------------------------
|
||||
|
||||
model.load_weights(home+'/.deepface/weights/vgg_face_weights.h5')
|
||||
|
||||
#-----------------------------------
|
||||
|
||||
vgg_face_descriptor = Model(inputs=model.layers[0].input, outputs=model.layers[-2].output)
|
||||
|
||||
return vgg_face_descriptor
|
0
deepface/basemodels/__init__.py
Normal file
0
deepface/basemodels/__init__.py
Normal file
0
deepface/commons/__init__.py
Normal file
0
deepface/commons/__init__.py
Normal file
20
deepface/commons/distance.py
Normal file
20
deepface/commons/distance.py
Normal file
@ -0,0 +1,20 @@
|
||||
import numpy as np
|
||||
|
||||
def findCosineDistance(source_representation, test_representation):
|
||||
a = np.matmul(np.transpose(source_representation), test_representation)
|
||||
b = np.sum(np.multiply(source_representation, source_representation))
|
||||
c = np.sum(np.multiply(test_representation, test_representation))
|
||||
return 1 - (a / (np.sqrt(b) * np.sqrt(c)))
|
||||
|
||||
def findEuclideanDistance(source_representation, test_representation):
|
||||
euclidean_distance = source_representation - test_representation
|
||||
euclidean_distance = np.sum(np.multiply(euclidean_distance, euclidean_distance))
|
||||
euclidean_distance = np.sqrt(euclidean_distance)
|
||||
return euclidean_distance
|
||||
|
||||
def l2_normalize(x):
|
||||
return x / np.sqrt(np.sum(np.multiply(x, x)))
|
||||
|
||||
"""def l2_normalize(x, axis=-1, epsilon=1e-10):
|
||||
output = x / np.sqrt(np.maximum(np.sum(np.square(x), axis=axis, keepdims=True), epsilon))
|
||||
return output"""
|
112
deepface/commons/functions.py
Normal file
112
deepface/commons/functions.py
Normal file
@ -0,0 +1,112 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
import numpy as np
|
||||
from keras.preprocessing.image import load_img, save_img, img_to_array
|
||||
from keras.applications.imagenet_utils import preprocess_input
|
||||
from keras.preprocessing import image
|
||||
import cv2
|
||||
from pathlib import Path
|
||||
import gdown
|
||||
|
||||
def initializeFolder():
|
||||
|
||||
home = str(Path.home())
|
||||
|
||||
if not os.path.exists(home+"/.deepface"):
|
||||
os.mkdir(home+"/.deepface")
|
||||
print("Directory ",home,"/.deepface created")
|
||||
|
||||
if not os.path.exists(home+"/.deepface/weights"):
|
||||
os.mkdir(home+"/.deepface/weights")
|
||||
print("Directory ",home,"/.deepface/weights created")
|
||||
|
||||
if not os.path.exists(home+"/.deepface/config"):
|
||||
os.mkdir(home+"/.deepface/config")
|
||||
print("Directory ",home,"/.deepface/config created")
|
||||
|
||||
def validateInputs(model_name, distance_metric):
|
||||
|
||||
distance_metrics = ['cosine', 'euclidean', 'euclidean_l2']
|
||||
if distance_metric not in distance_metrics:
|
||||
raise ValueError("Distance metric must be in ",distance_metrics," but you passed ", distance_metric)
|
||||
|
||||
#--------------------------
|
||||
|
||||
model_names = ['VGG-Face', 'Facenet', 'OpenFace']
|
||||
|
||||
if model_name not in model_names:
|
||||
raise ValueError("Model name metric must be in ",model_names," but you passed ", model_name)
|
||||
|
||||
def findThreshold(model_name, distance_metric):
|
||||
|
||||
threshold = 0.40
|
||||
|
||||
if model_name == 'VGG-Face':
|
||||
if distance_metric == 'cosine':
|
||||
threshold = 0.40
|
||||
elif distance_metric == 'euclidean':
|
||||
threshold = 0.55
|
||||
elif distance_metric == 'euclidean_l2':
|
||||
threshold = 0.75
|
||||
|
||||
elif model_name == 'OpenFace':
|
||||
if distance_metric == 'cosine':
|
||||
threshold = 0.10
|
||||
elif distance_metric == 'euclidean':
|
||||
threshold = 0.55
|
||||
elif distance_metric == 'euclidean_l2':
|
||||
threshold = 0.55
|
||||
|
||||
elif model_name == 'Facenet':
|
||||
if distance_metric == 'cosine':
|
||||
threshold = 0.40
|
||||
elif distance_metric == 'euclidean':
|
||||
threshold = 10
|
||||
elif distance_metric == 'euclidean_l2':
|
||||
threshold = 0.80
|
||||
|
||||
return threshold
|
||||
|
||||
def detectFace(image_path, target_size=(224, 224)):
|
||||
|
||||
opencv_home = cv2.__file__
|
||||
folders = opencv_home.split("\\")[0:-1]
|
||||
path = folders[0]
|
||||
for folder in folders[1:]:
|
||||
path = path + "/" + folder
|
||||
|
||||
detector_path = path+"/data/haarcascade_frontalface_default.xml"
|
||||
|
||||
if os.path.isfile(detector_path) != True:
|
||||
raise ValueError("Confirm that opencv is installed on your environment! Expected path ",detector_path," violated.")
|
||||
|
||||
#--------------------------------
|
||||
|
||||
detector = cv2.CascadeClassifier(detector_path)
|
||||
|
||||
img = cv2.imread(image_path)
|
||||
|
||||
faces = detector.detectMultiScale(img, 1.3, 5)
|
||||
|
||||
#print("found faces in ",image_path," is ",len(faces))
|
||||
|
||||
if len(faces) > 0:
|
||||
x,y,w,h = faces[0]
|
||||
detected_face = img[int(y):int(y+h), int(x):int(x+w)]
|
||||
detected_face = cv2.resize(detected_face, target_size)
|
||||
|
||||
img_pixels = image.img_to_array(detected_face)
|
||||
img_pixels = np.expand_dims(img_pixels, axis = 0)
|
||||
|
||||
if True:
|
||||
#normalize input in [0, 1]
|
||||
img_pixels /= 255
|
||||
else:
|
||||
#normalize input in [-1, +1]
|
||||
img_pixels /= 127.5
|
||||
img_pixels -= 1
|
||||
|
||||
return img_pixels
|
||||
|
||||
else:
|
||||
raise ValueError("Face could not be detected in ", image_path,". Please confirm that the picture is a face photo.")
|
23
setup.py
Normal file
23
setup.py
Normal file
@ -0,0 +1,23 @@
|
||||
import setuptools
|
||||
|
||||
with open("README.md", "r", encoding="utf-8") as fh:
|
||||
long_description = fh.read()
|
||||
|
||||
setuptools.setup(
|
||||
name="deepface",
|
||||
version="0.0.1",
|
||||
author="Sefik Ilkin Serengil",
|
||||
author_email="serengil@gmail.com",
|
||||
description="Deep Face Recognition Framework",
|
||||
long_description=long_description,
|
||||
long_description_content_type="text/markdown",
|
||||
url="https://github.com/serengil/deepface",
|
||||
packages=setuptools.find_packages(),
|
||||
classifiers=[
|
||||
"Programming Language :: Python :: 3",
|
||||
"License :: OSI Approved :: MIT License",
|
||||
"Operating System :: OS Independent",
|
||||
],
|
||||
python_requires='>=3.5.5',
|
||||
install_requires=["numpy>=1.14.0", "matplotlib>=2.2.2", "opencv-python>=3.4.4", "tensorflow>=1.9.0", "keras>=2.2.0", "gdown>=3.10.1"]
|
||||
)
|
BIN
tests/dataset/img1.jpg
Normal file
BIN
tests/dataset/img1.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.2 MiB |
BIN
tests/dataset/img2.jpg
Normal file
BIN
tests/dataset/img2.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 339 KiB |
BIN
tests/dataset/img3.jpg
Normal file
BIN
tests/dataset/img3.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 647 KiB |
51
tests/unit_tests.py
Normal file
51
tests/unit_tests.py
Normal file
@ -0,0 +1,51 @@
|
||||
from deepface import DeepFace
|
||||
|
||||
#-----------------------------------------
|
||||
|
||||
dataset = [
|
||||
['dataset/img1.jpg', 'dataset/img2.jpg', True],
|
||||
['dataset/img1.jpg', 'dataset/img3.jpg', False],
|
||||
['dataset/img2.jpg', 'dataset/img3.jpg', False],
|
||||
]
|
||||
|
||||
models = ['VGG-Face', 'Facenet', 'OpenFace']
|
||||
metrics = ['cosine', 'euclidean', 'euclidean_l2']
|
||||
|
||||
passed_tests = 0; test_cases = 0
|
||||
|
||||
for model in models:
|
||||
for metric in metrics:
|
||||
for instance in dataset:
|
||||
img1 = instance[0]
|
||||
img2 = instance[1]
|
||||
result = instance[2]
|
||||
|
||||
idx = DeepFace.verify(img1, img2, model_name = model, distance_metric = metric)
|
||||
|
||||
test_result_label = "failed"
|
||||
if idx[0] == result:
|
||||
passed_tests = passed_tests + 1
|
||||
test_result_label = "passed"
|
||||
|
||||
if idx[0] == True:
|
||||
classified_label = "verified"
|
||||
else:
|
||||
classified_label = "unverified"
|
||||
|
||||
test_cases = test_cases + 1
|
||||
|
||||
print(img1, " and ", img2," are ", classified_label, " as same person based on ", model," model and ",metric," distance metric. Distance: ",round(idx[1], 2),", Required Threshold: ", idx[2]," (",test_result_label,")")
|
||||
|
||||
print("--------------------------")
|
||||
|
||||
#-----------------------------------------
|
||||
|
||||
print("Passed unit tests: ",passed_tests," / ",test_cases)
|
||||
|
||||
accuracy = 100 * passed_tests / test_cases
|
||||
accuracy = round(accuracy, 2)
|
||||
|
||||
if accuracy > 80:
|
||||
print("Unit tests are completed successfully. Score: ",accuracy,"%")
|
||||
else:
|
||||
raise ValueError("Unit test score does not satisfy the minimum required accuracy. Minimum expected score is 80% but this got ",accuracy,"%")
|
Loading…
x
Reference in New Issue
Block a user