Spaces:
Sleeping
Sleeping
Upload 4 files
Browse files- poetry.lock +0 -0
- pyproject.toml +25 -0
- requirements.txt +10 -0
- train_model.py +56 -0
poetry.lock
ADDED
The diff for this file is too large to render.
See raw diff
|
|
pyproject.toml
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[tool.poetry]
|
2 |
+
name = "xray-image-classifier"
|
3 |
+
version = "0.1.0"
|
4 |
+
description = ""
|
5 |
+
authors = ["Your Name <your.email@example.com>"]
|
6 |
+
readme = "README.md"
|
7 |
+
|
8 |
+
[tool.poetry.dependencies]
|
9 |
+
python = "3.11.8"
|
10 |
+
tensorflow = "2.15.1"
|
11 |
+
keras = "^2.15.0"
|
12 |
+
numpy = "^1.23.5"
|
13 |
+
pandas = "^2.2.2"
|
14 |
+
matplotlib = "^3.9.2"
|
15 |
+
jupyter = "^1.0.0"
|
16 |
+
scipy = "^1.14.1"
|
17 |
+
[tool.poetry.group.dev.dependencies]
|
18 |
+
pytest = "^8.3.2"
|
19 |
+
ipython = "^8.26.0"
|
20 |
+
autopep8 = "^2.3.1"
|
21 |
+
jupyter = "^1.0.0"
|
22 |
+
|
23 |
+
[build-system]
|
24 |
+
requires = ["poetry-core"]
|
25 |
+
build-backend = "poetry.core.masonry.api"
|
requirements.txt
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
tensorflow==2.15.1
|
2 |
+
keras==2.15.0
|
3 |
+
numpy==1.23.5
|
4 |
+
pandas==2.2.2
|
5 |
+
matplotlib==3.9.2
|
6 |
+
jupyter==1.0.0
|
7 |
+
scipy==1.14.1
|
8 |
+
pytest==8.3.2
|
9 |
+
ipython==8.26.0
|
10 |
+
autopep8==2.3.1
|
train_model.py
ADDED
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import numpy as np
|
3 |
+
import tensorflow as tf
|
4 |
+
import matplotlib.pyplot as plt
|
5 |
+
from tensorflow.keras.preprocessing.image import ImageDataGenerator
|
6 |
+
from model import create_model
|
7 |
+
|
8 |
+
base_dir = 'data/chest_xray'
|
9 |
+
train_dir = os.path.join(base_dir, 'train')
|
10 |
+
val_dir = os.path.join(base_dir, 'val')
|
11 |
+
|
12 |
+
train_datagen = ImageDataGenerator(
|
13 |
+
rescale=1./255,
|
14 |
+
rotation_range=20,
|
15 |
+
width_shift_range=0.2,
|
16 |
+
height_shift_range=0.2,
|
17 |
+
shear_range=0.2,
|
18 |
+
zoom_range=0.2,
|
19 |
+
horizontal_flip=True,
|
20 |
+
fill_mode='nearest'
|
21 |
+
)
|
22 |
+
val_datagen = ImageDataGenerator(rescale=1./255)
|
23 |
+
|
24 |
+
train_generator = train_datagen.flow_from_directory(
|
25 |
+
train_dir,
|
26 |
+
target_size=(150, 150),
|
27 |
+
batch_size=32,
|
28 |
+
class_mode='binary'
|
29 |
+
)
|
30 |
+
|
31 |
+
val_generator = val_datagen.flow_from_directory(
|
32 |
+
val_dir,
|
33 |
+
target_size=(150, 150),
|
34 |
+
batch_size=32,
|
35 |
+
class_mode='binary'
|
36 |
+
)
|
37 |
+
|
38 |
+
sample_images, _ = next(train_generator)
|
39 |
+
for i in range(5):
|
40 |
+
plt.subplot(1, 5, i+1)
|
41 |
+
plt.imshow(sample_images[i])
|
42 |
+
plt.axis('off')
|
43 |
+
plt.show()
|
44 |
+
|
45 |
+
model = create_model()
|
46 |
+
|
47 |
+
history = model.fit(
|
48 |
+
train_generator,
|
49 |
+
steps_per_epoch=243,
|
50 |
+
epochs=10,
|
51 |
+
validation_data=val_generator,
|
52 |
+
validation_steps=280,
|
53 |
+
callbacks=[tf.keras.callbacks.EarlyStopping(monitor='val_loss', patience=3, restore_best_weights=True)]
|
54 |
+
)
|
55 |
+
|
56 |
+
model.save('xray_image_classifier_model.keras')
|