|
1 | | -# Gerekli Kütüphaneleri İçeri Aktarma |
| 1 | + |
2 | 2 | import os |
3 | 3 | import cv2 |
4 | 4 | import numpy as np |
|
8 | 8 | from tensorflow.keras.utils import to_categorical |
9 | 9 | from sklearn.model_selection import train_test_split |
10 | 10 |
|
11 | | -# --- 1. Veri Yükleme ve Ön İşleme --- |
12 | 11 |
|
13 | | -# Veri seti yolu ve kategoriler |
| 12 | + |
14 | 13 | 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'] |
16 | 15 |
|
17 | | -# Görüntü boyutlandırma |
18 | 16 | img_size = 128 |
19 | | -data = [] # Görüntü verileri |
20 | | -labels = [] # Görüntü etiketleri |
| 17 | +data = [] |
| 18 | +labels = [] |
| 19 | + |
21 | 20 |
|
22 | | -# Görüntüleri yükle ve ön işle |
23 | 21 | print("Veri yükleniyor...") |
24 | 22 | 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) |
27 | 25 |
|
28 | 26 | for img in os.listdir(path): |
29 | 27 | try: |
30 | | - # Görüntüyü gri tonlamaya çevir ve yeniden boyutlandır |
| 28 | + |
31 | 29 | img_array = cv2.imread(os.path.join(path, img), cv2.IMREAD_GRAYSCALE) |
32 | 30 | resized_array = cv2.resize(img_array, (img_size, img_size)) |
33 | 31 |
|
34 | | - # Veriyi listeye ekle |
| 32 | + |
35 | 33 | data.append(resized_array) |
36 | 34 | labels.append(class_num) |
37 | 35 | except Exception as e: |
38 | 36 | print("Hata:", e) |
39 | 37 |
|
40 | 38 | 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 |
42 | 40 | labels = np.array(labels) |
43 | 41 | X_train, X_test, y_train, y_test = train_test_split(data, labels, test_size=0.1, random_state=42) |
44 | 42 | y_train = to_categorical(y_train, num_classes=2) |
|
0 commit comments