A personal toolkit for Generative Adversarial Networks (GANs) in PyTorch.
- Modular Architecture: Easily extendable codebase with separate modules for datasets, models, trainers, and utilities.
- Flexible Data Loading: Supports various datasets with customizable transformations.
- Docker Support: Containerized environment for consistent deployment.
- Configuration Management: YAML configuration files for easy hyperparameter tuning and experiment management.
- Unit Testing: Comprehensive tests for reliability and robustness.
- Logging and Visualization: Integrated logging with TensorBoard support for monitoring training progress.
- Operating System: Linux, macOS, or Windows
- Python: Version 3.6 or higher
- PyTorch: Version 1.9.0 or higher
- CUDA: For GPU support (optional)
- Git: Version control system
- Docker: For containerization (optional)
-
Clone the Repository
git clone https://github.com/yourusername/gan-toolkit.git cd gan-toolkit
It's recommended to use a virtual environment to manage project dependencies.
It's recommended to use a virtual environment to manage project dependencies and prevent conflicts with other projects on your system.
# For Linux/macOS
python3 -m venv venv
# For Windows
python -m venv venvpip install --upgrade pippip install -r requirements.txtpip listThis should display all the packages listed in requirements.txt.
We provide scripts to download datasets. By default, the project uses the Cervical Cancer (Kaggle) dataset.
-
Set Up Kaggle API Credentials
- Sign in to Kaggle.
- Go to your account settings and select "Create New API Token". This will download a
kaggle.jsonfile.
-
Place the
kaggle.jsonfile in the appropriate directory:- Linux/macOS:
~/.kaggle/kaggle.json - Windows:
C:\Users\<YourUsername>\.kaggle\kaggle.json
- Linux/macOS:
-
Ensure the file has the correct permissions:
chmod 600 ~/.kaggle/kaggle.json -
Download the Dataset: Run the data download script:
python scripts/download_data.py
Note: The dataset will be downloaded to the data/ directory by default.
If you prefer to use your own dataset:
Place your dataset in the data/ directory with the following structure:
data/
└── your_dataset_name/
├── class1/
│ ├── image1.jpg
│ ├── image2.jpg
│ └── ...
└── class2/
├── image3.jpg
├── image4.jpg
└── ...Edit the configs/config.yaml file:
data:
dataset_path: './data/your_dataset_name'
# ... other configurationsAll configurable parameters are stored in configs/config.yaml. Adjust hyperparameters, paths, and other settings as needed.
data:
dataset_path: './data/cervical-cancer-dataset'
image_size: 64
batch_size: 128
num_workers: 4
image_channels: 3
mean: [0.5, 0.5, 0.5]
std: [0.5, 0.5, 0.5]
training:
num_epochs: 25
learning_rate: 0.0002
batch_size: 128
latent_dim: 100
model:
name: 'dcgan'
latent_dim: 100
feature_d: 64
feature_g: 64
sample_dir: 'samples'
model_dir: 'models'Run the training script with the desired configuration:
python src/main.py --config configs/config.yamlFor an interactive demonstration, use the provided Jupyter notebook:
jupyter notebookNavigate to notebooks/gan_example.ipynb and open it.
Ensure that the notebook can access the project modules by adjusting the system path if necessary:
import sys
sys.path.append('../')Execute the cells sequentially to see the model in action.
Follow the official Docker installation guide for your operating system:
- Windows and macOS: Docker Desktop
- Linux: Docker Engine
-
Navigate to the project root:
cd /path/to/gan-toolkit -
Build the Docker image:
docker build -t gan-toolkit .
docker run --gpus all -v $(pwd):/app gan-toolkit--gpus all: Enables GPU access inside the container (requires NVIDIA Docker support).-v $(pwd):/app: Mounts the current directory into the container.
-
Set up the repository:
distribution=$(. /etc/os-release;echo $ID$VERSION_ID) \ && curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add - \ && curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list
-
Install the NVIDIA Container Toolkit:
sudo apt-get update && sudo apt-get install -y nvidia-container-toolkit sudo systemctl restart docker
docker run --runtime=nvidia -v $(pwd):/app gan-toolkitWe use pytest for unit testing.
pytest tests/Tests are located in the tests/ directory.
Follow the existing examples to add new tests.
Ensure your tests cover:
- Data loading
- Model initialization
- Training steps
- Utility functions
We welcome contributions! Please read CONTRIBUTING.md for details on our code of conduct and the process for submitting pull requests.
- Fork the repository.
- Create a branch for your feature (
git checkout -b feature/new-feature). - Commit your changes (
git commit -am 'Add new feature'). - Push to the branch (
git push origin feature/new-feature). - Open a Pull Request.
- Follow PEP 8 guidelines.
- Use docstrings to document modules, classes, and methods.
- Add comments to explain complex code segments.
- Write unit tests for new features.
This project is licensed under the MIT License - see the LICENSE file for details.
Your Name
- Email: georgiospathanasiou@yahoo.com
- GitHub: Georgios Athanasiou
Feel free to reach out for any questions or suggestions!
- Inspired by the PyTorch DCGAN tutorial.
- Datasets provided by Kaggle.
Disclaimer: This project is intended for educational purposes. Use it responsibly and adhere to the licensing terms of any datasets or external resources used.