diff --git a/deepface/basemodels/ArcFace.py b/deepface/basemodels/ArcFace.py index 2ba0b77..a5e99cc 100644 --- a/deepface/basemodels/ArcFace.py +++ b/deepface/basemodels/ArcFace.py @@ -10,7 +10,9 @@ import os from pathlib import Path import gdown -def loadModel(): +#url = "https://drive.google.com/uc?id=1LVB3CdVejpmGHM28BpqqkbZP5hDEcdZY" + +def loadModel(url = 'https://github.com/serengil/deepface_models/releases/download/v1.0/arcface_weights.h5'): base_model = ResNet34() inputs = base_model.inputs[0] arcface_model = base_model.outputs[0] @@ -20,41 +22,36 @@ def loadModel(): arcface_model = keras.layers.Dense(512, activation=None, use_bias=True, kernel_initializer="glorot_normal")(arcface_model) embedding = keras.layers.BatchNormalization(momentum=0.9, epsilon=2e-5, name="embedding", scale=True)(arcface_model) model = keras.models.Model(inputs, embedding, name=base_model.name) - + #--------------------------------------- #check the availability of pre-trained weights - + home = str(Path.home()) - - url = "https://drive.google.com/uc?id=1LVB3CdVejpmGHM28BpqqkbZP5hDEcdZY" + file_name = "arcface_weights.h5" output = home+'/.deepface/weights/'+file_name - + if os.path.isfile(output) != True: print(file_name," will be downloaded to ",output) - gdown.download(url, output, quiet=False) - + gdown.download(url, output, quiet=False) + #--------------------------------------- - try: - model.load_weights(output) - except: - print("pre-trained weights could not be loaded.") - print("You might try to download it from the url ", url," and copy to ",output," manually") - + model.load_weights(output) + return model - + def ResNet34(): - + img_input = tensorflow.keras.layers.Input(shape=(112, 112, 3)) - + x = tensorflow.keras.layers.ZeroPadding2D(padding=1, name='conv1_pad')(img_input) x = tensorflow.keras.layers.Conv2D(64, 3, strides=1, use_bias=False, kernel_initializer='glorot_normal', name='conv1_conv')(x) x = tensorflow.keras.layers.BatchNormalization(axis=3, epsilon=2e-5, momentum=0.9, name='conv1_bn')(x) x = tensorflow.keras.layers.PReLU(shared_axes=[1, 2], name='conv1_prelu')(x) x = stack_fn(x) - + model = training.Model(img_input, x, name='ResNet34') return model @@ -91,4 +88,4 @@ def stack_fn(x): x = stack1(x, 64, 3, name='conv2') x = stack1(x, 128, 4, name='conv3') x = stack1(x, 256, 6, name='conv4') - return stack1(x, 512, 3, name='conv5') \ No newline at end of file + return stack1(x, 512, 3, name='conv5') diff --git a/deepface/basemodels/DeepID.py b/deepface/basemodels/DeepID.py index 08c7923..8fbfa6a 100644 --- a/deepface/basemodels/DeepID.py +++ b/deepface/basemodels/DeepID.py @@ -9,44 +9,46 @@ from tensorflow.keras.layers import Conv2D, Activation, Input, Add, MaxPooling2D #------------------------------------- -def loadModel(url = 'https://drive.google.com/uc?id=1uRLtBCTQQAvHJ_KVrdbRJiCKxU8m5q2J'): - +#url = 'https://drive.google.com/uc?id=1uRLtBCTQQAvHJ_KVrdbRJiCKxU8m5q2J' + +def loadModel(url = 'https://github.com/serengil/deepface_models/releases/download/v1.0/deepid_keras_weights.h5'): + myInput = Input(shape=(55, 47, 3)) - + x = Conv2D(20, (4, 4), name='Conv1', activation='relu', input_shape=(55, 47, 3))(myInput) x = MaxPooling2D(pool_size=2, strides=2, name='Pool1')(x) x = Dropout(rate=0.99, name='D1')(x) - + x = Conv2D(40, (3, 3), name='Conv2', activation='relu')(x) x = MaxPooling2D(pool_size=2, strides=2, name='Pool2')(x) x = Dropout(rate=0.99, name='D2')(x) - + x = Conv2D(60, (3, 3), name='Conv3', activation='relu')(x) x = MaxPooling2D(pool_size=2, strides=2, name='Pool3')(x) x = Dropout(rate=0.99, name='D3')(x) - + x1 = Flatten()(x) fc11 = Dense(160, name = 'fc11')(x1) - + x2 = Conv2D(80, (2, 2), name='Conv4', activation='relu')(x) x2 = Flatten()(x2) fc12 = Dense(160, name = 'fc12')(x2) - + y = Add()([fc11, fc12]) y = Activation('relu', name = 'deepid')(y) - + model = Model(inputs=[myInput], outputs=y) #--------------------------------- - + home = str(Path.home()) - + if os.path.isfile(home+'/.deepface/weights/deepid_keras_weights.h5') != True: print("deepid_keras_weights.h5 will be downloaded...") - + output = home+'/.deepface/weights/deepid_keras_weights.h5' gdown.download(url, output, quiet=False) - - model.load_weights(home+'/.deepface/weights/deepid_keras_weights.h5') - - return model \ No newline at end of file + + model.load_weights(home+'/.deepface/weights/deepid_keras_weights.h5') + + return model diff --git a/deepface/basemodels/Facenet.py b/deepface/basemodels/Facenet.py index 1f11325..2b7c6cc 100644 --- a/deepface/basemodels/Facenet.py +++ b/deepface/basemodels/Facenet.py @@ -21,7 +21,7 @@ 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) @@ -42,7 +42,7 @@ def InceptionResNetV2(): 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) @@ -68,7 +68,7 @@ def InceptionResNetV2(): 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) @@ -93,7 +93,7 @@ def InceptionResNetV2(): 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) @@ -118,7 +118,7 @@ def InceptionResNetV2(): 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) @@ -143,7 +143,7 @@ def InceptionResNetV2(): 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) @@ -205,7 +205,7 @@ def InceptionResNetV2(): 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) @@ -224,7 +224,7 @@ def InceptionResNetV2(): 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) @@ -243,7 +243,7 @@ def InceptionResNetV2(): 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) @@ -262,7 +262,7 @@ def InceptionResNetV2(): 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) @@ -281,7 +281,7 @@ def InceptionResNetV2(): 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) @@ -299,8 +299,8 @@ def InceptionResNetV2(): 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) - + 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) @@ -319,7 +319,7 @@ def InceptionResNetV2(): 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) @@ -338,7 +338,7 @@ def InceptionResNetV2(): 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) @@ -357,7 +357,7 @@ def InceptionResNetV2(): 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) @@ -377,7 +377,7 @@ def InceptionResNetV2(): x = add([x, up]) x = Activation('relu', name='Block17_10_Activation')(x) - # Mixed 7a (Reduction-B block): 8 x 8 x 2080 + # 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) @@ -404,7 +404,7 @@ def InceptionResNetV2(): 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) @@ -423,7 +423,7 @@ def InceptionResNetV2(): 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) @@ -442,7 +442,7 @@ def InceptionResNetV2(): 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) @@ -461,7 +461,7 @@ def InceptionResNetV2(): 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) @@ -480,7 +480,7 @@ def InceptionResNetV2(): 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) @@ -499,7 +499,7 @@ def InceptionResNetV2(): 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) @@ -517,7 +517,7 @@ def InceptionResNetV2(): 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) @@ -530,23 +530,25 @@ def InceptionResNetV2(): return model -def loadModel(url = 'https://drive.google.com/uc?id=1971Xk5RwedbudGgTIrGAL4F7Aifu7id1'): +#url = 'https://drive.google.com/uc?id=1971Xk5RwedbudGgTIrGAL4F7Aifu7id1' + +def loadModel(url = 'https://github.com/serengil/deepface_models/releases/download/v1.0/facenet_weights.h5'): model = InceptionResNetV2() - + #----------------------------------- - + home = str(Path.home()) - + if os.path.isfile(home+'/.deepface/weights/facenet_weights.h5') != True: print("facenet_weights.h5 will be downloaded...") - + output = home+'/.deepface/weights/facenet_weights.h5' gdown.download(url, output, quiet=False) - + #----------------------------------- - + model.load_weights(home+'/.deepface/weights/facenet_weights.h5') - + #----------------------------------- - - return model \ No newline at end of file + + return model diff --git a/deepface/basemodels/OpenFace.py b/deepface/basemodels/OpenFace.py index eb63812..afd8bbe 100644 --- a/deepface/basemodels/OpenFace.py +++ b/deepface/basemodels/OpenFace.py @@ -13,7 +13,9 @@ from tensorflow.keras import backend as K #--------------------------------------- -def loadModel(url = 'https://drive.google.com/uc?id=1LSe1YCV1x-BfNnfb7DFZTNpv_Q9jITxn'): +#url = 'https://drive.google.com/uc?id=1LSe1YCV1x-BfNnfb7DFZTNpv_Q9jITxn' + +def loadModel(url = 'https://github.com/serengil/deepface_models/releases/download/v1.0/openface_weights.h5'): myInput = Input(shape=(96, 96, 3)) x = ZeroPadding2D(padding=(3, 3), input_shape=(96, 96, 3))(myInput) @@ -229,19 +231,19 @@ def loadModel(url = 'https://drive.google.com/uc?id=1LSe1YCV1x-BfNnfb7DFZTNpv_Q9 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...") - + output = home+'/.deepface/weights/openface_weights.h5' gdown.download(url, output, quiet=False) - + #----------------------------------- - + model.load_weights(home+'/.deepface/weights/openface_weights.h5') - + #----------------------------------- - - return model \ No newline at end of file + + return model diff --git a/deepface/basemodels/VGGFace.py b/deepface/basemodels/VGGFace.py index 1e13aa9..720fed1 100644 --- a/deepface/basemodels/VGGFace.py +++ b/deepface/basemodels/VGGFace.py @@ -12,7 +12,7 @@ else: from tensorflow import keras from tensorflow.keras.models import Model, Sequential from tensorflow.keras.layers import Input, Convolution2D, ZeroPadding2D, MaxPooling2D, Flatten, Dense, Dropout, Activation - + #--------------------------------------- def baseModel(): @@ -60,34 +60,31 @@ def baseModel(): model.add(Convolution2D(2622, (1, 1))) model.add(Flatten()) model.add(Activation('softmax')) - + return model -def loadModel(url = 'https://drive.google.com/uc?id=1CPSeum3HpopfomUEK1gybeuIVoeJT_Eo'): - +#url = 'https://drive.google.com/uc?id=1CPSeum3HpopfomUEK1gybeuIVoeJT_Eo' + +def loadModel(url = 'https://github.com/serengil/deepface_models/releases/download/v1.0/vgg_face_weights.h5'): + model = baseModel() - + #----------------------------------- - + home = str(Path.home()) output = home+'/.deepface/weights/vgg_face_weights.h5' - + if os.path.isfile(output) != True: - print("vgg_face_weights.h5 will be downloaded...") + print("vgg_face_weights.h5 will be downloaded...") gdown.download(url, output, quiet=False) - + #----------------------------------- - try: - model.load_weights(output) - except Exception as err: - print(str(err)) - print("Pre-trained weight could not be loaded.") - print("You might try to download the pre-trained weights from the url ", url, " and copy it to the ", output) - + model.load_weights(output) + #----------------------------------- - + #TO-DO: why? vgg_face_descriptor = Model(inputs=model.layers[0].input, outputs=model.layers[-2].output) - - return vgg_face_descriptor \ No newline at end of file + + return vgg_face_descriptor diff --git a/deepface/extendedmodels/Age.py b/deepface/extendedmodels/Age.py index b8f0561..f2ee1e1 100644 --- a/deepface/extendedmodels/Age.py +++ b/deepface/extendedmodels/Age.py @@ -16,7 +16,9 @@ elif tf_version == 2: from tensorflow.keras.models import Model, Sequential from tensorflow.keras.layers import Convolution2D, Flatten, Activation -def loadModel(url = 'https://drive.google.com/uc?id=1YCox_4kJ-BYeXq27uUbasu--yz28zUMV'): +#url = 'https://drive.google.com/uc?id=1YCox_4kJ-BYeXq27uUbasu--yz28zUMV' + +def loadModel(url = 'https://github.com/serengil/deepface_models/releases/download/v1.0/age_model_weights.h5'): model = VGGFace.baseModel() diff --git a/deepface/extendedmodels/Emotion.py b/deepface/extendedmodels/Emotion.py index 9baaa38..447be74 100644 --- a/deepface/extendedmodels/Emotion.py +++ b/deepface/extendedmodels/Emotion.py @@ -15,7 +15,9 @@ elif tf_version == 2: from tensorflow.keras.models import Model, Sequential from tensorflow.keras.layers import Conv2D, MaxPooling2D, AveragePooling2D, Flatten, Dense, Dropout -def loadModel(url = 'https://drive.google.com/uc?id=13iUHHP3SlNg53qSuQZDdHDSDNdBP9nwy'): +#url = 'https://drive.google.com/uc?id=13iUHHP3SlNg53qSuQZDdHDSDNdBP9nwy' + +def loadModel(url = 'https://github.com/serengil/deepface_models/releases/download/v1.0/facial_expression_model_weights.h5'): num_classes = 7 @@ -52,15 +54,18 @@ def loadModel(url = 'https://drive.google.com/uc?id=13iUHHP3SlNg53qSuQZDdHDSDNdB if os.path.isfile(home+'/.deepface/weights/facial_expression_model_weights.h5') != True: print("facial_expression_model_weights.h5 will be downloaded...") - #TO-DO: upload weights to google drive + output = home+'/.deepface/weights/facial_expression_model_weights.h5' + gdown.download(url, output, quiet=False) - #zip + """ + #google drive source downloads zip output = home+'/.deepface/weights/facial_expression_model_weights.zip' gdown.download(url, output, quiet=False) #unzip facial_expression_model_weights.zip with zipfile.ZipFile(output, 'r') as zip_ref: zip_ref.extractall(home+'/.deepface/weights/') + """ model.load_weights(home+'/.deepface/weights/facial_expression_model_weights.h5') diff --git a/deepface/extendedmodels/Gender.py b/deepface/extendedmodels/Gender.py index dff11ff..80fb9f1 100644 --- a/deepface/extendedmodels/Gender.py +++ b/deepface/extendedmodels/Gender.py @@ -14,7 +14,9 @@ elif tf_version == 2: from tensorflow.keras.models import Model, Sequential from tensorflow.keras.layers import Convolution2D, Flatten, Activation -def loadModel(url = 'https://drive.google.com/uc?id=1wUXRVlbsni2FN9-jkS_f4UTUrm1bRLyk'): +#url = 'https://drive.google.com/uc?id=1wUXRVlbsni2FN9-jkS_f4UTUrm1bRLyk' + +def loadModel(url = 'https://github.com/serengil/deepface_models/releases/download/v1.0/gender_model_weights.h5'): model = VGGFace.baseModel() diff --git a/deepface/extendedmodels/Race.py b/deepface/extendedmodels/Race.py index 4a94332..20059b7 100644 --- a/deepface/extendedmodels/Race.py +++ b/deepface/extendedmodels/Race.py @@ -16,7 +16,9 @@ elif tf_version == 2: from tensorflow.keras.models import Model, Sequential from tensorflow.keras.layers import Convolution2D, Flatten, Activation -def loadModel(url = 'https://drive.google.com/uc?id=1nz-WDhghGQBC4biwShQ9kYjvQMpO6smj'): +#url = 'https://drive.google.com/uc?id=1nz-WDhghGQBC4biwShQ9kYjvQMpO6smj' + +def loadModel(url = 'https://github.com/serengil/deepface_models/releases/download/v1.0/race_model_single_batch.h5'): model = VGGFace.baseModel() @@ -41,13 +43,18 @@ def loadModel(url = 'https://drive.google.com/uc?id=1nz-WDhghGQBC4biwShQ9kYjvQMp if os.path.isfile(home+'/.deepface/weights/race_model_single_batch.h5') != True: print("race_model_single_batch.h5 will be downloaded...") - #zip + output = home+'/.deepface/weights/race_model_single_batch.h5' + gdown.download(url, output, quiet=False) + + """ + #google drive source downloads zip output = home+'/.deepface/weights/race_model_single_batch.zip' gdown.download(url, output, quiet=False) #unzip race_model_single_batch.zip with zipfile.ZipFile(output, 'r') as zip_ref: zip_ref.extractall(home+'/.deepface/weights/') + """ race_model.load_weights(home+'/.deepface/weights/race_model_single_batch.h5')