Spaces:
Sleeping
Sleeping
Update AKSHAYRAJAA/inference.py
Browse files- AKSHAYRAJAA/inference.py +26 -5
AKSHAYRAJAA/inference.py
CHANGED
@@ -25,27 +25,48 @@ TRANSFORMS = transforms.Compose([
|
|
25 |
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
|
26 |
])
|
27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
def load_model():
|
29 |
"""
|
30 |
Loads the model with the vocabulary and checkpoint.
|
31 |
"""
|
32 |
-
|
33 |
dataset = load_dataset() # Load dataset to access vocabulary
|
34 |
vocabulary = dataset.vocab # Assuming 'vocab' is an attribute of the dataset
|
35 |
|
36 |
-
|
37 |
model = get_model_instance(vocabulary) # Initialize the model
|
38 |
|
39 |
if can_load_checkpoint():
|
40 |
-
|
41 |
load_checkpoint(model)
|
42 |
else:
|
43 |
-
|
44 |
|
45 |
model.eval() # Set the model to evaluation mode
|
46 |
-
|
47 |
return model
|
48 |
|
|
|
49 |
def preprocess_image(image_path):
|
50 |
"""
|
51 |
Preprocess the input image for the model.
|
|
|
25 |
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
|
26 |
])
|
27 |
|
28 |
+
# def load_model():
|
29 |
+
# """
|
30 |
+
# Loads the model with the vocabulary and checkpoint.
|
31 |
+
# """
|
32 |
+
# st.write("Loading dataset and vocabulary...")
|
33 |
+
# dataset = load_dataset() # Load dataset to access vocabulary
|
34 |
+
# vocabulary = dataset.vocab # Assuming 'vocab' is an attribute of the dataset
|
35 |
+
|
36 |
+
# st.write("Initializing the model...")
|
37 |
+
# model = get_model_instance(vocabulary) # Initialize the model
|
38 |
+
|
39 |
+
# if can_load_checkpoint():
|
40 |
+
# st.write("Loading checkpoint...")
|
41 |
+
# load_checkpoint(model)
|
42 |
+
# else:
|
43 |
+
# st.write("No checkpoint found, starting with untrained model.")
|
44 |
+
|
45 |
+
# model.eval() # Set the model to evaluation mode
|
46 |
+
# st.write("Model is ready for inference.")
|
47 |
+
# return model
|
48 |
def load_model():
|
49 |
"""
|
50 |
Loads the model with the vocabulary and checkpoint.
|
51 |
"""
|
52 |
+
print("Loading dataset and vocabulary...")
|
53 |
dataset = load_dataset() # Load dataset to access vocabulary
|
54 |
vocabulary = dataset.vocab # Assuming 'vocab' is an attribute of the dataset
|
55 |
|
56 |
+
print("Initializing the model...")
|
57 |
model = get_model_instance(vocabulary) # Initialize the model
|
58 |
|
59 |
if can_load_checkpoint():
|
60 |
+
print("Loading checkpoint...")
|
61 |
load_checkpoint(model)
|
62 |
else:
|
63 |
+
print("No checkpoint found, starting with untrained model.")
|
64 |
|
65 |
model.eval() # Set the model to evaluation mode
|
66 |
+
print("Model is ready for inference.")
|
67 |
return model
|
68 |
|
69 |
+
|
70 |
def preprocess_image(image_path):
|
71 |
"""
|
72 |
Preprocess the input image for the model.
|