Code Monkey home page Code Monkey logo

Comments (4)

Luca96 avatar Luca96 commented on September 2, 2024 1

Hi, I've trained my model with Google Colab's GPU for almost 8-10 epochs. I did different trials achieving almost the same accuracy (around 90%).

Anyway, You can try to:

  1. Debug your loaded images: check the pixels' values, see if channels are switched. (are you training on CelebA, right?)
  2. Pretrain on ImageNet:
def mobilenet_model(num_features):
  base = MobileNetV2(input_shape=IMG_SHAPE,
                     weights='imagenet',     # <- 
                     include_top=False,
                     pooling='avg')
  
  # model top
  x = base.output
  x = Dense(1536, activation='relu')(x)
  x = BatchNormalization()(x)
  x = Dropout(0.3)(x)

  top = Dense(num_features, activation='sigmoid')(x)
  return Model(inputs=base.input, outputs=top)
  1. Reduce the strength of data augmentation (or avoid it):
# try with a factor of '0.1' instead of '0.2'
train_datagen = ImageDataGenerator(rotation_range=10, 
                                   rescale=1./255, 
                                   width_shift_range=0.1, 
                                   height_shift_range=0.1, 
                                   shear_range=0.1, 
                                   zoom_range=0.1, 
                                   horizontal_flip=True, 
                                   fill_mode='nearest')
  1. If none of the above works, try a different optimizer (e.g. adam) and/or increase the batch_size to 96 or 128.

Hope it helps.

from face-clustering.

Luca96 avatar Luca96 commented on September 2, 2024 1

Hi, I think that cosine_proximity should be the same as cosine_similarity.

I've noticed you're using keras stuff from tensorflow (I mean tf.keras). So, that's why you cannot find cosine_similarity because it's not defined under the tf.keras namespace. But that's fine.

You can also try to use binary_crossentropy as loss function and see if accuracy improves.

Note: if you import stuff from tf.keras make sure to use it for every keras-related stuff. Because there are some inconsistencies between plain keras imports and tf.keras ones. Also, I'm not aware of the existence of potential performance discrepancies between keras and tf.keras.

from face-clustering.

browarsoftware avatar browarsoftware commented on September 2, 2024 1

Yes! Thank you! This was an issue - after installing keras everythng works fine. I had only to replace 'other' with 'raw', and change batch size to 32:

valid_generator = valid_datagen.flow_from_dataframe(
dataframe=valid_split,
directory=celeba.images_folder,
x_col='image_id',
y_col=celeba.features_name,
target_size=TARGET_SIZE,
batch_size=batch_size,
#class_mode='other'
class_mode='raw'
)

It seems that tf.keras and keras works differently.

from face-clustering.

browarsoftware avatar browarsoftware commented on September 2, 2024

Thank you for the response! :-)

(1) Yes
(2) I have changed weights='imagenet'
(3) I have removed data augmentation:

train_datagen = tf.keras.preprocessing.image.ImageDataGenerator(
rescale=1. / 255,
)

(4) Bigger batch than 64 does not fit into my video memory (as long as I correctly read the exception)

After 32 epoches I obtained 86%.
I run tensorflow 2.1 on GeForce 2600 GTX.

In model.compile I do not have 'cosine_proximity' - this option is unavilable. Instead I use 'cosine_similarity' - is this the same?

from face-clustering.

Related Issues (5)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.