Row 6735
Content Data
This page contains data entry 6735 from the Axioma AXP content repository. The structured data below represents the complete record for this entry.
import streamlit as st import os import random import numpy as np import tensorflow as tf from PIL import Image # Path to the directory containing the celebrity images IMAGE_DIR = "path to dataset" # List of classes (directory names) CLASSES = os.listdir(IMAGE_DIR) # Load the pre-trained face recognition model MODEL_PATH = "VGG16.h5" u/st.cache(allow_output_mutation=True) def load_model(): model = tf.keras.models.load_model(MODEL_PATH) return model with st.spinner('Model is being loaded..'): model=load_model() # Function to preprocess the input image def preprocess_image(image_path): img = Image.open(image_path).convert('RGB') img = img.resize((224, 224)) # Assuming the model input size is 224x224 img = np.array(img) / 255.0 img = np.expand_dims(img, axis=0) return img # Function to get the name of the celebrity def get_celebrity_name(image_path): # Preprocess the image img = preprocess_image(image_path) # Predict using the loaded model predictions = model.predict(img) # Get the predicted class index predicted_index = np.argmax(predictions) # Get the celebrity name from the class index celebrity_name = CLASSES[predicted_index] return celebrity_name # Function to get a random image def get_random_image(): # Choose a random class random_class = random.choice(CLASSES) # Get list of images in the class directory images = os.listdir(os.path.join(IMAGE_DIR, random_class)) # Choose a random image from the class random_image = random.choice(images) # Return the path to the random image return os.path.join(IMAGE_DIR, random_class, random_image) def main(): st.title("Celebrity Face Recognition") st.write("Click below to recognize a celebrity") # Get a random image random_image_path = get_random_image() # Display the image st.image(random_image_path, caption='Random Celebrity Image', use_column_width=True) if st.button("Recognize Celebrity"): # Get the name of the celebrity celebrity_name = get_celebrity_name(random_image_path) st.write(f"Predicted Celebrity:{celebrity_name}") if __name__ == "__main__": main()
| Field | Value |
|---|---|
| text | import streamlit as st import os import random import numpy as np import tensorflow as tf from PIL import Image # Path to the directory containing the celebrity images IMAGE_DIR = "path to dataset" # List of classes (directory names) CLASSES = os.listdir(IMAGE_DIR) # Load the pre-trained face recognition model MODEL_PATH = "VGG16.h5" u/st.cache(allow_output_mutation=True) def load_model(): model = tf.keras.… |
| label | r/tensorflow |
| dataType | comment |
| communityName | r/tensorflow |
| datetime | 2024-05-13 |
| username_encoded | Z0FBQUFBQm5LakwzOGFjczB6V1RvcmpCMUpobk1RSFZJanNuTnBBZkxuWHplR0tCUmRiaUlDVkNiWS1pQ2FQQ1RLTWhXSFFIaGpwdk9SeGRvX3NEYVk4NVA4NUVmb0JGSUpHaTltMldqMHFwUVFRMEp6UkpCTlk9 |
| url_encoded | Z0FBQUFBQm5Lak9HNXlBVjBNUmdwZjJyY24tRjlrU0YtVFlyQk5VYlBXcF8xQmc4QkRROXBjelROa0dQMGxZNU5CWjBtWE1uODdKUHhyQkE1YXhiZEJhM3FHRll0UWprN2ZmbjNXZkFSWWJnV2ZJU1I2Zk1FdzJrNUV4RTVzdUdRc0RaTjdSUm9wMVdzZ2tMMWxmMzVnaUV4X0k5dHVMc2tOd1o3cmoxNkM4c0QxWk9xMm5wWWowNFIyVW1FcHJ3THNzNnZ5NXlyQWFfUlE0MnVuaHlyQ3RjYWd1aDdBdjdwdEljb1ZobHdNV3ZyZE11b1U5SWVGcz0= |
Raw Record
{
"text": " import streamlit as st\n import os\n import random\n import numpy as np\n import tensorflow as tf\n from PIL import Image\n \n # Path to the directory containing the celebrity images\n IMAGE_DIR = \"path to dataset\"\n \n # List of classes (directory names)\n CLASSES = os.listdir(IMAGE_DIR)\n \n \n # Load the pre-trained face recognition model\n \n MODEL_PATH = \"VGG16.h5\"\n \n u/st.cache(allow_output_mutation=True)\n def load_model():\n model = tf.keras.models.load_model(MODEL_PATH)\n return model\n with st.spinner('Model is being loaded..'):\n model=load_model()\n \n \n \n # Function to preprocess the input image\n def preprocess_image(image_path):\n img = Image.open(image_path).convert('RGB')\n img = img.resize((224, 224)) # Assuming the model input size is 224x224\n img = np.array(img) / 255.0\n img = np.expand_dims(img, axis=0)\n return img\n \n # Function to get the name of the celebrity\n def get_celebrity_name(image_path):\n # Preprocess the image\n img = preprocess_image(image_path)\n # Predict using the loaded model\n predictions = model.predict(img)\n # Get the predicted class index\n predicted_index = np.argmax(predictions)\n # Get the celebrity name from the class index\n celebrity_name = CLASSES[predicted_index]\n return celebrity_name\n \n # Function to get a random image\n def get_random_image():\n # Choose a random class\n random_class = random.choice(CLASSES)\n # Get list of images in the class directory\n images = os.listdir(os.path.join(IMAGE_DIR, random_class))\n # Choose a random image from the class\n random_image = random.choice(images)\n # Return the path to the random image\n return os.path.join(IMAGE_DIR, random_class, random_image)\n \n def main():\n st.title(\"Celebrity Face Recognition\")\n st.write(\"Click below to recognize a celebrity\")\n \n # Get a random image\n random_image_path = get_random_image()\n \n # Display the image\n st.image(random_image_path, caption='Random Celebrity Image', use_column_width=True)\n \n if st.button(\"Recognize Celebrity\"):\n # Get the name of the celebrity\n celebrity_name = get_celebrity_name(random_image_path)\n st.write(f\"Predicted Celebrity:{celebrity_name}\")\n \n if __name__ == \"__main__\":\n main()",
"label": "r/tensorflow",
"dataType": "comment",
"communityName": "r/tensorflow",
"datetime": "2024-05-13",
"username_encoded": "Z0FBQUFBQm5LakwzOGFjczB6V1RvcmpCMUpobk1RSFZJanNuTnBBZkxuWHplR0tCUmRiaUlDVkNiWS1pQ2FQQ1RLTWhXSFFIaGpwdk9SeGRvX3NEYVk4NVA4NUVmb0JGSUpHaTltMldqMHFwUVFRMEp6UkpCTlk9",
"url_encoded": "Z0FBQUFBQm5Lak9HNXlBVjBNUmdwZjJyY24tRjlrU0YtVFlyQk5VYlBXcF8xQmc4QkRROXBjelROa0dQMGxZNU5CWjBtWE1uODdKUHhyQkE1YXhiZEJhM3FHRll0UWprN2ZmbjNXZkFSWWJnV2ZJU1I2Zk1FdzJrNUV4RTVzdUdRc0RaTjdSUm9wMVdzZ2tMMWxmMzVnaUV4X0k5dHVMc2tOd1o3cmoxNkM4c0QxWk9xMm5wWWowNFIyVW1FcHJ3THNzNnZ5NXlyQWFfUlE0MnVuaHlyQ3RjYWd1aDdBdjdwdEljb1ZobHdNV3ZyZE11b1U5SWVGcz0="
}
Entry Information
- Entry ID: 6735
- Repository: Axioma AXP
- Dataset: arrmlet/reddit_dataset_36
- Total Entries: 100,000