AttributeError: module 'GhostFaceNets' has no attribute 'NormDense'
Closed this issue · 7 comments
Hello, i try to replicate the training on GhostFaceNets but in the script train.py in line 55:
from inspect import getmembers, isfunction, isclass
custom_objects.update(dict([ii for ii in getmembers(losses) if isfunction(ii[1]) or isclass(ii[1])]))
custom_objects.update({"NormDense": GhostFaceNets.NormDense})
I search in the repository if a can find the implementation of NormDense in GhosFaceNets but i dont see nothing that help me to give a solution of this error. Could you help me ?
the training on GhostFaceNets but in the script train.py in line 55:
from inspect import getmembers, isfunction, isclass
Hi,
I hope this message finds you well.
Please clone the current repo as I recently updated it.
Let me know if this issue still persists.
Hi, Thx for the quick response
I apologies if my writting is not the best, i have already cloned(updated version) of the repository but the error still exists when i try to run the train.py script
I try to implemented the denselayer by myself but doesn't work, here is an example of what try to do:
import tensorflow as tf
from tensorflow.keras.layers import Dense, LayerNormalization
from tensorflow import keras
import losses, train, GhostFaceNets
class NormDense(tf.keras.layers.Layer):
def init(self, units, activation=None, **kwargs):
super(NormDense, self).init(**kwargs)
self.units = units
self.activation = tf.keras.activations.get(activation)
self.dense_layer = Dense(units=self.units)
self.norm_layer = LayerNormalization()
def build(self, input_shape):
self.dense_layer.build(input_shape)
self.norm_layer.build(input_shape[-1:])
super(NormDense, self).build(input_shape)
def call(self, inputs):
x = self.dense_layer(inputs)
x = self.norm_layer(x)
if self.activation is not None:
x = self.activation(x)
return x
data_path = '/content/drive/MyDrive/faces_umd_112x112_folders'
eval_paths = ['/content/drive/MyDrive/faces_umd/lfw.bin', '/content/drive/MyDrive/faces_umd/cfp_fp.bin', '/content/drive/MyDrive/faces_umd/agedb_30.bin']
basic_model = GhostFaceNets.buildin_models("ghostnetv2", dropout=0, emb_shape=512, output_layer='GDC', bn_momentum=0.9, bn_epsilon=1e-5)
basic_model = GhostFaceNets.replace_ReLU_with_PReLU(basic_model)
for layer in basic_model.layers:
if isinstance(layer, Dense):
norm_dense = NormDense(units=layer.units, activation=layer.activation)
basic_model = tf.keras.Sequential([norm_dense])
else:
basic_model = tf.keras.Sequential([layer])
basic_model = GhostFaceNets.add_l2_regularizer_2_model(basic_model, weight_decay=5e-4, apply_to_batch_normal=False)
tt = train.Train(data_path, eval_paths=eval_paths,
save_path='ghostnetv1_w1.3_s2.h5', basic_model=basic_model, model=None,
lr_base=0.1, lr_decay=0.5, lr_decay_steps=45, lr_min=1e-5,
batch_size=128, random_status=0, eval_freq=1, output_weight_decay=1)
optimizer = keras.optimizers.SGD(learning_rate=0.1, momentum=0.9)
sch = [
{"loss": losses.ArcfaceLoss(scale=32), "epoch": 1, "optimizer": optimizer},
{"loss": losses.ArcfaceLoss(scale=64), "epoch": 50},
]
tt.train(sch, 0)
Hi, Thx for the quick response
I apologies if my writting is not the best, i have already cloned(updated version) of the repository but the error still exists when i try to run the train.py script
I try to implemented the denselayer by myself but doesn't work, here is an example of what try to do:
import tensorflow as tf from tensorflow.keras.layers import Dense, LayerNormalization from tensorflow import keras import losses, train, GhostFaceNets
class NormDense(tf.keras.layers.Layer): def init(self, units, activation=None, **kwargs): super(NormDense, self).init(**kwargs) self.units = units self.activation = tf.keras.activations.get(activation) self.dense_layer = Dense(units=self.units) self.norm_layer = LayerNormalization()
def build(self, input_shape): self.dense_layer.build(input_shape) self.norm_layer.build(input_shape[-1:]) super(NormDense, self).build(input_shape) def call(self, inputs): x = self.dense_layer(inputs) x = self.norm_layer(x) if self.activation is not None: x = self.activation(x) return x
data_path = '/content/drive/MyDrive/faces_umd_112x112_folders' eval_paths = ['/content/drive/MyDrive/faces_umd/lfw.bin', '/content/drive/MyDrive/faces_umd/cfp_fp.bin', '/content/drive/MyDrive/faces_umd/agedb_30.bin']
basic_model = GhostFaceNets.buildin_models("ghostnetv2", dropout=0, emb_shape=512, output_layer='GDC', bn_momentum=0.9, bn_epsilon=1e-5) basic_model = GhostFaceNets.replace_ReLU_with_PReLU(basic_model)
for layer in basic_model.layers: if isinstance(layer, Dense): norm_dense = NormDense(units=layer.units, activation=layer.activation) basic_model = tf.keras.Sequential([norm_dense]) else: basic_model = tf.keras.Sequential([layer])
basic_model = GhostFaceNets.add_l2_regularizer_2_model(basic_model, weight_decay=5e-4, apply_to_batch_normal=False)
tt = train.Train(data_path, eval_paths=eval_paths, save_path='ghostnetv1_w1.3_s2.h5', basic_model=basic_model, model=None, lr_base=0.1, lr_decay=0.5, lr_decay_steps=45, lr_min=1e-5, batch_size=128, random_status=0, eval_freq=1, output_weight_decay=1)
optimizer = keras.optimizers.SGD(learning_rate=0.1, momentum=0.9) sch = [ {"loss": losses.ArcfaceLoss(scale=32), "epoch": 1, "optimizer": optimizer}, {"loss": losses.ArcfaceLoss(scale=64), "epoch": 50}, ] tt.train(sch, 0)
I will check this and let you know real quick.
Hi, Thx for the quick response
I apologies if my writting is not the best, i have already cloned(updated version) of the repository but the error still exists when i try to run the train.py script
I try to implemented the denselayer by myself but doesn't work, here is an example of what try to do:
import tensorflow as tf from tensorflow.keras.layers import Dense, LayerNormalization from tensorflow import keras import losses, train, GhostFaceNets
class NormDense(tf.keras.layers.Layer): def init(self, units, activation=None, **kwargs): super(NormDense, self).init(**kwargs) self.units = units self.activation = tf.keras.activations.get(activation) self.dense_layer = Dense(units=self.units) self.norm_layer = LayerNormalization()
def build(self, input_shape): self.dense_layer.build(input_shape) self.norm_layer.build(input_shape[-1:]) super(NormDense, self).build(input_shape) def call(self, inputs): x = self.dense_layer(inputs) x = self.norm_layer(x) if self.activation is not None: x = self.activation(x) return x
data_path = '/content/drive/MyDrive/faces_umd_112x112_folders' eval_paths = ['/content/drive/MyDrive/faces_umd/lfw.bin', '/content/drive/MyDrive/faces_umd/cfp_fp.bin', '/content/drive/MyDrive/faces_umd/agedb_30.bin']
basic_model = GhostFaceNets.buildin_models("ghostnetv2", dropout=0, emb_shape=512, output_layer='GDC', bn_momentum=0.9, bn_epsilon=1e-5) basic_model = GhostFaceNets.replace_ReLU_with_PReLU(basic_model)
for layer in basic_model.layers: if isinstance(layer, Dense): norm_dense = NormDense(units=layer.units, activation=layer.activation) basic_model = tf.keras.Sequential([norm_dense]) else: basic_model = tf.keras.Sequential([layer])
basic_model = GhostFaceNets.add_l2_regularizer_2_model(basic_model, weight_decay=5e-4, apply_to_batch_normal=False)
tt = train.Train(data_path, eval_paths=eval_paths, save_path='ghostnetv1_w1.3_s2.h5', basic_model=basic_model, model=None, lr_base=0.1, lr_decay=0.5, lr_decay_steps=45, lr_min=1e-5, batch_size=128, random_status=0, eval_freq=1, output_weight_decay=1)
optimizer = keras.optimizers.SGD(learning_rate=0.1, momentum=0.9) sch = [ {"loss": losses.ArcfaceLoss(scale=32), "epoch": 1, "optimizer": optimizer}, {"loss": losses.ArcfaceLoss(scale=64), "epoch": 50}, ] tt.train(sch, 0)
Hi,
Sorry for the late response. Please clone the repo and try again.
I just updated it.
Hi, Thx for the quick response
I apologies if my writting is not the best, i have already cloned(updated version) of the repository but the error still exists when i try to run the train.py script
I try to implemented the denselayer by myself but doesn't work, here is an example of what try to do:
import tensorflow as tf from tensorflow.keras.layers import Dense, LayerNormalization from tensorflow import keras import losses, train, GhostFaceNets
class NormDense(tf.keras.layers.Layer): def init(self, units, activation=None, **kwargs): super(NormDense, self).init(**kwargs) self.units = units self.activation = tf.keras.activations.get(activation) self.dense_layer = Dense(units=self.units) self.norm_layer = LayerNormalization()
def build(self, input_shape): self.dense_layer.build(input_shape) self.norm_layer.build(input_shape[-1:]) super(NormDense, self).build(input_shape) def call(self, inputs): x = self.dense_layer(inputs) x = self.norm_layer(x) if self.activation is not None: x = self.activation(x) return x
data_path = '/content/drive/MyDrive/faces_umd_112x112_folders' eval_paths = ['/content/drive/MyDrive/faces_umd/lfw.bin', '/content/drive/MyDrive/faces_umd/cfp_fp.bin', '/content/drive/MyDrive/faces_umd/agedb_30.bin']
basic_model = GhostFaceNets.buildin_models("ghostnetv2", dropout=0, emb_shape=512, output_layer='GDC', bn_momentum=0.9, bn_epsilon=1e-5) basic_model = GhostFaceNets.replace_ReLU_with_PReLU(basic_model)
for layer in basic_model.layers: if isinstance(layer, Dense): norm_dense = NormDense(units=layer.units, activation=layer.activation) basic_model = tf.keras.Sequential([norm_dense]) else: basic_model = tf.keras.Sequential([layer])
basic_model = GhostFaceNets.add_l2_regularizer_2_model(basic_model, weight_decay=5e-4, apply_to_batch_normal=False)
tt = train.Train(data_path, eval_paths=eval_paths, save_path='ghostnetv1_w1.3_s2.h5', basic_model=basic_model, model=None, lr_base=0.1, lr_decay=0.5, lr_decay_steps=45, lr_min=1e-5, batch_size=128, random_status=0, eval_freq=1, output_weight_decay=1)
optimizer = keras.optimizers.SGD(learning_rate=0.1, momentum=0.9) sch = [ {"loss": losses.ArcfaceLoss(scale=32), "epoch": 1, "optimizer": optimizer}, {"loss": losses.ArcfaceLoss(scale=64), "epoch": 50}, ] tt.train(sch, 0)
Did it work?
Hello
I'm so sorry for my late reply, I just cloned the updated version from the repository and it works. Now I can train the model perfectly, thank you very much for the support and the quick response to the problem. Very useful
Kind regards
I am glad that it works. All the best :).