- Goal: Classify images as either
logoornologoand make it easy to search a folder for items like “t‑shirts with/without a logo”. - Artifacts: A trained Keras
.h5model inmodels/and two user interfaces: a chat-style CLI and a Streamlit web app.
- The
.h5model is loaded bymodel_utils.load_trained_model(). - Both
chat_cli.pyandstreamlit_app.pyimportload_trained_modelfrommodel_utils.pyand use it for inference.
-
model_utils.pyload_trained_model(path=None): loads the trained.h5frommodels/imageclassify.h5(default) or a path you pass.predict_image(model, image_path): returns{image_path, logo_probability, predicted_label}.predict_folder(model, folder, keyword_filter=None, limit=None, recursive=True): scans a folder, predicts for each image.- Note: The model trained in the notebook outputs a value where higher means “nologo”. The utilities invert that so
logo_probabilityreflects the chance of a logo.
-
chat_cli.py- Loads the model and runs an interactive prompt (chat-style) to search folders for items like “show me t-shirts with logo”.
- Parses phrases such as "with logo" and "without a logo".
- Scans
data/andlogos/by default (or a custom folder via--scan).
-
streamlit_app.py- Web UI to upload a single image or scan a folder and visualize predictions.
- Sidebar inputs let you choose model path and scan folder; results are shown with thumbnails.
- Your
.h5model is discovered atmodels/imageclassify.h5by default. - Images are loaded and resized to the model’s input size, normalized to
[0,1]. - The model’s output is post-processed so that
logo_probabilityis in[0,1]andpredicted_labelis eitherlogoornologo. - CLI/App filter results by label and keyword, and sort by confidence.
-
Install deps:
pip install -r requirements.txt
-
Chat CLI:
python chat_cli.py --model models/imageclassify.h5 --scan data- Example queries:
show me t-shirts with logoshow me t-shirts without a logotop 10 caps with logo
-
Streamlit app:
streamlit run streamlit_app.py- Use the sidebar to set model path and scan folder; use tabs to upload or scan.
- Model path: pass
--modelto CLI or set the sidebar field in the app. - Scan path: pass
--scanto CLI or set the sidebar field in the app. - Label mapping: If you retrain a model with different output ordering, adjust
_postprocess_output()inmodel_utils.py.
- "No matching images found":
- Ensure the keyword matches filenames or parent folder names (e.g., use
t-shirt,tshirts, ortee). - Check the scan folder contains images with extensions like
.jpg,.png. - Try removing the keyword to see if images are detected at all.
- Ensure the keyword matches filenames or parent folder names (e.g., use
- Predictions look inverted (logo vs nologo): Revisit
_postprocess_output()and the logic from your training notebook.