This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
preds = model.predict(val_images) | |
plt.figure(figsize=(20,20)) | |
for n , i in enumerate(list(np.random.randint(0,len(val_images),36))) : | |
plt.subplot(6,6,n+1) | |
plt.imshow(val_images[i]) | |
plt.axis('off') | |
x =np.argmax(preds[i]) # takes the maximum of of the 6 probabilites. | |
plt.title((class_names[x])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Epoch 1/20 | |
30/30 [==============================] - ETA: 0s - loss: 0.6868 - accuracy: 0.5508 | |
Epoch 00001: accuracy improved from -inf to 0.55085, saving model to modelPedestrianDetection.h5 | |
30/30 [==============================] - 1s 42ms/step - loss: 0.6868 - accuracy: 0.5508 - val_loss: 0.6735 - val_accuracy: 0.5787 | |
Epoch 2/20 | |
28/30 [===========================>..] - ETA: 0s - loss: 0.6447 - accuracy: 0.6451 | |
Epoch 00002: accuracy improved from 0.55085 to 0.64407, saving model to modelPedestrianDetection.h5 | |
30/30 [==============================] - 1s 32ms/step - loss: 0.6434 - accuracy: 0.6441 - val_loss: 0.6594 - val_accuracy: 0.6128 | |
Epoch 3/20 | |
28/30 [===========================>..] - ETA: 0s - loss: 0.5339 - accuracy: 0.7489 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Model: "sequential" | |
_________________________________________________________________ | |
Layer (type) Output Shape Param # | |
================================================================= | |
conv2d (Conv2D) (None, 198, 198, 16) 448 | |
_________________________________________________________________ | |
max_pooling2d (MaxPooling2D) (None, 99, 99, 16) 0 | |
_________________________________________________________________ | |
conv2d_1 (Conv2D) (None, 97, 97, 32) 4640 | |
_________________________________________________________________ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tensorflow.keras.callbacks import ModelCheckpoint, EarlyStopping | |
from tensorflow.keras.callbacks import ReduceLROnPlateau | |
es = EarlyStopping(monitor='accuracy', mode='max', verbose=1, patience=7) | |
filepath = "modelPedestrianDetection.h5" | |
ckpt = ModelCheckpoint(filepath, monitor='accuracy', verbose=1, save_best_only=True, mode='max') | |
rlp = ReduceLROnPlateau(monitor='accuracy', patience=3, verbose=1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
model = models.Sequential() | |
model.add(layers.Conv2D(16, (3, 3), activation='relu', input_shape=(200, 200, 3))) | |
model.add(layers.MaxPooling2D((2, 2))) | |
model.add(layers.Conv2D(32, (3, 3), activation='relu')) | |
model.add(layers.MaxPooling2D((2, 2))) | |
model.add(layers.Flatten()) | |
model.add(layers.Dense(128, activation='relu')) | |
model.add(layers.Dense(2)) | |
model.summary() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def load_data(): | |
datasets = ['Pedestrian-Detection/Train/Train', 'Pedestrian-Detection/Test/Test', 'Pedestrian-Detection/Val/Val'] | |
output = [] | |
for dataset in datasets: | |
imags = [] | |
labels = [] | |
directoryA = dataset +"/Annotations" | |
directoryIMG = dataset +"/JPEGImages/" | |
file = os.listdir(directoryA) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
history = neuralnetwork_cnn.fit_generator( | |
generator=training_set, validation_data=validation_set, | |
callbacks=[es, ckpt, rlp], epochs = 5, | |
) | |
#output | |
Epoch 1/5 | |
1842/1843 [============================>.] - ETA: 0s - loss: 0.0524 - acc: 0.9855 | |
Epoch 00001: acc improved from -inf to 0.98548, saving model to modelMedicalMNIST.h5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def cnn(image_size, num_classes): | |
classifier = Sequential() | |
classifier.add(Conv2D(64, (5, 5), input_shape=image_size, activation='relu', padding='same')) | |
classifier.add(MaxPooling2D(pool_size = (2, 2))) | |
classifier.add(Conv2D(128, (3, 3), activation='relu', padding='same')) | |
classifier.add(MaxPooling2D(pool_size = (2, 2))) | |
classifier.add(Flatten()) | |
classifier.add(Dense(num_classes, activation = 'softmax')) | |
classifier.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['acc']) | |
return classifier |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
image_size = (32, 32, 3) | |
datagen=ImageDataGenerator(rescale = 1./255, | |
shear_range=0.2, | |
zoom_range=0.2, | |
horizontal_flip=True, | |
) | |
training_set=datagen.flow_from_directory(train_dir, | |
target_size=image_size[:2], | |
batch_size=32, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def show_mri(med): | |
num = len(med) | |
if num == 0: | |
return None | |
rows = int(math.sqrt(num)) | |
cols = (num+1)//rows | |
f, axs = plt.subplots(rows, cols) | |
fig = 0 | |
for b in med: | |
img = image.load_img(b) |