How to randomly project RGB images using OPU

Hello:
I am trying to improve the accuracy of ridge classifier by using OPU-based random projection.
The size of the dataset I used is 48x48x3, and the number of images is 20000.I have two questions:
1.How to binarize RGB images? I have read the examples, but I am still confused. I converted images into 48x144 through concatenating RGB channels, and then used SeparateBitPlanEncoder to encode them into binary matrix with resolution of 288x144. Is this correct?
2. I noticed that the output size of OPUMap.fit_transform is (20000, n_components). What other operations are needed before projected data is used for ridge classification?

Hello and welcome to the community,

  1. In order to use the OPU to project RGB images, you should both binarize and flatten them such that you have a matrix of size n_samples x n_features. In your case, this matrix should be of shape number of images x number of features, so 20.000 x 6912, where 6912=48483. This can then be given to SeparatedBitPlanEncoder, note that this object should receive batches of images, not a single one at a time. Essentially:
  • reshape your data such that it has dimension n_samples x n_features
  • feed them to the SeparatedBitPlanencoder
  • feed the output to OPUMap
  1. Once you have the random features of size 20.000 x n_components, you can apply the ridge classification directly on them. Sometimes it is useful to rescale them into a nice range before doing the fit.

Best,
Iacopo

Hello Iacopo,
I reshape the data to get the matrix (20000 x6912) as you said, and then feed them to the SeparatedBitPlanencoder. But the n_samples of the binary matrix is 6 times larger (120000x6912). Do I need to transpose the matrix before encoding?

Ops, I am sorry I got confused with a different method. You need to run that through the OPUMap transform, and then the output of the photonic transform through SeparatedBitPlanDecoder to recover a matrix of proper dimensions before doing the fit.

The problem is solved, thank you.