Instructions to use sdrfsh/alexnet-door-entry-classifier with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Keras
How to use sdrfsh/alexnet-door-entry-classifier with Keras:
# Available backend options are: "jax", "torch", "tensorflow". import os os.environ["KERAS_BACKEND"] = "jax" import keras model = keras.saving.load_model("hf://sdrfsh/alexnet-door-entry-classifier") - Notebooks
- Google Colab
- Kaggle
| library_name: keras | |
| license: mit | |
| pipeline_tag: image-classification | |
| tags: | |
| - alexnet | |
| - tensorflow | |
| - keras | |
| - image-classification | |
| - activity-recognition | |
| metrics: | |
| - accuracy | |
| - f1 | |
| # AlexNet Binary Classifier - Real-Time Activity and Intention Recognition | |
| AlexNet-style convolutional neural network that classifies whether a person is **entering a door** or just **passing by** it. Trained with TensorFlow/Keras as part of the | |
| **[Real-Time Activity and Intention Recognition](https://github.com/sdrfsh/realtime-activity-and-intention-recognition)** project. | |
| ## Model Details | |
| - **Architecture:** AlexNet (5 conv layers + BatchNorm, 3×3 overlapping max-pooling, two 4096-unit dense layers with 0.5 dropout, softmax output) | |
| - **Framework:** TensorFlow / Keras (saved in the modern `.keras` format) | |
| - **Input:** RGB image, 227×227×3, raw 0-255 pixel values (rescaling to [0, 1] is built into the model - do **not** normalize before feeding images) | |
| - **Output:** softmax probabilities over 2 classes | |
| - `0` - **passing by** the door | |
| - `1` - **entering** the door | |
| ## Performance | |
| Evaluated on a held-out, balanced test set of 1,120 images (560 per class): | |
| | Metric | Value | | |
| |---|---| | |
| | Test accuracy | **98.84%** | | |
| | F1-score (passing by, 0) | 0.99 | | |
| | F1-score (entering, 1) | 0.99 | | |
| | Test loss | 0.0755 | | |
| Confusion matrix: | |
| | | Pred: passing by | Pred: entering | | |
| |---|---|---| | |
| | **True: passing by** | 548 | 12 | | |
| | **True: entering** | 1 | 559 | | |
| ## Usage | |
| ```python | |
| import keras | |
| import numpy as np | |
| from huggingface_hub import hf_hub_download | |
| model_path = hf_hub_download( | |
| repo_id="sdrfsh/alexnet-door-entry-classifier", | |
| filename="alexnet.keras", | |
| ) | |
| model = keras.models.load_model(model_path) | |
| img = keras.utils.load_img("image.jpg", target_size=(227, 227)) | |
| x = np.expand_dims(keras.utils.img_to_array(img), axis=0) | |
| probs = model.predict(x) | |
| label = int(probs.argmax(axis=1)[0]) | |
| class_names = {0: "passing by", 1: "entering"} | |
| print(f"Prediction: {class_names[label]} (confidence {probs.max():.2%})") | |
| ``` | |
| ## Training | |
| - Optimizer: Adam (initial LR 1e-4, reduced on plateau) | |
| - Loss: sparse categorical cross-entropy | |
| - Regularization: dropout 0.5 on dense layers, batch normalization, early stopping on validation loss (best weights restored) | |
| - Data split: 72% train / 18% validation / 10% test (stratified) | |
| Full training code and the wider project (real-time inference pipeline, data preparation) are available in the GitHub repository: | |
| 👉 **https://github.com/sdrfsh/realtime-activity-and-intention-recognition** | |
| ## Fine-tuning for other activity-recognition tasks | |
| This model can be used as a starting point and **fine-tuned on other activity-recognition datasets** (e.g., different actions, intentions, or interaction classes). The convolutional layers have learned general visual features from person/door scenes, so for a related task you can reuse them and retrain only the classification head, then optionally unfreeze the full network: | |
| ```python | |
| import keras | |
| from keras import layers | |
| from huggingface_hub import hf_hub_download | |
| path = hf_hub_download("sdrfsh/alexnet-door-entry-classifier", "alexnet.keras") | |
| base = keras.models.load_model(path) | |
| NUM_CLASSES = 4 # number of classes in your dataset | |
| # Reuse everything except the final classification layer | |
| backbone = keras.Model(base.inputs, base.layers[-2].output) | |
| backbone.trainable = False # stage 1: freeze the pretrained layers | |
| model = keras.Sequential([ | |
| backbone, | |
| layers.Dense(NUM_CLASSES, activation="softmax"), | |
| ]) | |
| model.compile(optimizer=keras.optimizers.Adam(1e-3), | |
| loss="sparse_categorical_crossentropy", metrics=["accuracy"]) | |
| model.fit(train_ds, validation_data=val_ds, epochs=10) | |
| # Stage 2 (optional): unfreeze and fine-tune the whole network at a low LR | |
| backbone.trainable = True | |
| model.compile(optimizer=keras.optimizers.Adam(1e-5), | |
| loss="sparse_categorical_crossentropy", metrics=["accuracy"]) | |
| model.fit(train_ds, validation_data=val_ds, epochs=10) | |
| ``` | |
| Input images should be 227×227×3 with raw 0-255 pixel values, as with the base model. | |
| ## Limitations | |
| - Trained specifically to distinguish a person **entering** a door from a person **passing by** it; performance on other scenes, camera angles, or doors unlike those in the training data is untested. | |
| - Input images must be resizable to 227×227 without destroying the relevant content. | |
| ## Citation | |
| If you use this model, please link back to the [GitHub repository](https://github.com/sdrfsh/realtime-activity-and-intention-recognition). |