An implementation of quantum convolutional neural network with MindQuantum. Huawei, classifying MNIST dataset

Overview

关于实现的一点说明


文件说明

  • tools.py 这里面主要有两个函数:

    • resize(a, lenb)

    这其实是我找同学写的一个小算法hhh。给出一个$28\times 28$的方阵a,返回一个$lenb\times lenb$的方阵。因为懒得装openCV,于是手动写了一个把图像降低分辨率的操作,原理是根据几何关系计算新的像素值。总之可以把$28\times28$的MNIST原始数据改成$16\times 16$的,这就可以用8个比特encode了。写的可能比较丑陋,但毕竟只是初始化数据用的,所以能用一次性就行了。

    • controlled_gate(circuit, gate, tqubit, cqubits, zero_qubit)

    这其实是因为我发现mindquantum的受控门不支持“空心受控”,于是我就自己写了个。如果$cqubits=[0,-1,2],zero_qubit=1$就表示第一、三量子比特为1时,第二量子比特为0时,才进行运算。就是用负数表示了“空心受控”,然后zero_qubit单独判断了下第0量子比特。(因为它没有符号)

  • test.py: 主程序,里面写注释了。用来训练和预测。

  • MNIST_params.npy:因为我手动写了个实现amplitude encoding的线路,然后该线路也是有参数的,参数是原始数据的各种复合运算。因为我不知道mindquantum支持参数复合运算的操作,于是我就预处理了下数据,把这些参数都算出来了(针对每个样本)。原始数据是$16\times 16=[0,256)$,但encoder中的参数只有$[0,255)$。所以MNIST_params.npy里的数据的规模是$60000\times 255$的。

  • MNIST_train.npy:$60000\times 256$的原始数据

  • MNIST_train_formalized:$60000\times 256$的原始数据,每行都归一化了,方便encoding。

  • weights.npy:我已经训练好的一组ansatz的参数值,在test.py中有用它来预测。

关于原理的一些说明

  • encoder部分是我自己想的hhh,我想了一个可以实现amplitude encoding的线路。复杂度不高。

  • ansatz我选的是https://arxiv.org/pdf/2108.00661.pdf中讲到的convolutional circuit1:

    cc

    pooling层就比较随意的受控RZ和受控RX门

  • 最后就是基于计算基下测量。

  • 然后就是Adam优化啥的都是自带的好东西,一直train就完事了

You might also like...
Sdf sparse conv - Deep Learning on SDF for Classifying Brain Biomarkers

Deep Learning on SDF for Classifying Brain Biomarkers To reproduce the results f

Bayesian optimisation library developped by Huawei Noah's Ark Library
Bayesian optimisation library developped by Huawei Noah's Ark Library

Bayesian Optimisation Research This directory contains official implementations for Bayesian optimisation works developped by Huawei R&D, Noah's Ark L

Ultra-lightweight human body posture key point CNN model. ModelSize:2.3MB  HUAWEI P40 NCNN benchmark: 6ms/img,
Ultra-lightweight human body posture key point CNN model. ModelSize:2.3MB HUAWEI P40 NCNN benchmark: 6ms/img,

Ultralight-SimplePose Support NCNN mobile terminal deployment Based on MXNET(=1.5.1) GLUON(=0.7.0) framework Top-down strategy: The input image is t

Yolo ros - YOLO-ROS for HUAWEI ATLAS200

YOLO-ROS YOLO-ROS for NVIDIA YOLO-ROS for HUAWEI ATLAS200, please checkout for b

Simulating Sycamore quantum circuits classically using tensor network algorithm.
Simulating Sycamore quantum circuits classically using tensor network algorithm.

Simulating the Sycamore quantum supremacy circuit This repo contains data we have obtained in simulating the Sycamore quantum supremacy circuits with

Implementation of character based convolutional neural network
Implementation of character based convolutional neural network

Character Based CNN This repo contains a PyTorch implementation of a character-level convolutional neural network for text classification. The model a

An implementation of the research paper
An implementation of the research paper "Retina Blood Vessel Segmentation Using A U-Net Based Convolutional Neural Network"

Retina Blood Vessels Segmentation This is an implementation of the research paper "Retina Blood Vessel Segmentation Using A U-Net Based Convolutional

Pytorch implementation of Cut-Thumbnail in the paper Cut-Thumbnail:A Novel Data Augmentation for Convolutional Neural Network.

Cut-Thumbnail (Accepted at ACM MULTIMEDIA 2021) Tianshu Xie, Xuan Cheng, Xiaomin Wang, Minghui Liu, Jiali Deng, Tao Zhou, Ming Liu This is the officia

Random Erasing Data Augmentation. Experiments on CIFAR10, CIFAR100 and Fashion-MNIST
Random Erasing Data Augmentation. Experiments on CIFAR10, CIFAR100 and Fashion-MNIST

Random Erasing Data Augmentation =============================================================== black white random This code has the source code for

Owner
ぼっけなす
やがて、平凡な人になった
ぼっけなす
Code image classification of MNIST dataset using different architectures: simple linear NN, autoencoder, and highway network

Deep Learning for image classification pip install -r http://webia.lip6.fr/~baskiotisn/requirements-amal.txt Train an autoencoder python3 train_auto

Hector Kohler 0 Mar 30, 2022
Learn about quantum computing and algorithm on quantum computing

quantum_computing this repo contains everything i learn about quantum computing and algorithm on quantum computing what is aquantum computing quantum

arfy slowy 8 Dec 25, 2022
This is a model made out of Neural Network specifically a Convolutional Neural Network model

This is a model made out of Neural Network specifically a Convolutional Neural Network model. This was done with a pre-built dataset from the tensorflow and keras packages. There are other alternative libraries that can be used for this purpose, one of which is the PyTorch library.

null 9 Oct 18, 2022
Extract MNIST handwritten digits dataset binary file into bmp images

MNIST-dataset-extractor Extract MNIST handwritten digits dataset binary file into bmp images More info at http://yann.lecun.com/exdb/mnist/ Dependenci

Omar Mostafa 6 May 24, 2021
Attention mechanism with MNIST dataset

[TensorFlow] Attention mechanism with MNIST dataset Usage $ python run.py Result Training Loss graph. Test Each figure shows input digit, attention ma

YeongHyeon Park 12 Jun 10, 2022
PyTorch experiments with the Zalando fashion-mnist dataset

zalando-pytorch PyTorch experiments with the Zalando fashion-mnist dataset Project Organization ├── LICENSE ├── Makefile <- Makefile with co

Federico Baldassarre 31 Sep 25, 2021
Cluttered MNIST Dataset

Cluttered MNIST Dataset A setup script will download MNIST and produce mnist/*.t7 files: luajit download_mnist.lua Example usage: local mnist_clutter

DeepMind 50 Jul 12, 2022
Classifying audio using Wavelet transform and deep learning

Audio Classification using Wavelet Transform and Deep Learning A step-by-step tutorial to classify audio signals using continuous wavelet transform (C

Aditya Dutt 17 Nov 29, 2022
Rafael Project- Classifying rockets to different types using data science algorithms.

Rocket-Classify Rafael Project- Classifying rockets to different types using data science algorithms. In this project we received data base with data

Hadassah Engel 5 Sep 18, 2021
Matplotlib Image labeller for classifying images

mpl-image-labeller Use Matplotlib to label images for classification. Works anywhere Matplotlib does - from the notebook to a standalone gui! For more

Ian Hunt-Isaak 5 Sep 24, 2022