Skip to content
ModelListedExternal
Download

Vbai TS 2.4

| Boyut | Parametre | F1 Skoru | mAPvaI | Doğruluk | Duyarlılık | Kesinlik | | 224 | 77.19M | %97.49 | %96.10 | %97.50 | %97.50 | %97.73 |

KindOtherVersionRevision cc9c918Cgrade

Model source

Kind
Other
File size
294 MB
Version
vRevision cc9c918
Updated
Sep 16, 2026
Downloads
0
Source
Hugging Face

Source description

Vbai-TS 2.4 Sürümü (TR)

BoyutParametreF1 SkorumAPvaIDoğrulukDuyarlılıkKesinlik
22477.19M%97.49%96.10%97.50%97.50%97.73

Tanım

Vbai-TS 2.4 (Tumor Segmentation) modeli, MRI veya fMRI görüntüsü üzerinden beyin hastalıklarını teşhis etmek amacıyla eğitilmiş ve geliştirilmiştir. Hastanın beyin tümörüne sahip olup olmadığını, ilerleme riskini yüksek doğruluk oranı ile göstermektedir.

Kitle / Hedef

Vbai modelleri tamamen öncelik olarak hastaneler, sağlık merkezleri ve bilim merkezleri için geliştirilmiştir.

Sınıflar

  • Glioma Tümörü: Kişide bulunan tümör agresif bir tutumdadır.
  • Meningioma Tümörü: Kişide bulunan tümör ilerlemektedir.
  • Hipofiz Tümör: Kişide bulunan tümör yavaş ilerlemektedir.
  • Tümör Yok: Kişide tümör bulunmamaktadır.

----------------------------------------

Vbai-TS 2.4 Version (EN)

SizeParamsF1 ScoremAPvaIAccuracyRecallPrecision
22477.19M97.49%96.10%97.50%97.50%97.73%

Description

The Vbai-TS 2.4 (Tumor Segmentation) model is trained and developed to diagnose brain diseases from MRI or fMRI images. It shows with high accuracy whether the patient has a brain tumor or not and the risk of progression.

Audience / Target

Vbai models are developed exclusively for hospitals, health centers and science centers.

Classes

  • Glioma Tumor: The tumor in the person has an aggressive behavior.
  • Meningioma Tumor: The tumor is progressing.
  • Pituitary Tumor: The tumor in the person is progressing slowly.
  • No Tumor: The person does not have a tumor.

Kullanım / Usage

import torch
import torch.nn as nn
import torch.nn.functional as F
from torchvision import transforms
from PIL import Image
import matplotlib.pyplot as plt
import numpy as np
import cv2
import os
import argparse
from pathlib import Path
from sklearn.metrics import precision_score, recall_score, f1_score, confusion_matrix, average_precision_score
from sklearn.preprocessing import label_binarize


transform = transforms.Compose([
    transforms.Resize((224, 224)),
    transforms.ToTensor(),
    transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
])

edge_transform = transforms.Compose([
    transforms.Resize((224, 224)),
    transforms.Grayscale(num_output_channels=1),
    transforms.ToTensor()
])


class BrainStructureAnalyzer:
    @staticmethod
    def detect_tumor_edges(image_tensor):
        try:
            if len(image_tensor.shape) == 4:
                image = image_tensor[0].squeeze().cpu().numpy()
            else:
                image = image_tensor.squeeze().cpu().numpy()

            image = ((image - image.min()) / (image.max() - image.min()) * 255).astype(np.uint8)
            blurred = cv2.GaussianBlur(image, (5, 5), 0)
            edges = cv2.Canny(blurred, 50, 150)
            kernel = np.ones((3, 3), np.uint8)
            edges = cv2.morphologyEx(edges, cv2.MORPH_CLOSE, kernel)

            return edges
        except Exception as e:
            print(f"Edge detection hatası: {e}")
            return np.zeros((224, 224), dtype=np.uint8)

    @staticmethod
    def analyze_tumor_structure(image_tensor):
        edges = BrainStructureAnalyzer.detect_tumor_edges(image_tensor)

        try:
            contours, _ = cv2.findContours(edges, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)

            if contours:
                contours = sorted(contours, key=cv2.contourArea, reverse=True)[:3]
            else:
                contours = []
        except Exception as e:
            print(f"Kontur analizi hatası: {e}")
            contours = []

        return edges, contours


