Views
No views yet
| Metric | Value |
|---|---|
| Validation Loss | 0.8670 |
| RMSE | 29.24 |
| MAE | 13.00 |
| SMAPE | 56.06% |
| MAPE | 73.07% |
1import torch
2from transformers import AutoTokenizer
3from PIL import Image
4import torchvision.transforms as T
5from huggingface_hub import hf_hub_download
6
7# Download checkpoint
8checkpoint_path = hf_hub_download(
9 repo_id="Rudra12567/albef-price-prediction",
10 filename="best_model.pth"
11)
12
13# Load checkpoint
14checkpoint = torch.load(checkpoint_path)
15# Initialize your model and load state_dict
16# model.load_state_dict(checkpoint['model_state_dict'])
17
18# Prepare image
19transform = T.Compose([
20 T.Resize((224, 224)),
21 T.ToTensor(),
22 T.Normalize((0.485, 0.456, 0.406), (0.229, 0.224, 0.225)),
23])
24
25image = Image.open('product.jpg').convert('RGB')
26pixel_values = transform(image).unsqueeze(0)
27
28# Prepare text
29tokenizer = AutoTokenizer.from_pretrained('bert-base-uncased')
30text_inputs = tokenizer(
31 "Product description here",
32 truncation=True,
33 padding='max_length',
34 max_length=128,
35 return_tensors='pt'
36)
37
38# Predict
39with torch.no_grad():
40 outputs = model(pixel_values, text_inputs)
41 price_log = outputs['price_pred']
42 price = torch.expm1(price_log)