def main(): # ==================================================== # Download and build a custom Xception # ==================================================== # instantiate pre-trained Xception model base_model = Xception(include_top=False, weights='imagenet', input_shape=(299, 299, 3)) # save base model base_model_json = base_model.to_json() name = "xcept_base_model" with open(name + ".json", "w") as json_file: json_file.write(base_model_json) base_model.save_weights(name + "_weight.h5") print("Saved base model to disk") # create a custom top classifier num_classes = 2 x = base_model.output x = GlobalAveragePooling2D()(x) x = Dense(1024, activation='relu')(x) predictions = Dense(num_classes, activation='softmax')(x) model = Model(inputs=base_model.inputs, outputs=predictions) # save custom model model_json = model.to_json() name = "xcept_custom_model" with open(name + ".json", "w") as json_file: json_file.write(model_json) model.save_weights(name + "_weight.h5") print("Saved custom model to disk")
exit() if args.compress == True: model.save("model_original.hdf5") import sys sys.path.append("./keras_compressor/keras_compressor") import subprocess subprocess.call( "python ./keras_compressor/bin/keras-compressor.py model_original.hdf5 model_compressed.hdf5 --log-level DEBUG", shell=True) from keras.models import load_model model = load_model("model_compressed.hdf5") model.summary() model.save_weights("model.hdf5") model.summary() model.save_weights("model.hdf5") with open('model.json', 'w') as f: f.write(model.to_json()) from keras.utils import plot_model plot_model(model, to_file='model.png', show_shapes=True, show_layer_names=True) import subprocess subprocess.call("python ./keras-js/encoder.py model.hdf5", shell=True) exit()