Update app.py
Browse files
app.py
CHANGED
|
@@ -11,6 +11,7 @@ from albumentations.pytorch.transforms import ToTensorV2
|
|
| 11 |
model = models.resnet50(pretrained=False)
|
| 12 |
model.fc = nn.Linear(2048, 21)
|
| 13 |
model.load_state_dict(torch.load('resnet_best.pth'), strict=True)#load weights from training run
|
|
|
|
| 14 |
|
| 15 |
st.title("My awesome ML Function")
|
| 16 |
|
|
@@ -22,6 +23,14 @@ if uploaded_file is not None:
|
|
| 22 |
st.image(image) #showing the image
|
| 23 |
np_img = np.array(image)
|
| 24 |
cv_image = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
elif ".csv" in uploaded_file.name: #csv check
|
| 26 |
dataframe = pd.read_csv(uploaded_file)
|
| 27 |
st.write(dataframe)
|
|
|
|
| 11 |
model = models.resnet50(pretrained=False)
|
| 12 |
model.fc = nn.Linear(2048, 21)
|
| 13 |
model.load_state_dict(torch.load('resnet_best.pth'), strict=True)#load weights from training run
|
| 14 |
+
model.eval()
|
| 15 |
|
| 16 |
st.title("My awesome ML Function")
|
| 17 |
|
|
|
|
| 23 |
st.image(image) #showing the image
|
| 24 |
np_img = np.array(image)
|
| 25 |
cv_image = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
| 26 |
+
|
| 27 |
+
# Let's resize the image and make a pytorch tensor from the image np array.
|
| 28 |
+
cust_transform = A.Compose([A.Resize(height=256, width=256, p=1.0),ToTensorV2(p=1.0)], p=1.0)
|
| 29 |
+
tensor = cust_transform(image=img)
|
| 30 |
+
tensor = tensor['image'].float().resize(1,3,256,256)
|
| 31 |
+
tensor,tensor.shape
|
| 32 |
+
custom_pred = model.forward(tensor).detach().numpy() # Forward is the python method defined inside the resnet.
|
| 33 |
+
custom_pred
|
| 34 |
elif ".csv" in uploaded_file.name: #csv check
|
| 35 |
dataframe = pd.read_csv(uploaded_file)
|
| 36 |
st.write(dataframe)
|