mirror of
https://github.com/iperov/DeepFaceLab.git
synced 2025-07-16 10:03:41 -07:00
added 'sort by vggface': sorting by face similarity using VGGFace model.
Requires 4GB+ VRAM and internet connection for the first run.
This commit is contained in:
parent
0d3b25812d
commit
734d97d729
8 changed files with 186 additions and 43 deletions
64
nnlib/VGGFace.py
Normal file
64
nnlib/VGGFace.py
Normal file
|
@ -0,0 +1,64 @@
|
|||
from nnlib import nnlib
|
||||
|
||||
def VGGFace():
|
||||
exec(nnlib.import_all(), locals(), globals())
|
||||
|
||||
img_input = Input(shape=(224,224,3) )
|
||||
|
||||
# Block 1
|
||||
x = Conv2D(64, (3, 3), activation='relu', padding='same', name='conv1_1')(
|
||||
img_input)
|
||||
x = Conv2D(64, (3, 3), activation='relu', padding='same', name='conv1_2')(x)
|
||||
x = MaxPooling2D((2, 2), strides=(2, 2), name='pool1')(x)
|
||||
|
||||
# Block 2
|
||||
x = Conv2D(128, (3, 3), activation='relu', padding='same', name='conv2_1')(
|
||||
x)
|
||||
x = Conv2D(128, (3, 3), activation='relu', padding='same', name='conv2_2')(
|
||||
x)
|
||||
x = MaxPooling2D((2, 2), strides=(2, 2), name='pool2')(x)
|
||||
|
||||
# Block 3
|
||||
x = Conv2D(256, (3, 3), activation='relu', padding='same', name='conv3_1')(
|
||||
x)
|
||||
x = Conv2D(256, (3, 3), activation='relu', padding='same', name='conv3_2')(
|
||||
x)
|
||||
x = Conv2D(256, (3, 3), activation='relu', padding='same', name='conv3_3')(
|
||||
x)
|
||||
x = MaxPooling2D((2, 2), strides=(2, 2), name='pool3')(x)
|
||||
|
||||
# Block 4
|
||||
x = Conv2D(512, (3, 3), activation='relu', padding='same', name='conv4_1')(
|
||||
x)
|
||||
x = Conv2D(512, (3, 3), activation='relu', padding='same', name='conv4_2')(
|
||||
x)
|
||||
x = Conv2D(512, (3, 3), activation='relu', padding='same', name='conv4_3')(
|
||||
x)
|
||||
x = MaxPooling2D((2, 2), strides=(2, 2), name='pool4')(x)
|
||||
|
||||
# Block 5
|
||||
x = Conv2D(512, (3, 3), activation='relu', padding='same', name='conv5_1')(
|
||||
x)
|
||||
x = Conv2D(512, (3, 3), activation='relu', padding='same', name='conv5_2')(
|
||||
x)
|
||||
x = Conv2D(512, (3, 3), activation='relu', padding='same', name='conv5_3')(
|
||||
x)
|
||||
x = MaxPooling2D((2, 2), strides=(2, 2), name='pool5')(x)
|
||||
|
||||
|
||||
# Classification block
|
||||
x = Flatten(name='flatten')(x)
|
||||
x = Dense(4096, name='fc6')(x)
|
||||
x = Activation('relu', name='fc6/relu')(x)
|
||||
x = Dense(4096, name='fc7')(x)
|
||||
x = Activation('relu', name='fc7/relu')(x)
|
||||
x = Dense(2622, name='fc8')(x)
|
||||
x = Activation('softmax', name='fc8/softmax')(x)
|
||||
|
||||
model = Model(img_input, x, name='vggface_vgg16')
|
||||
weights_path = keras.utils.data_utils.get_file('rcmalli_vggface_tf_vgg16.h5',
|
||||
'https://github.com/rcmalli/keras-vggface/releases/download/v2.0/rcmalli_vggface_tf_vgg16.h5')
|
||||
|
||||
model.load_weights(weights_path, by_name=True)
|
||||
|
||||
return model
|
Loading…
Add table
Add a link
Reference in a new issue