class AttentionModule(nn.Module):

    def __init__(self, in_channels):
        super(AttentionModule, self).__init__()
        self.conv1 = nn.Conv2d(in_channels, max(1, in_channels // 8), 1)
        self.conv2 = nn.Conv2d(max(1, in_channels // 8), 1, 1)
        self.sigmoid = nn.Sigmoid()

    def forward(self, x):
        attention = self.conv1(x)
        attention = F.relu(attention)
        attention = self.conv2(attention)
        attention = self.sigmoid(attention)
        return x * attention, attention


class EnhancedCNN(nn.Module):

    def __init__(self, num_classes=4):
        super(EnhancedCNN, self).__init__()
        self.num_classes = num_classes
        self.model_type = 'c'

        self.conv1 = nn.Conv2d(3, 32, kernel_size=3, stride=1, padding=1)
        self.conv2 = nn.Conv2d(32, 64, kernel_size=3, stride=1, padding=1)
        self.conv3 = nn.Conv2d(64, 128, kernel_size=3, stride=1, padding=1)

        self.attention1 = AttentionModule(64)
        self.attention2 = AttentionModule(128)

        self.fc1 = nn.Linear(128 * 28 * 28, 512)
        self.dropout = nn.Dropout(0.5)
        self.relu = nn.ReLU()
        self.pool = nn.MaxPool2d(kernel_size=2, stride=2, padding=0)

        self.edge_conv1 = nn.Conv2d(1, 32, kernel_size=3, padding=1)
        self.edge_conv2 = nn.Conv2d(32, 64, kernel_size=3, padding=1)
        self.edge_pool = nn.AdaptiveAvgPool2d(56)
        self.edge_fc = nn.Linear(64 * 56 * 56, 128)

        self.fc2 = nn.Linear(512, num_classes)
        self.combined_fc = nn.Linear(512 + 128, num_classes)

    def forward(self, x, edge_x=None):
        x = self.pool(self.relu(self.conv1(x)))

        x = self.relu(self.conv2(x))
        x, attention_map1 = self.attention1(x)
        x = self.pool(x)

        x = self.relu(self.conv3(x))
        x, attention_map2 = self.attention2(x)
        x = self.pool(x)

        x_flat = x.view(x.size(0), -1)
        x_flat = self.relu(self.fc1(x_flat))
        x_flat = self.dropout(x_flat)

        if edge_x is not None:
            try:
                edge_x = self.pool(self.relu(self.edge_conv1(edge_x)))
                edge_x = self.pool(self.relu(self.edge_conv2(edge_x)))
                edge_x = self.edge_pool(edge_x)
                edge_features = edge_x.view(edge_x.size(0), -1)
                edge_features = self.relu(self.edge_fc(edge_features))

                x_flat = torch.cat([x_flat, edge_features], dim=1)
                output = self.combined_fc(x_flat)
            except Exception as e:
                print(f"Edge branch hatası: {e}")
                output = self.fc2(x_flat)
        else:
            output = self.fc2(x_flat)

        return output, attention_map2


class VisualizationManager:

    @staticmethod
    def denormalize_image(image_tensor):
        mean = torch.tensor([0.485, 0.456, 0.406]).view(3, 1, 1)
        std = torch.tensor([0.229, 0.224, 0.225]).view(3, 1, 1)
        if image_tensor.device.type == 'cuda':
            mean = mean.cuda()
            std = std.cuda()
        image = image_tensor * std + mean
        image = torch.clamp(image, 0, 1)
        return image

    @staticmethod
    def create_tumor_visualization(image, attention_map, prediction, class_names, edges=None,
                                   save_path=None, confidence=None, show_plot=False):
        try:
            fig, axes = plt.subplots(2, 2, figsize=(15, 12))

            if isinstance(image, torch.Tensor):
                image = VisualizationManager.denormalize_image(image)
                image = image.permute(1, 2, 0).cpu().numpy()

            axes[0, 0].imshow(image)
            axes[0, 0].set_title('Orijinal MRI Görüntüsü', fontsize=12, fontweight='bold')
            axes[0, 0].axis('off')

            if attention_map is not None:
                attention = attention_map.squeeze().cpu().numpy()
                if attention.ndim > 2:
                    attention = np.mean(attention, axis=0)
                attention = cv2.resize(attention, (224, 224))

                im = axes[0, 1].imshow(attention, cmap='jet', alpha=0.8)
                axes[0, 1].set_title('Dikkat Haritası (Tümör Bölgeleri)', fontsize=12, fontweight='bold')
                axes[0, 1].axis('off')
                plt.colorbar(im, ax=axes[0, 1], fraction=0.046)
            else:
                axes[0, 1].text(0.5, 0.5, 'Dikkat Haritası\nMevcut Değil',
                                ha='center', va='center', transform=axes[0, 1].transAxes)
                axes[0, 1].axis('off')

            if edges is not None:
                axes[1, 0].imshow(edges, cmap='gray')
                axes[1, 0].set_title('Tümör Yapısı Çizgileri', fontsize=12, fontweight='bold')
                axes[1, 0].axis('off')
            else:
                axes[1, 0].text(0.5, 0.5, 'Tümör Yapısı\nAnalizi Mevcut Değil',
                                ha='center', va='center', transform=axes[1, 0].transAxes)
                axes[1, 0].axis('off')

            axes[1, 1].imshow(image)
            if attention_map is not None:
                attention_overlay = cv2.resize(attention, (224, 224))
                axes[1, 1].imshow(attention_overlay, cmap='jet', alpha=0.4)

            predicted_class = class_names[prediction] if prediction < len(class_names) else "Bilinmeyen"
            title_text = f'Teşhis: {predicted_class}'
            if confidence is not None:
                title_text += f'\nGüven: {confidence:.2f}%'
            axes[1, 1].set_title(title_text, fontsize=12, fontweight='bold', color='red')
            axes[1, 1].axis('off')

            plt.tight_layout()

            if save_path:
                try:
                    plt.savefig(save_path, dpi=300, bbox_inches='tight')
                    print(f"✅ Görselleştirme kaydedildi: {save_path}")
                except Exception as e:
                    print(f"⚠️ Görselleştirme kaydetme hatası: {e}")

            if show_plot:
                plt.show()
            else:
                plt.close(fig)

            return fig

        except Exception as e:
            print(f"❌ Görselleştirme oluşturma hatası: {e}")
            return None


def count_parameters(model):
    total_params = sum(p.numel() for p in model.parameters())
    trainable_params = sum(p.numel() for p in model.parameters() if p.requires_grad)
    return total_params, trainable_params


def load_model(model_path, device):
    print(f"📦 Model yükleniyor: {model_path}")

    if not os.path.exists(model_path):
        raise FileNotFoundError(f"Model dosyası bulunamadı: {model_path}")

    checkpoint = torch.load(model_path, map_location=device)

    model_config = checkpoint.get('model_config', {'num_classes': 4, 'model_type': 'c'})
    class_names = checkpoint.get('class_names', ['glioma_tumor', 'meningioma_tumor', 'no_tumor', 'pituitary_tumor'])

    model = EnhancedCNN(num_classes=model_config['num_classes']).to(device)
    model.load_state_dict(checkpoint['model_state_dict'])
    model.eval()

    total_params, trainable_params = count_parameters(model)

    print(f"✅ Model başarıyla yüklendi!")
    print(f"   Sınıflar: {class_names}")
    print(f"   Model tipi: {model_config['model_type']}")
    print(f"   Toplam parametre sayısı: {total_params:,}")
    print(f"   Eğitilebilir parametre sayısı: {trainable_params:,}")

    return model, class_names


def test_single_image(model, image_path, class_names, device, output_dir='test_results', show_plot=False):
    print(f"\n🔍 Görüntü analiz ediliyor: {image_path}")

    try:
        image = Image.open(image_path).convert('RGB')
        image_tensor = transform(image).unsqueeze(0).to(device)
        edge_tensor = edge_transform(image).unsqueeze(0).to(device)

        with torch.no_grad():
            outputs, attention_maps = model(image_tensor, edge_tensor)
            probabilities = F.softmax(outputs, dim=1)
            confidence, predicted =...

Sources

1 source
Hugging FacePrimaryVersion cc9c9187553a12d024729c9b140fae251c0c72c7
huggingface.co/Neurazum/Vbai-TS-2.4/tree/cc9c9187553a12d024729c9b140fae251c0c72c7

Verified Sep 1

Model artifacts

1 artifact

Vbai-TS 2.4.pt

pt · 294 MB · SHA-256 e684c37bf7a0…942b · Hugging Face

Download file

Source excerpts

2 excerpts

--- license: cc-by-nc-sa-4.0 language: - en - tr pipeline_tag: image-segmentation tags: - brain - mri - tumor - ai - disease - neuroscience - fmri - diagnosis library_name: pytorch new_version: Neurazum/Vbai-2.6TS --- # Vbai-TS 2.4 Sürümü (TR) | Boyut | Parametre | F1 Skoru | mAPᵛᵃᴵ | Doğruluk | Duyarlılık | Kesinlik | |-------|--------|-------|--------|--------|---------|----------| | _224_ | 77.19M | %97.49 | %96.10 | %97.50 | %97.50 | %97.73 | ## Tanım Vbai-TS 2.4 (Tumor Segmentation) modeli, MRI veya fMRI görüntüsü üzerinden beyin hastalıklarını teşhis etmek amacıyla eğitilmiş ve geliştirilmiştir. Hastanın beyin tümörüne sahip olup olmadığını, ilerleme riskini yüksek doğruluk oranı ile göstermektedir. ### Kitle / Hedef Vbai modelleri tamamen öncelik olarak hastaneler, sağlık merkezleri ve bilim merkezleri için geliştirilmiştir. ### Sınıflar - **Glioma Tümörü**: Kişide bulunan tümör agresif bir tutumdadır. - **Meningioma Tümörü**: Kişide bulunan tümör ilerlemektedir. - **Hipofiz Tümör**: Kişide bulunan tümör yavaş ilerlemektedir. - **Tümör Yok**: Kişide tümör bulunmamaktadır. ## ---------------------------------------- # Vbai-TS 2.4 Version (EN) | Size | Params | F1 Score | mAPᵛᵃᴵ | Accuracy | Recall | Precision | |-------|--------|-------|--------|--------|---------|----------| | _224_ | 77.19M | 97.49% | 96.10% | 97.50% | 97.50% | 97.73% | ## Description The Vbai-TS 2.4 (Tumor Segmentation) model is trained and developed to diagnose brain diseases from MRI or fMRI images. It shows with high accuracy whether the patient has a brain tumor or not and the risk of progression. #### Audience / Target Vbai models are developed exclusively for hospitals, health centers and science centers. #### Classes - **Glioma Tumor**: The tumor in the person has an aggressive behavior. - **Meningioma Tumor**: The tumor is progressing. - **Pituitary Tumor**: The tumor in the person is progressing slowly. - **No Tumor**: The person does not have a tumor. # Kullanım / Usage ```python import torch import torch.nn as nn import torch.nn.functional as F from torchvision import transforms from PIL import Image import matplotlib.pyplot as plt import numpy as np import cv2 import os import argparse from pathlib import Path from sklearn.metrics import precision_score, recall_score, f1_score, confusion_matrix, average_precision_score from sklearn.preprocess...

Source context: 0 downloads · 1 likes · Pipeline image-segmentation · Library pytorch · Repo Neurazum/Vbai-TS-2.4