jvahala commited on
Commit
011b03a
1 Parent(s): 7e4c198

fix imread issue

Browse files
Files changed (1) hide show
  1. app.py +3 -2
app.py CHANGED
@@ -28,7 +28,9 @@ model.eval()
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 = cv2.imread(uploaded_file.name)
 
 
32
  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.
33
 
34
  cust_transform = A.Compose([A.Resize(height=256, width=256, p=1.0),ToTensorV2(p=1.0)], p=1.0)
@@ -38,7 +40,6 @@ if uploaded_file is not None:
38
  custom_pred = model.forward(tensor).detach().numpy() # Forward is the python method defined inside the resnet.
39
  custom_pred
40
 
41
- st.image(img)
42
  st.write(f'Predicted: {id2class[np.argmax(custom_pred)]}')
43
  elif '.csv' in uploaded_file.name:
44
  dataframe = pd.read_csv(uploaded_file)
 
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)
 
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)