Extracting features using Hybrid QNN

I had an question regarding, "How Hybrid QNN could be used as feature extractors?"

I wanted to take this tutorial’s code: Quantum transfer learning | PennyLane Demos

and use the model to extract features from the training dataset images. I tried a few traditional methods and resulted in error. Can someone either guide me Or help me on how it can be done?

Note: I went over past questions on this topic in this forum but the notebooks provided with the help have either been moved/private now. That’s why, I’m asking this question again.

Hey @sleepingcat4! Welcome to the forum :sunglasses:

Could you attach a minimal code example that shows what you’re trying to accomplish?

I was trying to extract features and I was able to receive them but unfortunately I have a new trouble while I can’t train a random classifier based on those extract features : (

Code used for extracting features

for batch_idx, (data, _) in enumerate(x_train):
    torch_image_batched = data.to(device)
    features_var1 = model_hybrid(torch_image_batched)

Now, I have a problem, where I can’t use them to train and predict labels using a random classifier. If you could help me out, that’ll be helpful.

**A link to the Google Colab: ** Google Colab

Hey @sleepingcat4!

Your code base in your collab link is quite large and I’m not sure what’s going on there :sweat_smile:. It would help if we could work on a smaller toy example here that illustrates what you’re trying to accomplish :slight_smile:.

When you say you’re trying to extract features, what do you mean exactly?

That’ll be helpful. What I’m trying to achieve:

Follow the Quantum Transfer learning tutorial provided by Pennylane. Use the Quantum Hybrid Model to extract features from the dataset and then train a random classifier for doing the actual prediction task.

I’m able to extract features from the dataset using the Quantum Hybrid Model. But, I’m getting error while trying to train the random classifier. Can you pinpoint me, what’s going wrong here? Because I assume the random forest is unable to train because of the Quantum Circuits. If you could help me out, that’ll be amazing!

It’s next to impossible to tell what the error could be without seeing your code :sweat_smile:. If you could attach something, we can start there!