alexz123 commited on
Commit
aed63ee
·
1 Parent(s): 530a6d8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -4
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
- #if uploaded_file is not None:
30
- # if '.jpg' in uploaded_file.name.lower() or '.png' in uploaded_file.name.lower():
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)