使用ibmq qiskit库的多类量子svm用于面部检测

A support vector machine (SVM) is a supervised machine learning model that uses classification algorithms for two-group classification problems most of the time.

支持向量机(SVM)是一种监督型机器学习模型,该模型大多数时候使用分类算法解决两组分类问题。

The basics of Support Vector Machines and how it works are best understood with a simple example. Let’s imagine we have two data labels: cat and dog, and our data has two features: color and position. We want a classifier that, given a pair of (color, position) coordinates, outputs if it’s either cat or dog. A support vector machine takes these data points and outputs the hyperplane (decision boundaries that help classify the data points) that best separates the tags. This line is the decision boundary: anything that falls to one side of it we will classify as a dog, and anything that falls to the other as a cat.

通过一个简单的示例,可以最好地理解支持向量机的基础知识及其工作方式。 假设我们有两个数据标签:cat和dog,而我们的数据具有两个功能:颜色和位置。 我们想要一个分类器,给定一对(颜色,位置)坐标,如果它是猫还是狗,则输出。 支持向量机获取这些数据点并输出最能分隔标签的超平面(有助于对数据点进行分类的决策边界)。 这条线是决策的边界:落在它一侧的任何东西我们都将归为狗,而落到另一侧的任何东西都将归为猫。

Image for post
SVM- optimal hyperplane classifying binary classes in datasets
SVM-最佳超平面分类数据集中的二进制类

But identifying such optimal hyperplane is not easy, that may take several trails to give higher accuracy when the classification data has only two groups of classes, the hyperplane constraint will be simple and but in cases, with three or more classes the Power of SVM is triggered or challenged.

但是识别这样的最优超平面并不容易,当分类数据只有两组类别时,可能要花几条路才能提供更高的准确性,超平面约束会很简单,但是在具有三个或更多类别的情况下,SVM的强大功能被触发或挑战。

Quantum Machine Learning is the analysis of classical data and quantum states on a quantum computer. The whole essence of it is being able to compute immense quantities of data more intelligently and quickly, providing the computational advantage of classifying objects too complex for classical computers and more thorough data analysis.

量子机器学习是在量子计算机上分析经典数据和量子状态。 它的全部本质是能够更智能,更快速地计算大量数据,从而提供了对对象进行分类的计算优势,而这些对象对于传统计算机而言过于复杂,并且无法进行更彻底的数据分析。

The quantum SVM algorithm takes the classical machine learning algorithm and performs the support vector machine on a quantum circuit in order to be efficiently processed on a quantum computer.

量子SVM算法采用经典的机器学习算法,并在量子电路上执行支持向量机,以便在量子计算机上进行有效处理。

Here, I had tried to implement Quantum Support Vector Machine for classifying binary-class data and multi class data. For, binary-class data the QSVM gave 100% accuracy when comparing with multi class QSVM.

在这里,我试图实现Quantum Support Vector Machine来对二进制数据和多数据分类。 对于二进制类数据,与多类QSVM相比,QSVM的准确性为100%。

The dataset I had chosen is Olivetti faces dataset. There are ten different images of each of 40 distinct persons. For some person, the images were taken at different times, varying the lighting, facial expressions (open/closed eyes, smiling/not smiling) and facial details (glasses/no glasses). All the images were taken against a dark homogeneous background with the subjects in an upright, frontal position (with tolerance for some side movement). The image is quantized to 256 grey levels and stored as unsigned 8-bit integers; the loader will convert these to floating point values on the interval [0, 1], which are easier to work with for many algorithms.

我选择的数据集是Olivetti faces数据集。 每个40位不同的人都有10张不同的图像。 对于某些人而言,图像是在不同的时间拍摄的,它们会改变光线,面部表情(睁开/闭眼,微笑/不微笑)和面部细节(眼镜/不戴眼镜)。 所有图像都是在深色均质背景下拍摄的,对象处于直立的,正面的位置(对某些侧向移动具有容忍度)。 图像被量化为256灰度级并存储为无符号的8位整数; 加载程序会将它们转换为间隔[0,1]上的浮点值,对于许多算法而言,它们更易于使用。

The “target” for this database is an integer from 0 to 39 indicating the identity of the person pictured; however, with only 10 examples per class, this relatively small datasets is more interesting from an unsupervised or semi-supervised perspective.

该数据库的“目标”是从0到39的整数,表示被摄人物的身份。 但是,每个类只有10个示例,从无监督或半监督的角度来看,这个相对较小的数据集更加有趣。

Image for post
Import faces datasets
导入面部数据集
Image for post
Olivetti Faces datasets
Olivetti Faces数据集

Setup the Quantum environment by importing qiskit components and data processing on input data to that split into training data, target, class labels are done using sklearn library components.

通过导入qiskit组件和对输入数据的数据处理将数据拆分成训练数据,目标标签和类标签,从而使用sklearn库组件完成设置Quantum环境。

