haoling1/LC25000
Viewer • Updated • 25k • 22
How to use felixhrdyn/convnextv1-lung-cancer with Keras:
# Available backend options are: "jax", "torch", "tensorflow".
import os
os.environ["KERAS_BACKEND"] = "jax"
import keras
model = keras.saving.load_model("hf://felixhrdyn/convnextv1-lung-cancer")
This is a model card intended to be used as the README.md of the Hugging Face model repository:
The model is a fine-tuned ConvNeXt-Base classifier for lung histopathology tissue type prediction.
convnext_lung_82.kerasThe model predicts one of the following:
AdenocarcinomaBenign TissueSquamous Cell CarcinomaThis model card summarizes the training/evaluation reported by the LUCIAN project.
val_accuracy.Two split strategies were evaluated in the LUCIAN project:
| Metric | Split 80:10:10 (Final) | Split 70:15:15 |
|---|---|---|
| Train Accuracy | 96.08% | 94.95% |
| Validation Accuracy | 96.67% | 94.00% |
| Test Accuracy | 93.67% | 90.44% |
| Precision (macro) | 93.63% | 90.47% |
| Recall (macro) | 93.67% | 90.44% |
| F1-Score (macro) | 93.64% | 90.39% |
Metrics are reported from the best checkpoint epoch selected by
ModelCheckpoint(monitor='val_accuracy', mode='max').
from huggingface_hub import hf_hub_download
import tensorflow as tf
path = hf_hub_download(
repo_id="felixhrdyn/convnextv1-lung-cancer",
filename="convnext_lung_82.keras",
)
model = tf.keras.models.load_model(path)
This matches the preprocessing used in the LUCIAN app (resize(224, 224), RGB, normalize to [0, 1]).
import numpy as np
from PIL import Image
import tensorflow as tf
IMAGE_SIZE = (224, 224)
LABELS = ["Adenocarcinoma", "Benign Tissue", "Squamous Cell Carcinoma"]
img = Image.open("your_image.jpg").convert("RGB").resize(IMAGE_SIZE)
x = np.expand_dims(np.array(img) / 255.0, axis=0).astype(np.float32)
probs = model(tf.convert_to_tensor(x), training=False).numpy()[0]
pred = LABELS[int(np.argmax(probs))]
print(pred, probs)
If you use this model, cite the LUCIAN project (and the ConvNeXt paper):