Downloads · 30 days
0
sukhmani1303/lung-cancer-cnn-model
lung-cancer-cnn-model is a machine learning model from sukhmani1303. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
A TensorFlow CNN model to classify chest CT images as Normal or Lung Cancer (~96% accuracy).
Downloads · 30 days
0
Access
Public
Updated May 25, 2025
Repo size
13.9 MB
Likes
0
Public
Click a slice to open those files.
.zip13.9 MB · 100%
From the Hugging Face model README
A TensorFlow CNN model to classify chest CT images as Normal or Lung Cancer (~96% accuracy).
lung_cancer_cnn_saved_model.zip)handler.py for API endpointsimport tensorflow as tf
import numpy as np
import cv2
model = tf.saved_model.load("lung_cancer_cnn_saved_model")
infer = model.signatures['serving_default']
class_names = ['Normal', 'Lung Cancer']
def predict(image_path):
img = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)
img = cv2.resize(img, (256, 256)) / 255.0
img = img.reshape(1, 256, 256, 1).astype(np.float32)
input_key = list(infer.structured_input_signature[1].keys())[0]
outputs = infer(**{input_key: tf.convert_to_tensor(img)})
output_key = list(outputs.keys())[0]
pred = outputs[output_key].numpy()[0][0]
class_id = 1 if pred > 0.5 else 0
confidence = pred if class_id == 1 else 1 - pred
return class_names[class_id], confidence
result, confidence = predict("path/to/ct.jpg")
print(f"Prediction: {result}, Confidence: {confidence:.4f}")
For educational use only. Consult healthcare professionals.