Image for post
Qiskit components for initiating Quantum state and making Quantum Instance
Qiskit组件,用于启动量子状态并创建量子实例

Import Descripion: The BasicAer from qiskit helps in accessing the back-end Quantum devices/ simulators, qiskit.ml.datasets contains example datasets such as Breast caner data and Adhoc data. Qiskit Aqua provides a library of quantum algorithms and components to build quantum applications and leverage near-term devices.

导入描述:qiskit中的BasicAer帮助访问后端Quantum设备/模拟器,qiskit.ml.datasets包含示例数据集,例如乳腺癌数据和Adhoc数据。 Qiskit Aqua提供了一个量子算法和组件库,用于构建量子应用程序并利用近期设备。

Using sklearn library a function called my_new_data(), which takes parameters as training_size, test_size and number of features to be defined to provide classical way of splitting the training and target data.

使用sklearn库,一个名为my_new_data()的函数将参数作为training_size,test_size和要定义的功能数量 提供分割训练数据和目标数据的经典方法。

Image for post

The number of Classes defined in the data processing section deals with the Classification has to be binary or multi class. For, two class QSVM implementation we defined only two classes “0,1” in class labels in the data processing. But it multi-class QSVM we have to give the number of classes as we desired to classify.

在数据处理部分中处理分类的类数必须是二进制或多类。 对于两个类别的QSVM实现,我们在数据处理中的类别标签中仅定义了两个类别“ 0,1”。 但是,对于多类QSVM,我们必须提供想要分类的类数。

Image for post
The left side is the data for binary class QSVM where class labels are 0 and 1 but on right side the QSVM has three classes 0,1 and 2, thus it is multi-class QSVM (We can increase the class numbers so far we want but accuracy is not so good for more classes)
左侧是二进制类QSVM的数据,其中类标签为0和1,但右侧的QSVM具有三个类0,1和2,因此它是多类QSVM(到目前为止,我们可以增加类号但对于更多的课程,准确性不是很好)

Execution on Quantum Device:

量子Device E的xecution:

Image for post
Executing Quantum SVM Algorithm in a Quantum Simulator
在量子模拟器中执行Quantum SVM算法

Feature map,a non-linear transformation function to the data used to find such a hyperplane. It transforms the raw features, or measurable properties, of the phenomenon or subject under study. Classifying in this new feature space — and, as a matter of fact, also in any other space, including the raw original one — is nothing more than seeing how close data points are to each other. This is the same as computing the inner product for each pair of data in the set. In fact we do not need to compute the non-linear feature map for each datum, but only the inner product of each pair of data points in the new feature space. This collection of inner products is called the kernel and it is perfectly possible to have feature maps that are hard to compute but whose kernels are not. QSVM uses a Quantum processor to solve this problem by a direct estimation of the kernel in the feature space. From BasicAer component get the back-end simulator to execute the Quantum Algorithm constructed above.

特征图,一种用于查找此类超平面的数据的非线性变换函数。 它改变了正在研究的现象或主题的原始特征或可测量的特性。 在这个新的特征空间中进行分类,事实上,在任何其他空间中,包括原始原始空间中进行分类,无非就是看到数据点之间的距离。 这与为集合中的每对数据计算内部乘积相同。 实际上,我们不需要为每个数据计算非线性特征图,而只需计算新特征空间中每对数据点的内积。 内部产品的这种集合称为内核 ,完全有可能具有难以计算但其内核没有的特征图。 QSVM使用Quantum处理器通过直接估计特征空间中的内核来解决此问题。 从BasicAer组件获取后端模拟器,以执行上面构造的Quantum Algorithm。

Result from the above is:

从上述R esult是:

Image for post
Result for binary class QSVM
二进制类QSVM的结果

QSVM will run the binary classification or multi-class classification based on how many classes the data has. If the data has more than 2 classes then a multiclass_extension is required to be supplied. Aqua provides several multiclass_extensions.

QSVM将基于数据具有多少类来运行二进制分类或多分类。 如果数据具有两个以上的类,则需要提供multiclass_extension 。 Aqua提供了几个multiclass_extensions

Image for post
The feature map for multi-class QSVM implementation
多类QSVM实现的功能图

The above multi-class execution is done for three classes, four and more. The Observation brought-up is the accuracy reduces with increase in number of classes to classify using QSVM.

上面的多类执行是针对三个,四个或更多类进行的。 观察的结果是,随着使用QSVM进行分类的数量增加,准确性降低。

Thank you for a read.

感谢您的阅读。

For more research based papers, articles and projects Follow, https://www.researchgate.net/profile/Arthi_Udayakumar https://medium.com/@arthi1996.007

有关更多基于研究的论文,文章和项目, 请访问 https://www.researchgate.net/profile/Arthi_Udayakumar https://medium.com/@arthi1996.007

LinkedIn

领英

翻译自: https://medium.com/quantumcomputingindia/multi-class-quantum-svm-for-face-detection-using-ibmq-qiskit-library-f7d544d50a37

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值