Skip to content

Commit e89fc6c

Browse files
authored
Update tumorrr.py
1 parent 6ddf94b commit e89fc6c

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

tumorrr.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Gerekli Kütüphaneleri İçeri Aktarma
1+
22
import os
33
import cv2
44
import numpy as np
@@ -8,37 +8,35 @@
88
from tensorflow.keras.utils import to_categorical
99
from sklearn.model_selection import train_test_split
1010

11-
# --- 1. Veri Yükleme ve Ön İşleme ---
1211

13-
# Veri seti yolu ve kategoriler
12+
1413
data_dir = '/kaggle/input/brain-mri-images-for-brain-tumor-detection'
15-
categories = ['no', 'yes'] # 'no' - Tümör Yok, 'yes' - Tümör Var
14+
categories = ['no', 'yes']
1615

17-
# Görüntü boyutlandırma
1816
img_size = 128
19-
data = [] # Görüntü verileri
20-
labels = [] # Görüntü etiketleri
17+
data = []
18+
labels = []
19+
2120

22-
# Görüntüleri yükle ve ön işle
2321
print("Veri yükleniyor...")
2422
for category in categories:
25-
path = os.path.join(data_dir, category) # Kategori klasör yolu
26-
class_num = categories.index(category) # Etiket: 0 (no) veya 1 (yes)
23+
path = os.path.join(data_dir, category)
24+
class_num = categories.index(category)
2725

2826
for img in os.listdir(path):
2927
try:
30-
# Görüntüyü gri tonlamaya çevir ve yeniden boyutlandır
28+
3129
img_array = cv2.imread(os.path.join(path, img), cv2.IMREAD_GRAYSCALE)
3230
resized_array = cv2.resize(img_array, (img_size, img_size))
3331

34-
# Veriyi listeye ekle
32+
3533
data.append(resized_array)
3634
labels.append(class_num)
3735
except Exception as e:
3836
print("Hata:", e)
3937

4038
print("Veri yükleme tamamlandı.")
41-
data = np.array(data).reshape(-1, img_size, img_size, 1) / 255.0 # Normalizasyon
39+
data = np.array(data).reshape(-1, img_size, img_size, 1) / 255.0
4240
labels = np.array(labels)
4341
X_train, X_test, y_train, y_test = train_test_split(data, labels, test_size=0.1, random_state=42)
4442
y_train = to_categorical(y_train, num_classes=2)

0 commit comments

Comments
 (0)