Update app.py
Browse files
app.py
CHANGED
|
@@ -25,7 +25,22 @@ model.fc = nn.Linear(2048, 21)
|
|
| 25 |
model.load_state_dict(torch.load('resnet_best.pth', map_location=torch.device('cpu')), strict=True)
|
| 26 |
model.eval()
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
model.load_state_dict(torch.load('resnet_best.pth', map_location=torch.device('cpu')), strict=True)
|
| 26 |
model.eval()
|
| 27 |
|
| 28 |
+
if uploaded_file is not None:
|
| 29 |
+
if '.jpg' in uploaded_file.name.lower() or '.png' in uploaded_file.name.lower():
|
| 30 |
+
st.write(uploaded_file.name)
|
| 31 |
+
img = Image.open(uploaded_file)
|
| 32 |
+
st.image(img)
|
| 33 |
+
img = np.array(img)
|
| 34 |
+
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) # OpenCV images have a different color profile. So remember to switch to RGB, that our resnet model understands.
|
| 35 |
+
|
| 36 |
+
cust_transform = A.Compose([A.Resize(height=256, width=256, p=1.0),ToTensorV2(p=1.0)], p=1.0)
|
| 37 |
+
tensor = cust_transform(image=img)
|
| 38 |
+
tensor = tensor['image'].float().resize(1,3,256,256)
|
| 39 |
+
|
| 40 |
+
custom_pred = model.forward(tensor).detach().numpy() # Forward is the python method defined inside the resnet.
|
| 41 |
+
custom_pred
|
| 42 |
+
|
| 43 |
+
st.write(f'Predicted: {id2class[np.argmax(custom_pred)]}')
|
| 44 |
+
elif '.csv' in uploaded_file.name:
|
| 45 |
+
dataframe = pd.read_csv(uploaded_file)
|
| 46 |
+
st.write(dataframe)
|