File size: 1,957 Bytes
c71b57e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
---
license: mit
language:
- en
metrics:
- accuracy
pipeline_tag: image-classification
---

## ๐Ÿ“‚ Project Structure

```
.
โ”œโ”€โ”€ image_classifier.h5     # Trained model
โ”œโ”€โ”€ main.py                 # Training & prediction script
โ””โ”€โ”€ README.md               # Project description
```

---

## โš™๏ธ Technologies Used

* Python 3.10+
* TensorFlow / Keras
* NumPy
* Matplotlib

---

## ๐Ÿ“Š Dataset

The dataset is from **Kaggle Multi-Cancer Dataset**:

```
/kaggle/input/multi-cancer/Multi Cancer/Multi Cancer/Breast Cancer
```

Images are split into **90% training** and **10% validation** using `ImageDataGenerator`.

---

## ๐Ÿ—๏ธ Model Architecture

* **Conv2D (32 filters, 3x3, ReLU)**
* **MaxPooling2D (2x2)**
* **Conv2D (64 filters, 3x3, ReLU)**
* **MaxPooling2D (2x2)**
* **Conv2D (128 filters, 3x3, ReLU)**
* **MaxPooling2D (2x2)**
* **Flatten**
* **Dense (512, ReLU)**
* **Dense (Softmax output, # of classes)**

Optimizer: **Adam**
Loss: **Categorical Crossentropy**
Metric: **Accuracy**

---

## ๐Ÿš€ Training

```python
model.fit(train_generator, validation_data=validation_generator, epochs=10)
```

After training, the model is saved as:

```python
model.save("image_classifier.h5")
```

---

## ๐Ÿ”ฎ Prediction Example

```python
def guess(image_path, model, class_indices):
    img = load_img(image_path, target_size=(150, 150))
    img_array = img_to_array(img) / 255.0
    img_array = np.expand_dims(img_array, axis=0)

    prediction = model.predict(img_array)
    predicted_class = np.argmax(prediction)
    class_labels = {v: k for k, v in class_indices.items()}
    predicted_label = class_labels[predicted_class]

    plt.imshow(img)
    plt.title(f"Model guess: {predicted_label}")
    plt.axis("off")
    plt.show()
```

---

## โœ… Results

* Trains a CNN model for breast cancer image classification
* Provides a simple **guess() function** to visualize predictions
* Model is reusable via `image_classifier.h5`