neuralmind-ai / electricity-theft-detection-with-self-attention

Electricity theft detection using Self-Attention mechanisms
32 stars 7 forks source link

How to predict with this model #1

Open malekiamir opened 3 years ago

malekiamir commented 3 years ago

Hi I'm trying to use your model in a digital meter project, and I don't have any experience with PyTorch. I've trained the model and I can load it but I don't know how to feed the model to predict. I would be glad if you please help me with this. Thanks for your great repo

gustavoplensack commented 3 years ago

Hi @malekiamir!

Consider taking a look at this file, it may help you. There we implement a Pytorch's dataset (docs).

If you need further information, let me know!

malekiamir commented 3 years ago

thanks for your reply @gustavoplensack, I might describe the problem not very clear. I have the .pth file and the problem is how to use it. I just know that the input shape has 3 dimensions but I don't know what are these dimensions.

so if I have a consumer's usage data in an array for example, and the model is ready. what input should I feed to the model, like model(sth), to get the prediction for that consumer?

gustavoplensack commented 3 years ago

To evaluate the that for a consumer, your input sth should be in the shape of a 3D tensor. The original input (a time series) is converted into a matrix (2D). The 3D data is built with a binary mask with the same shape as the original data matrix stacked over the original data.

More details about the preprocessing and transformations are provided at section 3.1 and 3.2 of this paper and the code that implements this preprocessing from the download of the original dataset to the input to the model is implemented at:

malekiamir commented 3 years ago

Thanks for your response,

Now I have the output tensor and it is like this : tensor([[ 0.8610, -1.5230], [ 2.9618, -2.5590]], device='cuda:0', grad_fn=) but I don't know how to find the output which is 1 or 0. The code I am using is this:

for x, y in dataset_train: xnan = x.copy() x[np.isnan(x)] = 0. xnan[~np.isnan(xnan)] = 0. xnan[np.isnan(xnan)] = 1. x = np.stack((x, xnan), axis=1) input = torch.Tensor(x) output = model(input.cuda()) print(output) break

I want to test it on a single object of the dataset but as I said, instead of the classification output, I have The output tensor!

Thanks for your time