Views
No views yet
0) and Human (1).Rescaling layer (1./255) so raw RGB pixel arrays can be passed directly into the model without manual preprocessing pipelines.model.fit, tf.keras.utils.image_dataset_from_directory).1Input Image (300 × 300 × 3 RGB)
2 └── Rescaling Layer (Scale to [0.0, 1.0])
3 ├── [Block 1] Conv2D (16 filters, 3x3, ReLU) ──> MaxPooling2D (2x2) [Output: 149x149x16]
4 ├── [Block 2] Conv2D (32 filters, 3x3, ReLU) ──> MaxPooling2D (2x2) [Output: 73x73x32]
5 ├── [Block 3] Conv2D (64 filters, 3x3, ReLU) ──> MaxPooling2D (2x2) [Output: 35x35x64]
6 ├── [Block 4] Conv2D (64 filters, 3x3, ReLU) ──> MaxPooling2D (2x2) [Output: 16x16x64]
7 ├── [Block 5] Conv2D (64 filters, 3x3, ReLU) ──> MaxPooling2D (2x2) [Output: 7x7x64]
8 └── Flatten Layer [Vector Size: 3,136]
9 └── Dense Layer (512 units, ReLU activation)
10 └── Output Layer (1 unit, Sigmoid activation) [Output: Binary Probability]pip install tensorflow numpy pillow huggingface_hub1import numpy as np
2import tensorflow as tf
3from huggingface_hub import hf_hub_download
4
5# 1. Download model directly from Hugging Face Hub
6model_path = hf_hub_download(
7 repo_id="MightyDragon-Dev/horse-or-human-classifier",
8 filename="horse-or-human-model.keras"
9)
10model = tf.keras.models.load_model(model_path)
11
12# 2. Load and prep test image
13img_path = "sample.jpg" # Target image file
14img = tf.keras.utils.load_img(img_path, target_size=(300, 300))
15img_array = tf.keras.utils.img_to_array(img)
16img_array = np.expand_dims(img_array, axis=0) # Shape: (1, 300, 300, 3)
17
18# 3. Predict class probability
19prediction = model.predict(img_array)[0][0]
20
21if prediction > 0.5:
22 print(f"Result: Human (Confidence: {prediction:.2%})")
23else:
24 print(f"Result: Horse (Confidence: {(1 - prediction):.2%})")| Parameter | Value |
|---|---|
| Dataset Source | Laurence Moroney's Horses or Humans Dataset |
| Training Data | 1,027 Synthetic Photoreal CGI Renderings (500 Horses / 527 Humans) |
| Input Shape | (300, 300, 3) |
| Batch Size | 32 |
| Optimizer | RMSprop (learning_rate=0.001) |
| Loss Function | binary_crossentropy |
| Epochs Trained | 15 |