Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tensorflow.keras import Sequential
- from tensorflow.keras.layers import Dense, GlobalAveragePooling2D
- from tensorflow.keras.optimizers import Adam
- from tensorflow.keras.preprocessing.image import ImageDataGenerator
- from tensorflow.keras.applications.resnet import ResNet50
- import numpy as np
- def load_train(path):
- datagen = ImageDataGenerator(rescale=1./255, horizontal_flip=True, vertical_flip=True)
- train_datagen_flow = datagen.flow_from_directory(
- path,
- target_size=(150, 150),
- batch_size=16,
- class_mode='sparse',
- seed=12345)
- return train_datagen_flow
- def create_model(input_shape):
- optimizer = Adam(lr=0.0001)
- backbone = ResNet50(input_shape=(150, 150, 3),
- weights='imagenet',
- include_top=False)
- model = Sequential()
- model.add(backbone)
- model.add(GlobalAveragePololing2D())
- model.add(Dense(units=12, activation='softmax'))
- model.compile(optimizer=optimizer, loss='sparse_categorical_crossentropy',
- metrics=['acc'])
- return model
- def train_model(model, train_data, test_data, batch_size=None, epochs=3,
- steps_per_epoch=None, validation_steps=None):
- model.fit(train_data, validation_data=test_data,
- batch_size=batch_size, epochs=epochs,
- steps_per_epoch=steps_per_epoch,
- validation_steps=validation_steps,
- verbose=2)
- return model
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement