image classification web app using stramlit
import cv2from PIL import Image, ImageOpsimport numpy as npdef import_and_predict(image_data, model): size = (150,150) image = ImageOps.fit(image_data, size, Image.ANTIALIAS) image = np.asarray(image) img = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) img_resize = (cv2.resize(img, dsize=(75, 75), interpolation=cv2.INTER_CUBIC))/255. img_reshape = img_resize[np.newaxis,...] prediction = model.predict(img_reshape) return predictionif file is None: st.text("Please upload an image file")else: image = Image.open(file) st.image(image, use_column_width=True) prediction = import_and_predict(image, model) if np.argmax(prediction) == 0: st.write("It is a paper!") elif np.argmax(prediction) == 1: st.write("It is a rock!") else: st.write("It is a scissor!") st.text("Probability (0: Paper, 1: Rock, 2: Scissor") st.write(prediction)
Are there any code examples left?
New code examples in category Python
-
Python 2023-04-11 03:04:20
-
Python 2022-03-27 22:40:04 pycharm no module named
-
Python 2022-03-27 22:25:05 assign multiple variablesin one line
-
Python 2022-03-27 22:20:02 levenshtein distance
-
Python 2022-03-27 21:35:09 get text from url python last slash
-
Python 2022-03-27 21:30:30 df concatenate df
-
Python 2022-03-27 21:25:09 python odd or even
-
Python 2022-03-27 21:15:32 python include function from another file
-
Python 2022-03-27 21:10:01 color module python
-
Python 2022-03-27 21:00:27 python tkinter cursor types