Update model/model.py
Browse files- model/model.py +4 -1
model/model.py
CHANGED
@@ -6,6 +6,8 @@ from transformers import AutoModelForImageClassification
|
|
6 |
def predict(image_path):
|
7 |
model = AutoModelForImageClassification.from_pretrained('sensei-ml/concrete_crack_images_classification')
|
8 |
model.eval()
|
|
|
|
|
9 |
|
10 |
with torch.no_grad():
|
11 |
# Convertir el array de NumPy a un tensor de PyTorch
|
@@ -13,7 +15,7 @@ def predict(image_path):
|
|
13 |
|
14 |
# Redimensionar la imagen usando funciones de transformaci贸n que soporten tensores
|
15 |
image_tensor = F.resize(image_tensor, [227, 227])
|
16 |
-
|
17 |
# Normalizaci贸n
|
18 |
transform = transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
|
19 |
|
@@ -21,6 +23,7 @@ def predict(image_path):
|
|
21 |
input_tensor = transform(image_tensor).unsqueeze(0) # A帽adir la dimensi贸n del batch
|
22 |
|
23 |
# Hacer predicciones
|
|
|
24 |
outputs = model(input_tensor)
|
25 |
logits = outputs.logits
|
26 |
probabilities = torch.nn.functional.softmax(logits, dim=1)[0]
|
|
|
6 |
def predict(image_path):
|
7 |
model = AutoModelForImageClassification.from_pretrained('sensei-ml/concrete_crack_images_classification')
|
8 |
model.eval()
|
9 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
10 |
+
model.to(device)
|
11 |
|
12 |
with torch.no_grad():
|
13 |
# Convertir el array de NumPy a un tensor de PyTorch
|
|
|
15 |
|
16 |
# Redimensionar la imagen usando funciones de transformaci贸n que soporten tensores
|
17 |
image_tensor = F.resize(image_tensor, [227, 227])
|
18 |
+
|
19 |
# Normalizaci贸n
|
20 |
transform = transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
|
21 |
|
|
|
23 |
input_tensor = transform(image_tensor).unsqueeze(0) # A帽adir la dimensi贸n del batch
|
24 |
|
25 |
# Hacer predicciones
|
26 |
+
input_tensor = input_tensor.to(device)
|
27 |
outputs = model(input_tensor)
|
28 |
logits = outputs.logits
|
29 |
probabilities = torch.nn.functional.softmax(logits, dim=1)[0]
|