'PyTorch F1 score monitoring and re-training
I have a pre trained model that I load and test with testing data using PyTorch. Within the testing loop, I am calculating the f1 scores of each batch and monitor their f1 scores through a simple IF condition:
if f1_scores <= 0.5:
anomaly_store_x.append(test_inputs)
anomaly_store_y.append(test_label)
anomaly_store_x and anomaly_store_y stores the data and labels of the batches that have triggered the f1_score condition. After gathering them, I would like to retrain the data with the a singular data loader with both the anomaly lists and the original training data.
My questions is how can I combine both these different data into one DataLoader?
A simplified code of the testing loop can be seen below:
for i, data in enumerate(test_dl):
test_inputs, test_label = data
if CUDA == True:
test_inputs, test_label = torch.tensor(test_inputs).cuda(), torch.tensor(test_label).cuda()
''' Feed input to model '''
outputs = model_load(test_inputs)
test_label = test_label.long()
_, y_pred_tags = torch.max(outputs, dim = 1)
''' F1 Scores '''
f1_scores = f1_score(y_test_label_flat2, y_test_pred_list_flat2, average=None)
''' Anomaly Detection '''
if f1_scores >= 0.5:
anomaly_store_x.append(test_inputs)
anomaly_store_x.append(test_label)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
