<jupyter_start><jupyter_text>Retrain MobileNet<jupyter_code>from tensorflow.keras.layers import Dense, GlobalAveragePooling2D
from tensorflow.keras.applications.mobilenet import MobileNet
from tensorflow.keras.models import Model
# imports the mobilenet model and discards the last 1000 neuron layer.
base_model = MobileNet(weights='imagenet', include_top=False)

x = base_model.output
x = GlobalAveragePooling2D()(x)
x = Dense(1024, activation='relu')(x)
x = Dense(1024, activation='relu')(x)
x = Dense(512, activation='relu')(x)
preds = Dense(2, activation='softmax')(x)
model = Model(inputs=base_model.input, outputs=preds)
for i, layer in enumerate(model.layers):
    print(i,layer.name)
for layer in model.layers:
    layer.trainable = False

for layer in model.layers[:20]:
    layer.trainable = False

for layer in model.layers[20:]:
    layer.trainable = True
# from google_images_download import google_images_download
# response = google_images_download.googleimagesdownload()
# arguments = {"keywords": "blue tit", "limit":100, "print_urls": False, "format": "jpg", "size": ">400*300"}
# paths = response.download(arguments)
# arguments = {"keywords": "crow", "limit": 100, "print_urls": False, "format": "jpg", "size": ">400*300"}
# paths = response.download(arguments)
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras.applications.mobilenet import preprocess_input
train_datagen = ImageDataGenerator(preprocessing_function=preprocess_input)
train_generator = train_datagen.flow_from_directory('./downloads',
                                                  target_size=(224,224),
                                                  color_mode='rgb',
                                                  batch_size=32,
                                                  class_mode='categorical',
                                                  shuffle=True)
model.compile(optimizer='Adam', loss='categorical_crossentropy', metrics=['accuracy'])

step_size_train = train_generator.n // train_generator.batch_size
model.fit_generator(generator=train_generator, steps_per_epoch=step_size_train, epochs=20)<jupyter_output>Epoch 1/20
7/7 [==============================] - 5s 740ms/step - loss: 0.0080 - acc: 0.9949
Epoch 2/20
7/7 [==============================] - 5s 716ms/step - loss: 0.2408 - acc: 0.9898
Epoch 3/20
7/7 [==============================] - 5s 744ms/step - loss: 0.1439 - acc: 0.9388
Epoch 4/20
7/7 [==============================] - 5s 719ms/step - loss: 0.1536 - acc: 0.9286
Epoch 5/20
7/7 [==============================] - 5s 742ms/step - loss: 0.4921 - acc: 0.9490
Epoch 6/20
7/7 [==============================] - 5s 731ms/step - loss: 0.1554 - acc: 0.9898
Epoch 7/20
7/7 [==============================] - 5s 729ms/step - loss: 0.0329 - acc: 0.9898
Epoch 8/20
7/7 [==============================] - 5s 740ms/step - loss: 0.0507 - acc: 0.9847
Epoch 9/20
7/7 [==============================] - 5s 723ms/step - loss: 0.0559 - acc: 0.9796
Epoch 10/20
7/7 [==============================] - 5s 729ms/step - loss: 0.0327 - acc: 0.9847
Epoch 11/20
7/7 [==============================] - 5s 733ms/step - lo[...]
{'fraction_non_alphanumeric': 0.22281752284903877, 'fraction_numerical': 0.07910494799873936, 'mean_word_length': 3.613372093023256, 'pattern_counts': {'":': 10, '<': 4, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 17, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '467950', 'license': 'MIT', 'n_tokens_mistral': 1171, 'n_tokens_neox': 983, 'n_words': 224, 'path': 'testing/Untitled1.ipynb', 'repo_name': 'wsbuck/DogeNet', 'size': '3173'}