Brain Cancer Classification using a Quantum-Hybrid Classical Model

Abidi Ghofrane
11 min readSep 16, 2021

--

A journey of 3 machine learning students starting on Quantum machine learning to fight cancer.

In the context of finishing our curriculum in Holberton school, students are expected to create a project from scratch, in which we have the freedom of choosing and building our own ideas, using the experience and skills we gathered in Holberton in the last 2 years. So my team picked working on Brain cancer detection and classification using Quantum Machine Learning. I know! It sounds like we’ve done all there is to be done in classic machine learning and moved right up to Quantum. well it wasn’t easy. but it sure was not impossible!

The idea of brain cancer detection presented itself from our own lives and experiences. who doesn’t want to find a cure for cancer? Well, at least from our part, maybe we can help in detecting it sooner. So brain cancer is a huge problem right ? detecting it at early stages is even a bigger one. A brain tumor is a growth of cells in the brain that multiplies in an abnormal, uncontrollable way. Brain tumors can be cancerous (malignant) or noncancerous (benign). When benign or malignant tumors grow, they can cause the pressure inside the skull to increase. This can cause brain damage, and it can be life-threatening.

Currently, the diagnosis of brain tumors requires a number of tests and procedures including surgery to extract a tissue sample, a neurological exam and magnetic resonance imaging tests (MRIs). These procedures can take several weeks to determine the genetic characteristics of the tumor, which can even delay the detection and therefore make the treatment process even harder. What we are proposing is a model that detects and classifies the tumor using Quantum Machine Learning, a less invasive way that could potentially minimize the number of surgeries and refine the type of therapy required. but there are like more than 100 types of brain tumors. So we decided to work on 3 common ones, meningioma, Glioma & pituitary tumors.

  • Meningioma is the most common type of primary brain tumors. it begins in the brain or spinal cord.
  • Glioma is the second common, about 33% of all brain tumors are glioma. it originates in the glial cells that surround and support neurons in the brain
  • A pituitary tumor is a gland in the brain. It makes hormones that affect many other glands and many functions in the body.

So the plan was, find a good dataset, prepare the architecture than develop a model, prepare for a website to deploy the model & finally deploy, but as the famous quote from the movie Parasite goes,

‘You know what kind of plan works out? no plan at all.’

but for a teamwork with a deadline ahead, that was impossible. so we just had to adjust to new circumstances every time.

When we first started, we spent a lot of time in research, gathering information and sharing good resources with each other on Quantum physics, Quantum computing & Quantum Machine Learning. In order to understand how we’re going to do this.

The job was split into 3 categories:

  • Look for the right Dataset
  • Pick an architecture & Develop a model
  • Deploy it

Finding the right dataset was tricky, because after picking one, we’d find out that it has a lot of issues in it, like for example different shapes in the images or wrong labels. Meanwhile, the research on architecture was being made, which one to take? and how to implement a quantum neural network? first, we thought about making a segmentation which basically, not only tells if there’s a tumor, it also says where! but it was almost impossible because segmentation was even more complicated if done by a quantum machine and would take forever to process the training. So eventually we decided on a classification model using a quantum layer inside for image processing. to be precise, a convolutional neural network with a quantum layer.

Before we move way further, let’s talk quantum and what we’ve learned about it on the way.

What is Quantum machine learning?

So QML is like the next big thing, and it’s very powerful. That is one of the reasons that interested us (along with how dope Quantum physics are). It is a research area that explores the crossing of ideas from quantum computing and machine learning. Quantum computing is based on the principles of quantum physics.

Quantum physics describes the behavior of atoms and fundamental particles, like electrons and photons. So a quantum computer operates by controlling the behavior of these particles but in a way that is completely different from our regular computers. A quantum computer is not just a more powerful version of our current computers. just like a light bulb is not a more powerful candle. you can’t build a light bulb by building better and better candles. a light bulb is a different technology based on deeper scientific understanding. similarly, a quantum computer is a new kind of device, based on the science of quantum physics, and just like a light bulb transformed society, quantum computers have the potential to impact so many aspects of our lives, including our security needs, our health care and even the internet.
here’s how it works:
While a regular computer simulates heads or tails of a coin as a bit, a 0 or a 1, a quantum computer is completely different. A Qbit has a more fluid,
nonbinary identity. It can exist in a superposition or a combination of 0s and 1s. with some probability of being zero and some probability of being one. in other words, its identity is on a spectrum. for example, it could have a 70% chance of being zero and 30% chance of being one or 80-20 or 60-40. The possibilities are endless. The key idea here is that we have to give up on precise values of zero and one and allow for some uncertainty.

The two most relevant aspects of quantum theory are the principles of superposition and entanglement:

  • Superposition:
    Think of a qubit as an electron in a magnetic field. The electron’s spin may be either in alignment with the field, or opposite to the field. Changing the electron’s spin from one state to another is achieved by using a pulse of energy, such as from a laser. If only half a unit of laser energy is used, and the particle is isolated from all external influences, the particle then enters a superposition of states. Behaving as if it were in both states simultaneously. In the quantum world, the Qubit doesn’t have to be just 0 or 1, it can be in any proportions of both states at once. but as soon as u test its value, say, by sending the photon through a filter, it has to decide to be either vertically or horizontally polarized. so as long as it’s unobserved, the qubit is in a superposition of probabilities for 0 and 1, and you can’t predict which it’ll be. but the instant you measure it, it collapses into one of the definite states.
  • Entanglement
    Quantum entanglement allows qubits that are separated by large distances to interact with each other instantaneously. No matter how great the distance between the correlated particles, they will remain entangled as long as they are isolated.

