trying to figure out how to load custom model
Browse files
app.py
CHANGED
@@ -8,7 +8,7 @@ from PIL import Image
|
|
8 |
from scipy import special
|
9 |
import sys
|
10 |
from types import SimpleNamespace
|
11 |
-
from transformers import AutoModel
|
12 |
import torch
|
13 |
|
14 |
# sys.path.insert(1, "../")
|
@@ -84,10 +84,10 @@ def get_activations(model, image: list, model_name: str,
|
|
84 |
|
85 |
layer_outputs = {}
|
86 |
for i in range(len(model.model.features)):
|
87 |
-
image = model.
|
88 |
layer_outputs[i] = image
|
89 |
print(i, layer_outputs[i].shape)
|
90 |
-
output = model
|
91 |
output_1 = activation_indices[model_name].detach().cpu().numpy()
|
92 |
output_2 = activation_indices[model_name].detach().cpu().numpy()
|
93 |
|
@@ -197,14 +197,13 @@ def predict_and_analyze(model_name, num_channels, dim, input_channel, image):
|
|
197 |
image = torch.from_numpy(image)
|
198 |
|
199 |
assert image.shape == (1, num_channels, W, W), "Data is the wrong shape"
|
|
|
200 |
|
201 |
-
|
202 |
-
|
203 |
-
# model_name += '_%i' % (num_channels)
|
204 |
-
|
205 |
model_loading_name = model_path + "%s_%i_planet_detection" % (model_name, num_channels)
|
206 |
|
207 |
-
|
|
|
208 |
# model = load_model(model_name, activation=True)
|
209 |
model = AutoModel.from_pretrained(model_loading_name)
|
210 |
print("Model loaded")
|
|
|
8 |
from scipy import special
|
9 |
import sys
|
10 |
from types import SimpleNamespace
|
11 |
+
from transformers import AutoModel, pipeline
|
12 |
import torch
|
13 |
|
14 |
# sys.path.insert(1, "../")
|
|
|
84 |
|
85 |
layer_outputs = {}
|
86 |
for i in range(len(model.model.features)):
|
87 |
+
image = model.features[i](image)
|
88 |
layer_outputs[i] = image
|
89 |
print(i, layer_outputs[i].shape)
|
90 |
+
output = model(image).detach().cpu().numpy()
|
91 |
output_1 = activation_indices[model_name].detach().cpu().numpy()
|
92 |
output_2 = activation_indices[model_name].detach().cpu().numpy()
|
93 |
|
|
|
197 |
image = torch.from_numpy(image)
|
198 |
|
199 |
assert image.shape == (1, num_channels, W, W), "Data is the wrong shape"
|
200 |
+
print("Data loaded")
|
201 |
|
202 |
+
print("Loading model")
|
|
|
|
|
|
|
203 |
model_loading_name = model_path + "%s_%i_planet_detection" % (model_name, num_channels)
|
204 |
|
205 |
+
# pipeline = pipeline(task="image-classification", model=model_loading_name)
|
206 |
+
|
207 |
# model = load_model(model_name, activation=True)
|
208 |
model = AutoModel.from_pretrained(model_loading_name)
|
209 |
print("Model loaded")
|