AI art analysis from an existing data file
A PyTorch implementation of a Generative Adversarial Network (GAN) for creating artistic images. This project uses deep learning to generate new artwork based on a training dataset of existing art pieces.
- Custom art dataset handling with automatic image preprocessing
- GAN architecture with Generator and Discriminator networks
- Checkpoint saving and loading functionality
- Art generation from trained models
- Progress tracking with real-time loss reporting
- Error handling and graceful interruption
- Python 3.x
- PyTorch
- torchvision
- Pillow (PIL)
- CUDA-capable GPU (optional, but recommended for faster training)
- Clone this repository
- Install the required packages:
pip install torch torchvision pillow
ArtDataset
: Custom dataset class for loading and preprocessing art imagesGenerator
: Neural network for generating new imagesDiscriminator
: Neural network for discriminating between real and generated images- Training utilities and checkpoint management
- Art generation functionality
Place your training images in a directory (default: "part1") and run:
python your_script.py
The script will:
- Load and preprocess your training images
- Train the GAN for the specified number of epochs
- Save checkpoints at regular intervals
- Generate sample artworks upon completion
You can modify these parameters in the script:
num_epochs
: Number of training epochs (default: 100)batch_size
: Batch size for training (default: 32)latent_dim
: Dimension of the latent space (default: 100)lr
: Learning rate (default: 0.0002)save_interval
: Checkpoint saving frequency (default: 10 epochs)
The generate_art
function can be used to create new artworks:
generate_art(generator, output_dir="generated_artwork", num_images=10)
- Takes random noise as input
- Uses transposed convolutions for upsampling
- Includes batch normalization and ReLU activations
- Outputs 64x64 RGB images
- Processes 64x64 RGB images
- Uses convolutional layers
- Includes LeakyReLU activations and batch normalization
- Outputs probability of input being real
The script includes robust error handling for:
- Image loading failures
- Training interruptions
- General exceptions
Generated artwork will be saved in the specified output directory (default: "generated_artwork") as PNG files.
Checkpoints are automatically saved:
- At specified intervals during training
- In the "checkpoints" directory
- Include both Generator and Discriminator states
- Can be used to resume training or generate art
- Training time varies based on dataset size and hardware
- GPU acceleration recommended for optimal performance
- Memory usage scales with batch size
Feel free to submit issues and enhancement requests!