Spaces:
Build error
Build error
Commit ·
ec39d50
1
Parent(s): d3e8879
Update app.py
Browse files
app.py
CHANGED
|
@@ -28,6 +28,13 @@ effnetb2.load_state_dict(
|
|
| 28 |
|
| 29 |
### 3. Predict function ###
|
| 30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
# Create predict function
|
| 32 |
def predict(img) -> Tuple[Dict, float]:
|
| 33 |
"""Transforms and performs a prediction on img and returns prediction and time taken.
|
|
@@ -37,7 +44,7 @@ def predict(img) -> Tuple[Dict, float]:
|
|
| 37 |
|
| 38 |
# Transform the target image and add a batch dimension
|
| 39 |
img = effnetb2_transforms(img).unsqueeze(0)
|
| 40 |
-
pix = np.array(img)
|
| 41 |
|
| 42 |
# Put model into evaluation mode and turn on inference mode
|
| 43 |
effnetb2.eval()
|
|
|
|
| 28 |
|
| 29 |
### 3. Predict function ###
|
| 30 |
|
| 31 |
+
def normalize_2d(matrix):
|
| 32 |
+
# Only this is changed to use 2-norm put 2 instead of 1
|
| 33 |
+
norm = np.linalg.norm(matrix, 1)
|
| 34 |
+
# normalized matrix
|
| 35 |
+
matrix = matrix/norm
|
| 36 |
+
return matrix
|
| 37 |
+
|
| 38 |
# Create predict function
|
| 39 |
def predict(img) -> Tuple[Dict, float]:
|
| 40 |
"""Transforms and performs a prediction on img and returns prediction and time taken.
|
|
|
|
| 44 |
|
| 45 |
# Transform the target image and add a batch dimension
|
| 46 |
img = effnetb2_transforms(img).unsqueeze(0)
|
| 47 |
+
pix = normalize_2d(np.array(img))
|
| 48 |
|
| 49 |
# Put model into evaluation mode and turn on inference mode
|
| 50 |
effnetb2.eval()
|