Hello everyone,
I am sorry in advance if this question is too basic.

But, I am stucked on this problem. I am trying to convert a class target to a regression-like target.

For context, say I have images 224 x 224 RGB belonging to a class corresponding to any element of this array [0, 1, 2, 3, 4] I would like to convert the corresponding class to a target of float type. Given that my images are now in torch tensors of values between 0 and 1.

Is there any pytorch function I can use to do this? If not can someone kindly suggest a way I can simply do this?

If your question is about casting data types, take a look at Casting data types

If you want to run some kind of classification, maybe try to use CrossEntropyLoss or something closely related which should take care of that.

If you are just starting, I would recommend to do the PyTorch introduction and use a dataset with less dimensions, e.g. MNIST. From my experience, using those small datasets is much more convenient, since most of the basic methods can easily be transferred to more complex data and models, without requiring a lot of hardware.

Hi Luis, thank you for your response. I understand your responses, but they are not what I am looking for.

What I am looking for is a way to normalize my categories/classes ([0, 1, 2, 3, 4]) where each element represent a class; given an image of say size 224 x 224 (could as well be any size). Ordinarily, this fits perfectly as a classification problem. But, I am meaning to convert it to a regression problem, such that my target labels will no longer be categories but regression targets (continuous float) with the same range of my image tensor.

Hello Tiamiyu,
as far as I remember correctly, when the CE loss is applied, you do not need to convert the classes to floats in advance. In the sense of deep learning you usually do regression even when you want to solve a classification task. When you apply the softmax function a probability score is returned, e.g.
[0.25, 0.15, 0.3, 0.2, 0.1] for a 5-class (0, 1, 2, 3, 4) problem. In this example your network would have predicted that class 2 with a probability score of 0.3 is the most reasonable one.
If you just want to scale your targets, you can do that e.g. with Normalize data to range. Note that you have to check your input range at first, in order to apply the method presented by the attached URL. Does this resolve your question?