Upload 5 files
Browse filesFiles changed (5)
- README.md+4-4
- app.pyAdded+64
- haarcascade_frontalface_default.xmlAdded
- packages.txtAdded+1
- requirements.txtAdded+8
12345678910---title: BMIAPPemoji: 😻colorFrom: graycolorTo: yellowsdk: streamlitsdk_version: 1.41.1app_file: app.pypinned: false---12345678910---title: BMIAPPemoji: 📊colorFrom: yellowcolorTo: graysdk: streamlitsdk_version: 1.19.0app_file: app.pypinned: false---
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364import cv2import streamlit as stfrom keras_vggface.vggface import VGGFaceimport tensorflow as tffrom tensorflow.keras.applications import ResNet50from tensorflow.keras.preprocessing import imagefrom tensorflow.keras.models import Modelfrom tensorflow.keras.layers import GlobalAveragePooling2Dimport numpy as npimport pickle
pickle_file_path = 'models/svm_model.pkl'
with open(pickle_file_path, 'rb') as file: svm_model = pickle.load(file)
base_model = VGGFace(model='vgg16', include_top=False, input_shape=(224, 224, 3))x = base_model.outputx = GlobalAveragePooling2D()(x)model = Model(inputs=base_model.input, outputs=x)
# Function to preprocess the imagedef preprocess_image(img): img = cv2.resize(img, (224, 224)) img = image.img_to_array(img) img = np.expand_dims(img, axis=0) img = img[0] # Remove the extra dimension return img def extract_features(image_array): # img = np.squeeze(image_array, axis=0) img = np.expand_dims(image_array, axis=0) img = tf.keras.applications.resnet50.preprocess_input(img) features = model.predict(img,verbose=0) return features.flatten()
# Function to predict BMIdef predict_bmi(img): pre_img = preprocess_image(img) features = extract_features(pre_img) features = features.reshape(1,-1) pred = svm_model.predict(features) return pred
def main(): st.title("BMI Prediction from Camera Image") st.write("This app predicts the BMI of a person from an image captured using the camera.")
# Capture an image from the camera using streamlit-media's camera_input function img_file_buffer = st.camera_input("Take a picture")
if img_file_buffer is not None: # Load the image data from the file buffer file_bytes = np.asarray(bytearray(img_file_buffer.getvalue()), dtype=np.uint8) img = cv2.imdecode(file_bytes, 1)
# Preprocess the image and predict BMI bmi_label = predict_bmi(img)
# Display the predicted BMI st.write("Predicted BMI:", str(bmi_label[0] - 5))
if __name__ == '__main__': main()1python3-opencv12345678tensorflow==2.10.0opencv-pythonstreamlit==1.22.0keras_applicationskeras_vggface @ git+https://github.com/rcmalli/keras-vggface.gitnumpy==1.23.5streamlit-webrtcscikit-learnREADME.md+4-4
app.pyAdded+64
haarcascade_frontalface_default.xmlAdded
packages.txtAdded+1
requirements.txtAdded+8