<jupyter_start><jupyter_text>Ship or no ShipThis notebook contains a Convolutional Neural Net trained to detect whether a given image has, or does not have, a ship.<jupyter_code>from tensorflow.keras.preprocessing.image import ImageDataGenerator
import numpy as np
import matplotlib.pyplot as plt
img = plt.imread('../data/ship_no_ship/test/ship/0123b84ee.jpg')
plt.imshow(img)<jupyter_output><empty_output><jupyter_text>Create training and test sets<jupyter_code>train_gen = ImageDataGenerator(rescale = 1/255.)
test_gen = ImageDataGenerator(rescale = 1/255.)
train_images = train_gen.flow_from_directory(
    '../data/ship_no_ship/train/',
    class_mode = 'binary',
    batch_size = 8,
    target_size = (768, 768)
)
test_images = train_gen.flow_from_directory(
    '../data/ship_no_ship/test/',
    class_mode = 'binary',
    batch_size = 8,
    target_size = (768, 768)
)
train_images.class_indices<jupyter_output><empty_output><jupyter_text>Define the model<jupyter_code>import tensorflow.keras
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Conv2D, MaxPool2D, Dropout, Flatten
from tensorflow.keras.callbacks import EarlyStopping
model = Sequential()

#model.add(Conv2D(32, (3, 3), activation = 'relu'))
#model.add(MaxPool2D())

#model.add(Conv2D(32, (3, 3), activation = 'relu'))
#model.add(MaxPool2D())

model.add(Conv2D(64, (3, 3), activation = 'relu'))

model.add(MaxPool2D())
model.add(Flatten())
model.add(Dense(64, activation = 'relu'))
model.add(Dropout(0.2))
model.add(Dense(64, activation = 'relu'))
model.add(Dropout(0.2))
model.add(Dense(1, activation = 'sigmoid'))
model.compile(loss = 'binary_crossentropy', optimizer = 'adam', metrics = ['accuracy'])
early_stop = EarlyStopping(patience=5, monitor = 'val_accuracy')<jupyter_output><empty_output><jupyter_text>Fit the model<jupyter_code>history = model.fit(train_images, 
                    epochs = 10, 
                    validation_data=test_images,
                    callbacks=[early_stop])
plt.plot(history.history['accuracy'])
plt.plot(history.history['val_accuracy'])
model.save('ship-no-ship-model-1.h5')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13657407407407407, 'fraction_numerical': 0.028703703703703703, 'mean_word_length': 5.48948948948949, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '177543', 'license': 'CC0-1.0', 'n_tokens_mistral': 806, 'n_tokens_neox': 762, 'n_words': 139, 'path': 'ship-or-no-ship/ship-or-no-ship.ipynb', 'repo_name': 'transcriptive/shipdetection', 'size': '2160'}