ResNet50 Liver Tumor Classification

This model is a fine-tuned version of pre-trained ResNet50 for liver tumor classification tasks. The model has been trained to classify medical images into two categories: tumor and non-tumor.

Model Description

  • Architecture: ResNet50 (modified for single-channel input)
  • Base Model: torchvision ResNet50
  • Task: Binary classification for liver tumor detection
  • Input: 1-channel medical images (224x224)
  • Output: 2 classes (tumor/non-tumor)

Training Data

This model was fine-tuned on the Liver Tumor Classification Dataset.

Usage

First, install the required dependencies:

pip install torch torchvision huggingface_hub

Then, you can load and use the model as follows:

# Model implementation
import torch
import torch.nn as nn
import torch.nn.functional as F
import torchvision
from huggingface_hub import PyTorchModelHubMixin


class ResNet50LiverTumor(nn.Module, PyTorchModelHubMixin):
    def __init__(self, in_channels, num_classes):
        super().__init__()
        self.in_channels = in_channels
        self.num_classes = num_classes

        resnet = torchvision.models.resnet50(num_classes=self.num_classes)
        self.conv1 = nn.Conv2d(self.in_channels, 64, kernel_size=(7, 7), stride=(2, 2), padding=(3, 3), bias=False)
        for name, module in resnet.named_children():
            if name not in ['conv1']: #
                setattr(self, name, module)

    def forward(self, x):
        x = x[:, 0, ...][:, None, ...]

        x = self.conv1(x)
        x = self.bn1(x)
        x = self.relu(x)
        x = self.maxpool(x)

        x = self.layer1(x)
        x = self.layer2(x)
        x = self.layer3(x)
        x = self.layer4(x)

        x = self.avgpool(x)
        x = torch.flatten(x, 1)
        output = self.fc(x)

        return output

# Load the model from the Hub:
model = ResNet50LiverTumor.from_pretrained("seongun/resnet50-livertumor")
model.eval()

# Define preprocessing transform
transform = transforms.Compose([
    transforms.ToTensor(),
    transforms.Resize((224, 224), antialias=False),
])

# Inference example
sample = transform(liver_tumor_sample).unsqueeze(0)
with torch.no_grad():
    output = model(image)
prediction = torch.argmax(output, dim=1)
Downloads last month
-
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Dataset used to train seongun/resnet50-livertumor