DeepTrackAI / deeplay

Other
5 stars 6 forks source link

DCGAN model #45

Closed HarshithBachimanchi closed 11 months ago

HarshithBachimanchi commented 11 months ago

This PR introduces DCGAN architectures into deeplay. The models are implemented as described in the original DCGAN article (link).

Example:

Creating DCGAN generator

generator = dl.DcganGenerator(
    latent_dim=100,
    features_dim=64,
    output_channels=1,
    class_conditioned_model=False,
    num_classes=10, # only used if class_conditioned_model=True
    embedding_dim=100, # only used if class_conditioned_model=True
)

Creating DCGAN discriminator

discriminator = dl.DcganDiscriminator(
    input_channels=1,
    features_dim=64,
    class_conditioned_model=False,
    num_classes=10,  # only used if class_conditioned_model=True
    embedding_dim=100,  # only used if class_conditioned_model=True
)

As DCGAN is a fixed architecture, the images need to be resized to 64 x 64 before passing through the models. The number of Conv blocks in discriminator and the ConvTranspose blocks in the generator are fixed to 4 as per the paper. However, the number of features in each block can be controlled by changing the features_dim attribute.

For generator, number of features in each ConvTranspose block goes as [features_dim*16, features_dim*8, features_dim*4, features_dim*2]

For discriminator, the number of features in each Conv block goes by [features_dim, features_dim*2, features_dim*4, features_dim*8].

By changing the features_dim parameter, the relative strength of generator and discriminator can be controlled.

BenjaminMidtvedt commented 11 months ago

I think it's looking good now, nice work! I'm good to merge