Andreas-w commited on
Commit
0ef611b
·
1 Parent(s): fd368c9

Create metode.py

Browse files
Files changed (1) hide show
  1. metode.py +25 -0
metode.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from fastai.vision.all import *
3
+
4
+ def load_model(model_path):
5
+ # Load the model weights from the .pth file
6
+ state_dict = torch.load(model_path)
7
+
8
+ # Define the model architecture
9
+ model = resnet34(num_classes=2)
10
+
11
+ # Load the model weights into the architecture
12
+ model.load_state_dict(state_dict)
13
+
14
+ # Define the data loaders
15
+ dls = ImageDataLoaders.from_folder(path, train='train', valid='valid')
16
+
17
+ # Define the Learner object
18
+ learn = Learner(dls, model, metrics=accuracy)
19
+
20
+ return learn
21
+
22
+ # Load the model from the .pth file and create the necessary objects
23
+ learn = load_model('my_model.pth')
24
+
25
+ # Use the model for inference or further training