{"id":25952410,"url":"https://github.com/junayed-hasan/quantum-machine-learning","last_synced_at":"2025-03-04T14:51:08.580Z","repository":{"id":207355867,"uuid":"719027131","full_name":"junayed-hasan/Quantum-Machine-Learning","owner":"junayed-hasan","description":"This repository implements knowledge distillation from classical to quantum neural networks for image classification. It includes experiments on MNIST and FashionMNIST datasets, demonstrating improved accuracy in quantum models. Code for classical teachers and quantum students, with baseline and distilled versions, is provided.","archived":false,"fork":false,"pushed_at":"2025-02-23T17:53:07.000Z","size":1785,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-23T18:34:44.795Z","etag":null,"topics":["computer-vision","deep-learning","knowledge-distillation","neural-network","quantum-machine-learning"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/junayed-hasan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-11-15T09:46:19.000Z","updated_at":"2025-02-23T17:53:10.000Z","dependencies_parsed_at":null,"dependency_job_id":"96316ee7-567b-4376-98a2-aac4eaac4e91","html_url":"https://github.com/junayed-hasan/Quantum-Machine-Learning","commit_stats":null,"previous_names":["junayed-hasan/quantum-machine-learning"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/junayed-hasan%2FQuantum-Machine-Learning","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/junayed-hasan%2FQuantum-Machine-Learning/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/junayed-hasan%2FQuantum-Machine-Learning/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/junayed-hasan%2FQuantum-Machine-Learning/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/junayed-hasan","download_url":"https://codeload.github.com/junayed-hasan/Quantum-Machine-Learning/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241868475,"owners_count":20033822,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["computer-vision","deep-learning","knowledge-distillation","neural-network","quantum-machine-learning"],"created_at":"2025-03-04T14:51:07.760Z","updated_at":"2025-03-04T14:51:08.570Z","avatar_url":"https://github.com/junayed-hasan.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Bridging Classical and Quantum Machine Learning \n\n[![arXiv](https://img.shields.io/badge/arXiv-2311.13810-b31b1b.svg)](https://arxiv.org/abs/2311.13810)\n\nThis repository contains the code and experiments for the paper \"Bridging Classical and Quantum Machine Learning: Knowledge Transfer From Classical to Quantum Neural Networks Using Knowledge Distillation\".\n\n---\n\n## Table of Contents\n\n1. [Motivation](#motivation)  \n2. [Architecture and Approach](#architecture-and-approach)  \n   - [Knowledge Distillation Method](#knowledge-distillation-method)  \n   - [Dimensionality Techniques](#dimensionality-techniques)  \n3. [Project Structure](#project-structure)  \n4. [Installation and Setup](#installation-and-setup)  \n5. [Usage](#usage)  \n6. [Experiments](#experiments)  \n   - [MNIST](#mnist)  \n   - [FashionMNIST](#fashionmnist)  \n7. [Results](#results)  \n8. [Citation](#citation)  \n9. [License](#license)  \n\n---\n\n## Motivation\n\nQuantum neural networks have shown promise in surpassing classical neural networks in tasks like image classification when using a similar number of learnable parameters. However, the development and optimization of quantum models face challenges such as qubit instability and limited availability. This project introduces a novel method to transfer knowledge from classical to quantum neural networks using knowledge distillation, effectively bridging the gap between classical machine learning and emerging quantum computing techniques.\n\nOur approach adapts classical convolutional neural network (CNN) architectures like LeNet and AlexNet to serve as teacher networks, facilitating the training of student quantum models. This method yields significant performance improvements for quantum models by solely depending on classical CNNs, eliminating the need for cumbersome training of large quantum models in resource-constrained settings.\n\n---\n\n## Architecture and Approach\n\n### Knowledge Distillation Method\n\nIn our paper, “Bridging Classical and Quantum Machine Learning: Knowledge Transfer From Classical to Quantum Neural Networks Using Knowledge Distillation,” we show how a **frozen classical CNN** (teacher) transfers knowledge to a **smaller quantum network** (student). Below is a high-level diagram illustrating the overall training scheme:\n\n![Quantum-Classical Knowledge Distillation Architecture](ss1.png)\n\nWe compare our **classical-to-quantum** knowledge distillation approach to (1) classical-to-classical and (2) quantum-to-quantum distillation methods:\n\n![Motivation and Different Distillation Strategies](ss2.png)\n\n1. **Teacher Model (Classical, Frozen)**  \n   - Typically a large CNN (e.g., LeNet, AlexNet).  \n2. **Student Model (Quantum, Trainable)**  \n   - A QNN with significantly fewer trainable parameters.  \n3. **Distillation Loss**  \n   - Minimizes KL divergence between teacher’s and student’s output logits.\n\n### Dimensionality Techniques\n\nBecause quantum circuits can only handle a limited number of qubits, we must **reduce input dimensionality** before encoding data into a quantum circuit. We experiment with several strategies:\n\n![Dimensionality Reduction for Quantum Processing](ss3.png)\n\n1. **Fully Connected (Flatten + FC):**  \n   - Flatten the image, project to \\(2^Q\\) features for \\(Q\\) qubits.  \n2. **Average/Max Pooling:**  \n   - Divide the image into \\(2^Q\\) regions and pool values.  \n3. **Center Crop:**  \n   - Crop the central \\(N \\times N\\) patch with \\(N^2 = 2^Q\\).  \n4. **PCA:**  \n   - Use Principal Component Analysis to extract \\(2^Q\\) components.\n\nBelow is an example of the **error rates** for different dimensionality strategies across MNIST, FashionMNIST, and CIFAR10 for 4-qubit and 8-qubit QNNs:\n\n![Error Comparison of Methods](ss4.png)\n\n---\n\n\n## Project Structure\n\n```\n├── MNIST Experiments\n│   ├── Teachers                       # Classical CNN teacher notebooks\n│   ├── Baseline students             # Quantum students without distillation\n│   └── Distillation on students      # Quantum students with knowledge distillation\n├── FashionMNIST Experiments\n│   ├── Teachers\n│   ├── Baseline students\n│   └── Distillation on students\n├── ss1.png                            # Architecture diagram\n├── ss2.png                            # Motivation \u0026 method comparison diagram\n├── ss3.png                            # Dimensionality reduction methods\n├── ss4.png                            # Error comparison chart\n└── README.md                          # You are here!\n```\n\n---\n\n## Installation and Setup\n\nTo run the experiments, you need:\n\n- **Python 3.7 or higher**\n- **PyTorch 1.8 or higher**\n- **Qiskit 0.25 or higher**  \n- **TorchQuantum 0.1.0 or higher**\n- **Jupyter Notebook or Jupyter Lab**\n\n### Quick Installation\n\n```bash\npip install torch            # For PyTorch\npip install qiskit           # For Qiskit\npip install torchquantum     # For TorchQuantum\npip install jupyter          # For notebooks\n```\n\n### Optional: Virtual Environment\n\nIt’s recommended to use a virtual environment:\n```bash\npython -m venv venv\nsource venv/bin/activate  # or venv\\Scripts\\activate on Windows\n```\nThen proceed with the installations within your virtual environment.\n\n---\n\n## Usage\n\n1. **Clone the Repository**  \n   ```bash\n   git clone https://github.com/your_username/quantum-machine-learning.git\n   cd quantum-machine-learning\n   ```\n\n2. **Launch Jupyter**  \n   ```bash\n   jupyter notebook  # or jupyter lab\n   ```\n3. **Open Notebooks**  \n   - `MNIST Experiments` or `FashionMNIST Experiments` notebooks (for classical teacher training, baseline quantum models, and knowledge-distilled quantum models).\n\nIf you prefer **Google Colab**, simply upload the notebooks and select the appropriate runtime.\n\n---\n\n## Experiments\n\n### MNIST\n\n1. **Teachers**  \n   - Train classical CNNs (LeNet, etc.) on MNIST.  \n2. **Baseline Students**  \n   - Train quantum models without using distillation.  \n3. **Distillation on Students**  \n   - Transfer knowledge from the frozen classical teacher to the quantum student.\n\n### FashionMNIST\n\nFollow the same process as MNIST but with FashionMNIST data:\n1. **Teachers**  \n2. **Baseline Students**  \n3. **Distillation on Students**  \n\nThese steps highlight how knowledge distillation improves QNN accuracy across different datasets.\n\n---\n\n## Results\n\n- **MNIST**: Average quantum model accuracy improves by **0.80%** with distillation.  \n- **FashionMNIST**: Average quantum model accuracy improves by **5.40%** with distillation.  \n- **CIFAR10** (in some ablation studies): Also shows enhancement, although absolute performance is more challenging due to dataset complexity.\n\nRefer to the **Error Comparison** chart (`ss4.png`) for a visual summary of various dimensionality reduction strategies and 4-qubit/8-qubit experiments.\n\n---\n\n## Citation\n\nIf you find this repository useful in your research, please consider citing our work:\n\n```bibtex\n@article{hasan2023bridging,\n  title={Bridging Classical and Quantum Machine Learning: Knowledge Transfer From Classical to Quantum Neural Networks Using Knowledge Distillation},\n  author={Hasan, Mohammad Junayed and Mahdy, MRC},\n  journal={arXiv preprint arXiv:2311.13810},\n  year={2023}\n}\n```\n\n---\n\n## License\n\nThis project is licensed under the **MIT License**. See the [LICENSE](LICENSE) file for details.  \n\n**Happy Quantum Coding!** If you have any questions or suggestions, feel free to open an issue or submit a pull request.\n\n\u0026copy; 2025 [Mohammad Junayed Hasan](https://www.linkedin.com/in/mjhasan21/)  \n\n---\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjunayed-hasan%2Fquantum-machine-learning","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjunayed-hasan%2Fquantum-machine-learning","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjunayed-hasan%2Fquantum-machine-learning/lists"}