This project implements both hybrid and pure quantum-classical neural networks based on the paper:
"Quantum convolutional neural network for image classification"
Guoming Chen et al., Pattern Analysis and Applications, 2023
The core idea is to use quantum circuits—specifically QCNNs built with MERA (Multi-scale Entanglement Renormalization Ansatz) and a newly added pure QCNN—to extract and process multi-scale features from classical image datasets. This implementation evaluates these models on a binary skin cancer classification task using the ISIC 2018 dataset.
- Implemented in PennyLane + PyTorch
- Two architectures supported:
- Hybrid QCNN using
qml.templates.MERA+ Classical NN - Pure QCNN using layered entanglement and pooling
- Hybrid QCNN using
- Four quantum preprocessing pipelines supported:
- PCA for dimensionality reduction
- HOG (Histogram of Oriented Gradients) for edge-aware features
- PATCH-based encoding to represent local image structures
- FRAC and FRAC with Entropy Map using fractal-based descriptors
- Dataset: ISIC 2018 (binary classification: benign vs malignant)
- Public dataset for skin lesion diagnosis
- This project elaborates the task to multiclass classification:
- Images are preprocessed using resizing, grayscale conversion, and contrast normalization.
- Label balancing and data augmentation (e.g., flipping) are optionally applied.
- Input image is resized and flattened.
- PCA is applied to extract the top
kcomponents (typically 16 or 32). - Each component is scaled to fit the input range of RX, RY, RZ rotations.
- These values are then encoded into a fixed-depth MERA circuit.
- Histogram of Oriented Gradients is computed from grayscale input.
- The descriptor is flattened and truncated to the number of qubits used (e.g., 16).
- This forms the quantum feature vector input to the MERA circuit.
- The input image (e.g., 256×256) is divided into fixed-size patches (e.g., 16 patches of 64×64).
- Each patch is flattened and normalized.
- Each patch is encoded separately into a 16-qubit MERA circuit.
- The outputs from all patches are concatenated to form a complete quantum feature vector.
- Fractal-based entropy and slope values computed per image.
- Features are enriched using local entropy maps over grid patches.
- Output is a 32-dimensional vector encoded across 32 qubits.
- Based on
qml.templates.MERA - Hierarchically organized layers for multi-scale entanglement
- Uses
qml.qnn.TorchLayerto embed it as the first layer of a PyTorch model - Parameter counts are automatically determined based on:
n_wires: Number of qubitsn_block_wires: Size of the local block (set to 2 for entanglement)
- No classical preprocessing layers; purely quantum convolution and pooling
- Composed of alternating:
- Convolution layers with
IsingXX,IsingYY, andIsingZZgates - Pooling layers with
CNOT+RYrotations
- Convolution layers with
- Controlled reductions across qubit hierarchy: 32 → 16 → 8 → 4
- Final 4 qubits are measured and passed to a classical linear layer
- Also uses
qml.qnn.TorchLayerfor full gradient-based training
- Image → Classical Features (HOG, PCA, PATCH, FRAC)
- Quantum Encoding using
qml.AngleEmbedding - MERA Quantum Circuit → Quantum Feature Vector
- Classical Fully Connected Network → Prediction
![]() |
|---|
| Hybrid quantum NN Architecture |
- Image → Classical Feature Vector (FRAC, FRAC + Entropy)
- Quantum Encoding + Pure QCNN:
- Cluster state initialization (H + CZ)
- Feature encoding (RX, RY, RZ)
- Convolution (Ising gates)
- Pooling (CNOT + RY)
- Final 4 qubits → PauliZ → 4D vector → Linear Layer → Prediction
![]() |
|---|
| Pure Quantum Circuit with Pool and Conv |
- Accuracy, Confusion Matrix, Training Curves
- Robustness (planned)
- Visualizations of quantum circuit and feature flow
![]() |
|---|
![]() |
| Accuracy vs Validation + Confusion matrix (FRAC-20) |
![]() |
|---|
![]() |
| Accuracy vs Validation + Confusion matrix (HOG-MERA) |
![]() |
|---|
![]() |
| Accuracy vs Validation + Confusion matrix (PCA-MERA) |
![]() |
|---|
![]() |
| Accuracy vs Validation + Confusion matrix (PATCH-MERA) |
![]() |
|---|
![]() |
| Accuracy vs Validation + Confusion matrix (QCNN-FRAC) |
![]() |
|---|
![]() |
| Accuracy vs Validation + Confusion matrix (QCNN-FRAC+Entropy) |
![]() |
|---|
![]() |
| Accuracy vs Validation + Confusion matrix (QCNN-HOG) |
![]() |
|---|
![]() |
| Accuracy vs Validation + Confusion matrix (QCNN-PATCH) |
Install dependencies:
pip install -r requirements.txtRun preprocessors:
python3 <preprocessor_dir>/<preprocessor_type>.pyRun hybrid model:
python3 quantum_hybrid_NN/quantum_hybrid_nn_mera.py --batch <batch size> --feature ['PCA', 'HOG', 'PATCH', 'FRAC', 'FRAC_ENTOPY']Run pure model:
python3 quantum_NN/quantum_nn.py --batch <batch size> --feature ['PCA', 'HOG', 'PATCH', 'FRAC', 'FRAC_ENTOPY']
