Taken together, quantum superposition and entanglement create an enormously enhanced computing power. Where a 2-bit register in an ordinary computer can store only one of four binary configurations (00, 01, 10, or 11) at any given time, a 2-qubit register in a quantum computer can store all four numbers simultaneously. This is because each qubit represents two values. If more qubits are added, the increased capacity is expanded exponentially.

How are algorithms built and processed in quantum computing?

In quantum computing, circuits illustrate how an algorithm or a program is executed. These circuits are different to the ones we’re used to in standard computing (which show connections in space). In quantum, circuits show connections between Qubits in space as well as operations performed in time. If you’ve ever played a musical instrument, you can think about a quantum circuit like a musical notation that plays an algorithm as you read along.

We’ll generally draw rails in our circuit. each representing a qubit with an initial state. multiple qubits are represented by multiple rails, the horizontal axis then represents time. we can then add different logic operations:
(bit flips, phase flips, entangling gates etc, in order to build up a program)
as time flows from left to right, the state of the Qbit changes because of the
operations. If you do it right, you can actually solve a problem.
let’s look at a simple example. let’s start with two Qubits, each initialized in
the state 0. now let’s perform a Hadamard gate on the first Qbit (this gate transforms 0 to: 0 minus 1) next, let’s perform a C knot between these two Qbits.

Doing so fundamentally changes things, instead of two separate Qbits, we now have an entangled pair of 00 minus 11. No way to describe the Qbits individually now.
The state lives in a space of correlations describing how measurements on one Qbit would be linked to measurements on the other. With this example, measuring 0 or 1 on one Qbit, would always result in the same measurement outcome on the other. that’s because they’re not really independent anymore. That’s a simple example that does something really interesting but not necessarily really useful, but if you add together enough Qbits and enough operations in just the right way, you can actually perform something quite impactful.
The idea is, to build a useful algorithm, we need to manipulate the enormous superposition state of all Qbits, in such a way that even when we destroy everything at the end by measuring our Qbits we still get a useful outcome.

Now That we’ve grasped the meaning of quantum computing, let’s go back to our main idea. So, a quantum hybrid classification model to classify cancer. okay and with what architecture? Well, There are multiple complex quantum architectures out there but for lack of resources (since we’re working on our standard computers) We first thought of working with Tensorflow quantum, but the library was very very new and not much users to it yet so we won’t find good resources other than the documentation provided, plus we won’t find answers on stackoverflow for our potential issues. but even with that we actually tried starting on it but we’ve already faced problems. We mostly thought about using Qiskit directly, by working on quantum emulators. That would make the job even cooler. but honestly it wasn’t easy as we thought it would be, specially for a beginner developper, and yet it took a lot of time until we finally found PennyLane The Quantum Machine Learning library That would make working on QML beginner friendly. now that we’ve decided to work on PennyLane, we still had to figure out a good architecture for our model. Since the job was mostly image analysis, we decided it’s time for a Quantum Convolutional Neural Network.

Quantum convolutional neural networks (QCNNs) were first introduced in Cong et al. (2018). The structure of QCNNs is motivated by that of CNNs. Convolutional neural networks (CNNs) provide a successful machine learning architecture for classification tasks such as image recognition.

To gain physical insight into the mechanism underlying QCNNs and motivate their application to the problems under consideration, we now relate our circuit model to two well-known concepts in quantum information theory — the multiscale entanglement renormalization ansatz25 (MERA). A MERA can be understood as a quantum state generated by a sequence of unitary and isometry layers applied to an input state (e.g. |00i). While each isometry layer introduces a set of new qubits in a predetermined state (e.g. |0i) before applying unitary gates on nearby ones, unitary layers simply apply quasi-local unitary gates to the existing qubits.

mera vs QCNN

This exponentially growing, hierarchical structure allows for the long-range correlations associated with critical systems. The QCNN circuit has similar structure, but runs in the reverse direction. Hence, for any given state |ψi with a MERA representation, there is always a QCNN that recognizes |ψi with deterministic measurement outcomes; one such QCNN is simply the inverse of the MERA circuit

QCNN vs CNN

To not bore you with more architectures research & details here’s the final architecture we set foot on.

And now, we’ve set up on an architecture, developing the model, and still switching back and forth on datasets for conventionality reasons. until we finally came across this great dataset that has meningioma, Glioma and pituitary tumors with labels. The model design incorporates 3 major stages: Image processing for the feature extraction on the quantum convolutional circuit, training the processed image with fully connected layers (Dense Keras layers) and evaluation.

Image processing

First, Resizing the images​.

Then, convolving & pooling using the Quantum convolutional Layer. by taking 4 pixels each time, where each pixel would pass a qubit through a wire. Then pass through a RX gate, then each two qubits would reunite in a RZ gate, next go through a RX gate. the outputs now re reunited in a RZ then RX gate and finally to the measurement function of the circuit.

Training

The model training is no different than the usual,

  • first, we split the data to 3 parts Training/Validation/Test​
  • Then, we passed the processed training data through a Fully Connected layer​ (Keras Dense layer)
  • The loss function calculations using the Sparse Categorical Cross Entropy​
  • Calculating the Validation Accuracy​

Evaluation

  • Accuracy: 88%​
  • Precision: 88%​​
  • F1-score: 88%​​
  • Recall: 88%

All that is left for us to do now is deployment. And collecting a new dataset that does detection and not classification, meaning a dataset with labels 0 & 1(yes or no) . This actually is still being made because we’re doing the data preparation manually and by the time of the deadline (hope it will be done)

We’ve reached the end of the journey my friend, wish us luck for the final presentation. Here’s a Github link for the repo

https://github.com/ggirlk/Brain_Cancer_Classification/

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Abidi Ghofrane
Abidi Ghofrane

Written by Abidi Ghofrane

Software engineering student at Holberton School Tunis

Responses (1)

Write a response