Generate beautiful abstract art using neural networks! This project uses deep neural networks to map 2D coordinates to RGB colors, creating unique and mesmerizing artistic patterns.
This project demonstrates how neural networks can be used as creative tools. By training a network to map coordinates to colors, we get infinite varieties of abstract art. Each network creates a unique piece, and you can control the style by adjusting architecture parameters like depth, width, and activation functions.
Tutorial: Making deep neural networks paint to understand how they work
This codebase has been modernized with:
- Python Module (
art_generator.py): Clean, documented, type-annotated code - Command-Line Interface (
generate_art.py): Generate art from the terminal - Animation Support (
animate_art.py,generate_animation.py): Create mesmerizing animated art! ✨ - Modern PyTorch Practices: GPU support (CUDA/MPS), efficient tensor operations
- Better Project Structure: Proper requirements, .gitignore, modular design
- Enhanced Jupyter Notebook: Uses the module, better documentation
- Type Hints: Full type annotations for better IDE support
- Improved Documentation: Comprehensive docstrings and examples
- Python 3.8 or higher
- pip package manager
- Clone the repository:
git clone https://github.com/paraschopra/abstract-art-neural-network.git
cd abstract-art-neural-network- Install dependencies:
pip install -r requirements.txtThat's it! You're ready to generate art.
Generate art with a single command:
# Basic usage - generates a 128x128 image
python generate_art.py
# High resolution with custom output name
python generate_art.py --width 1920 --height 1080 --output my_art.png
# Experiment with architecture
python generate_art.py --neurons 64 --layers 12 --activation ReLU
# Generate multiple images at once
python generate_art.py --batch 10
# Full control
python generate_art.py \
--width 1024 \
--height 768 \
--neurons 32 \
--layers 15 \
--activation Tanh \
--output masterpiece.png \
--show| Option | Description | Default |
|---|---|---|
-W, --width |
Image width in pixels | 128 |
-H, --height |
Image height in pixels | 128 |
-o, --output |
Output filename | Random |
-n, --neurons |
Neurons per hidden layer | 16 |
-l, --layers |
Number of hidden layers | 9 |
-a, --activation |
Activation function (Tanh, ReLU, LeakyReLU, ELU, GELU, Sigmoid) | Tanh |
-b, --batch |
Number of images to generate | 1 |
--device |
Device to use (cpu, cuda, mps) | Auto-detect |
--show |
Display the image | False |
--no-save |
Don't save to disk | False |
Use the module in your own Python scripts:
from art_generator import create_and_generate
import torch.nn as nn
# Generate art
network, image = create_and_generate(
width=512,
height=512,
num_neurons=32,
num_layers=10,
activation=nn.Tanh,
save=True,
output_path="my_art.png"
)
# The network can be reused at different resolutions
from art_generator import generate_image
high_res = generate_image(network, width=1920, height=1080)Generate mesmerizing animated art with multiple effects:
# Morph between two networks
python generate_animation.py --type morph --output morph.gif
# Zoom animation
python generate_animation.py --type zoom --output zoom.mp4 --fps 60
# Rotation animation
python generate_animation.py --type rotate --rotations 2 --output spin.gif
# Wave/pulse effect
python generate_animation.py --type wave --output wave.mp4
# Spiral/vortex effect
python generate_animation.py --type spiral --output vortex.gif
# Panning animation (circular, horizontal, or vertical)
python generate_animation.py --type pan --pan-path circular --output pan.mp4
# Combined effects (rotation + zoom + wave)
python generate_animation.py --type combo --frames 120 --output combo.gif
# High-res animation with custom parameters
python generate_animation.py \
--type rotate \
--width 512 \
--height 512 \
--frames 120 \
--fps 60 \
--neurons 64 \
--layers 12 \
--output masterpiece.mp4| Option | Description | Default |
|---|---|---|
-t, --type |
Animation type (morph, zoom, rotate, wave, spiral, pan, combo) | morph |
-W, --width |
Animation width | 256 |
-H, --height |
Animation height | 256 |
-f, --frames |
Number of frames | 60 |
--fps |
Frames per second | 30 |
-o, --output |
Output file (.gif or .mp4) | Required |
--zoom-start/end |
Zoom range | 1.0 / 0.2 |
--rotations |
Full rotations | 1.0 |
--wave-amplitude |
Wave strength | 0.1 |
--spiral-strength |
Spiral strength | 10.0 |
--pan-path |
Pan type (circular, horizontal, vertical) | circular |
For interactive exploration and experimentation:
jupyter notebook generate-art.ipynbThe notebook includes:
- Quick start guide
- Experiments with network depth and width
- Comparison of different activation functions
- High-resolution generation examples
The system uses a simple but powerful idea:
- Neural Network: A feedforward network takes (x, y) coordinates as input
- Coordinate Mapping: Coordinates are normalized and fed through hidden layers
- Color Output: The network outputs RGB values for each pixel
- Random Initialization: Each network starts with random weights, creating unique art
- Resolution Independent: Generate at any size from the same network
- Fast Generation: GPU-accelerated when available (CUDA or Apple Metal)
- Highly Customizable: Control depth, width, and activation functions
- Deterministic: Same network always produces the same art
- No Training Required: Uses random initialization creatively
abstract-art-neural-network/
├── art_generator.py # Core module with modern Python code
├── generate_art.py # Command-line interface for static art
├── animate_art.py # Animation module with multiple effects
├── generate_animation.py # Command-line interface for animations
├── generate-art.ipynb # Interactive Jupyter notebook
├── requirements.txt # Python dependencies
├── .gitignore # Git ignore patterns
├── README.md # This file
├── IMPROVEMENTS.md # Future enhancement ideas
└── LICENSE # MIT License
- Experiment with activations: ReLU creates sharp edges, Tanh creates smooth gradients
- Deeper networks: More layers (15-30) create more complex patterns
- Wider networks: More neurons (64-128) add detail and variation
- Batch generation: Generate many images and pick your favorites
- High resolution: Networks are resolution-independent - render at any size!
- CPU: ~1 second for 128x128, ~10 seconds for 1080p
- GPU (CUDA): ~0.1 seconds for 128x128, ~1 second for 1080p
- Memory: Minimal - even large networks use <100MB
Contributions are welcome! Check out IMPROVEMENTS.md for ideas on what to work on.
# Clone and install in development mode
git clone https://github.com/paraschopra/abstract-art-neural-network.git
cd abstract-art-neural-network
pip install -e .See IMPROVEMENTS.md for a comprehensive list of potential improvements including:
- Animation support
- Web interface
- Style control and conditioning
- 3D art generation
- And much more!
- Python ≥ 3.8
- PyTorch ≥ 2.0
- NumPy ≥ 1.24
- Matplotlib ≥ 3.7
- Pillow ≥ 10.0
For interactive notebook:
- Jupyter ≥ 1.0
- IPython ≥ 8.12
MIT License - see LICENSE file for details.
If you use this in your research or project, please cite:
@misc{chopra2025abstractart,
author = {Paras Chopra},
title = {Abstract Art Neural Network Generator},
year = {2025},
publisher = {GitHub},
url = {https://github.com/paraschopra/abstract-art-neural-network}
}Made by @paraschopra
- Tutorial article on Towards Data Science
- Thanks to Divyanshu Kalra for optimization suggestions
- Thanks to @AlexisVLRT for contributions
Enjoy creating abstract art! Share your creations with #NeuralArt 🎨


