This file contains hidden or 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
| import pandas as pd | |
| df_train = pd.read_csv('./KagglePlanetMCML.csv') | |
| df_train.head() |
This file contains hidden or 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
| import tensorflow as tf | |
| IM_SIZE = 128 | |
| image_input = tf.keras.Input(shape=(IM_SIZE, IM_SIZE, 3), name='input_layer') | |
| # Some convolutional layers | |
| conv_1 = tf.keras.layers.Conv2D(32, | |
| kernel_size=(3, 3), | |
| padding='same', | |
| activation='relu')(image_input) |
This file contains hidden or 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
| print(model.summary()) |
This file contains hidden or 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.compile(optimizer='adam', | |
| loss={'weather': 'categorical_crossentropy', | |
| 'ground': 'binary_crossentropy'}) |
This file contains hidden or 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
| import ast | |
| import numpy as np | |
| import math | |
| import os | |
| import random | |
| from tensorflow.keras.preprocessing.image import img_to_array as img_to_array | |
| from tensorflow.keras.preprocessing.image import load_img as load_img | |
| def load_image(image_path, size): | |
| # data augmentation logic such as random rotations can be added here |
This file contains hidden or 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
| callbacks = [ | |
| tf.keras.callbacks.ModelCheckpoint('./model.h5', verbose=1) | |
| ] | |
| model.fit_generator(generator=seq, | |
| verbose=1, | |
| epochs=1, | |
| use_multiprocessing=True, | |
| workers=4, | |
| callbacks=callbacks) |
This file contains hidden or 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
| seq = KagglePlanetSequence('./KagglePlanetMCML.csv', | |
| './data/train/', | |
| im_size=IM_SIZE, | |
| batch_size=32) |
This file contains hidden or 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
| another_model = tf.keras.models.load_model('./model.h5') | |
| another_model.fit_generator(generator=seq, verbose=1, epochs=1) |
This file contains hidden or 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
| import tensorflow as tf | |
| from tensorflow.python.saved_model import builder as saved_model_builder | |
| from tensorflow.python.saved_model.signature_def_utils_impl import predict_signature_def | |
| from tensorflow.python.saved_model import tag_constants | |
| tf.keras.backend.set_learning_phase(0) | |
| # The export path contains the name and the version of the model | |
| export_path = './PlanetModel/1' | |
| model = tf.keras.models.load_model('./model.h5') | |
| builder = saved_model_builder.SavedModelBuilder(export_path) |
This file contains hidden or 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
| import requests | |
| import json | |
| image = img_to_array(load_img('./data/train/train_10001.jpg', target_size=(128,128))) / 255. | |
| payload = { | |
| "instances": [{'input_image': image.tolist()}] | |
| } | |
| r = requests.post('http://localhost:9000/v1/models/PlanetModel:predict', json=payload) | |
| json.loads(r.content) |
OlderNewer