deepfakes / faceswap

Deepfakes Software For All
https://www.faceswap.dev
GNU General Public License v3.0
51.46k stars 13.14k forks source link

Configurable NN Layers #100

Closed gdunstone closed 6 years ago

gdunstone commented 6 years ago

I want to add a cli parameter for NN layers, but I don't know how to tweak that within the model plugins.

I think its here: https://github.com/deepfakes/faceswap/blob/68ef3b992674d87d0c73da9c29a4c5a0e735f04b/plugins/Model_Original.py#L48

This is my rough draft of the encoder...

    def Encoder(self):
        input_ = Input(shape=IMAGE_SHAPE)
        x = input_
        for p2 in range(8, self.nn_layers+8):
            x = self.conv(pow(2, p2))(x)
        x = Dense(ENCODER_DIM)(Flatten()(x))
        x = Dense(4 * 4 * 1024)(x) # does this need to change? 
        x = Reshape((4, 4, 1024))(x) # and this?
        x = self.upscale(512)(x)
        return KerasModel(input_, x)
Clorr commented 6 years ago

I am not in favor of letting end user changing this. Because generated model files won't be reloadable if the parameters change. If someone more advanced wants to play with these, it is possible but he will change parameters directly.

gdunstone commented 6 years ago

That sounds perfectly fine reasoning to me. If I did want to do it, is what I did above the correct way to do it?

Clorr commented 6 years ago

Actually, there is no "correct" shape for the NN. The shape of each layer, and the global shape of the network can be almost whatever you want. The shape is to be tweaked until you get a result corresponding to what you expect.

After that I'm not experienced enough to tell you if there is a flaw in what you suggest. You should try and see what you get from it ;-)

flip1995 commented 6 years ago

I don't think a configuration where you can only configure the amount of conv-layers would be helpful.

Just adding conv-layers probably won't improve the model. Considering the current IMAGE_SHAPE and as of how the conv-layers are constructed, the input for the layer x = self.conv(1024)(x) has the shape (8, 8, 512) and the output the shape (4, 4, 1024). Learning features of the size 2x2 pixel in following conv-layers probably won't do anything if not worsen the NN.

Tweaking the NN with pooling-layers or changing the strides and kernel_sizes of the conv-layers would be the better approach here (Besides other common tweaks for NNs, like dropout, ...). But that is always trial and error.

But as @Clorr already mentioned this is something only advanced users would do and a config parameter for that would be more complex, than just changing the code.

gdunstone commented 6 years ago

Thanks so much for all your help, I'll have a play around with it and see how it goes.