You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: modules/eda.py
+44-32
Original file line number
Diff line number
Diff line change
@@ -19,37 +19,6 @@ def folders(dataset):
19
19
folders=os.listdir(path)
20
20
returnfolders
21
21
22
-
defavg_images(dataset, sub_folder):
23
-
'''
24
-
This function takes two arguments the dataset: training or testing, and the sub_folder for the type of tumor e.g. ['glioma', 'meningioma', 'notumor', 'pituitary']
25
-
This function is used to find the average pixel values of each class
26
-
The purpose is to find if there is a difference in each class
27
-
'''
28
-
#assign the path in the function for readability and understanding
29
-
#assign the sub folder (class name) that was passed to the function
30
-
path= (f'../Images/{dataset}')
31
-
class_name=sub_folder
32
-
batch_size=32# Modify this to suit your needs
33
-
#instantiate ImageDataGenerator
34
-
datagen=ImageDataGenerator(rescale=1./255) # normalize pixel values to [0,1]
35
-
#get the images from the directory
36
-
generator=datagen.flow_from_directory(path,
37
-
classes=[class_name],
38
-
class_mode=None,
39
-
color_mode='grayscale',
40
-
target_size=(256, 256),
41
-
batch_size=batch_size)
42
-
n_samples=generator.samples
43
-
average_image=np.zeros((256, 256, 1))
44
-
45
-
foriinrange(n_samples//batch_size): # Integer division to avoid partial batches
46
-
images=next(generator)
47
-
average_image+=np.sum(images, axis=0)
48
-
49
-
average_image/=n_samples
50
-
returnaverage_image
51
-
52
-
53
22
defimage_len(dataset, folders):
54
23
'''
55
24
This code takes in the list directory of the folder containing the classification folders. And the dataset.
#learned i didnt need a comma because that creates a tuple: https://stackoverflow.com/questions/39192261/class-init-takes-parameters-but-turns-them-into-tuples-for-some-reason
50
+
self.dataset=dataset
51
+
self.sub_folder=sub_folder
52
+
53
+
defavg_images(self):
54
+
'''
55
+
This function takes two arguments the dataset: training or testing, and the sub_folder for the type of tumor e.g. ['glioma', 'meningioma', 'notumor', 'pituitary']
56
+
This function is used to find the average pixel values of each class
57
+
The purpose is to find if there is a difference in each class
58
+
'''
59
+
#assign the path in the function for readability and understanding
60
+
#assign the sub folder (class name) that was passed to the function
61
+
path= (f'../Images/{self.dataset}')
62
+
class_name=self.sub_folder
63
+
batch_size=32# Modify this to suit your needs
64
+
#instantiate ImageDataGenerator
65
+
datagen=ImageDataGenerator(rescale=1./255) # normalize pixel values to [0,1]
66
+
#get the images from the directory
67
+
generator=datagen.flow_from_directory(path,
68
+
classes=[class_name],
69
+
class_mode=None,
70
+
color_mode='grayscale',
71
+
target_size=(256, 256),
72
+
batch_size=batch_size)
73
+
n_samples=generator.samples
74
+
average_image=np.zeros((256, 256, 1))
75
+
76
+
foriinrange(n_samples//batch_size): # Integer division to avoid partial batches
0 commit comments