Spaces:
Build error
Build error
Download utils.py from Saahil-doryu/Clothpredict: direct link, hf CLI and curl.
- Browser
- Download file 754 Bytes
-
https://huggingface.co/spaces/Saahil-doryu/Clothpredict/resolve/main/utils.py
- Command line
-
hf download hf://spaces/Saahil-doryu/Clothpredict/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/Saahil-doryu/Clothpredict/resolve/main/utils.py
754 Bytes
| import torch | |
| class AverageMeter(object): | |
| """Computes and stores the average and current value""" | |
| def __init__(self): | |
| self.reset() | |
| def reset(self): | |
| self.val = 0 | |
| self.avg = 0 | |
| self.sum = 0 | |
| self.count = 0 | |
| def update(self, val, n=1): | |
| self.val = val | |
| self.sum += val * n | |
| self.count += n | |
| self.avg = self.sum / self.count | |
| def accuracy(output, target): | |
| """Computes the Top-1 accuracy for a single prediction""" | |
| with torch.no_grad(): | |
| pred = output.argmax(dim=1) # Get the highest scoring class | |
| correct = pred.eq(target).sum().item() # Compare with the actual target | |
| return correct * 100.0 # Convert to percentage | |