Keras training aids and optimization tools

Source: Internet
Author: User
Tags constructor keras
Original: http://blog.csdn.net/zzulp/article/details/76591341 1 Callbacks

Callbacks provides a series of classes that can be called back during training to enable observation and interference in the training process. In addition to some classes provided by the library, users can customize the class. The following lists the more useful callback classes.

modelcheckpoint
class name effect constructor
is used to save the model modelcheckpoint (filepath, monitor= ' Val_loss ') between epochs, save_best_only =false, Save_weights_only=false, mode= ' auto ', period=1)
earlystopping when early Stop is activated (if a loss is found to be less than the previous epoch training), the training is stopped after the patience epoch. earlystopping (monitor= ' Val_loss ', patience=0, mode= ' auto ')
tensorboard generate TB-required logs Tensorboard (log_dir= './logs ', histogram_freq=0, Write_graph=true, Write_images=false, Embeddings_freq=0, Embeddings_layer_names=none, Embeddings_metadata=none)
Reducelronplateau when the indicator becomes Reduce learning rate Reducelronplateau (monitor= ' Val_loss ', factor=0.1, patience=10, mode= ' auto ', epsilon=0.0001, CoolD Own=0, min_lr=0)

Example:

From keras.callbacks import modelcheckpoint

model = sequential ()
model.add (Dense, input_dim=784, kernel_ initializer= ' uniform '))
Model.add (Activation (' Softmax '))
model.compile (loss= ' categorical_crossentropy ') , optimizer= ' Rmsprop ')

checkpointer = Modelcheckpoint (filepath= "/tmp/weights.h5", Save_best_only=true)
TENSBRD = Tensorboard (logdir= ' Path/of/log ')
model.fit (X_train, Y_train, batch_size=128, Callbacks=[checkpointer , TENSBRD])
1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10

PS: After adding the Tensorboard callback class, you can use the TensorFlow tensorboard command line to open the Visual Web service. 2 Application

This module provides a pre-trained image model based on image-net to facilitate our migration learning. When first used, the model weight data is downloaded to the ~/.keras/models directory.

Image Model Description constructor Function
InceptionV3 InceptionV3 (include_top=true, weights= ' imagenet ', input_tensor=none,input_shape=none,pooling=none,classes=1000)
ResNet50 ResNet50 (include_top=true, weights= ' imagenet ', input_tensor=none,input_shape=none,pooling=none,classes=1000)
VGG19 VGG19 (include_top=true, weights= ' imagenet ', input_tensor=none,input_shape=none,pooling=none,classes=1000)
VGG16 VGG16 (include_top=true, weights= ' imagenet ', input_tensor=none,input_shape=none,pooling=none,classes=1000)
Xception Xception (include_top=true, weights= ' imagenet ', Input_tensor=none,input_shape=none,pooling=none, classes=1000)

Parameter description

Parameters Description
Include_top Whether to keep the top-level fully connected network, false as long as the bottleneck
Weights ' Imagenet ' stands for load pre-training weights, none for random initialization
Input_tensor Can be filled in keras tensor as the model of the image output tensor
Input_shape A tuple with a length of 3, indicating the shape of the input image, the width of the picture must be greater than 197
Pooling Feature extraction network pooling mode. None represents non-pooling, and the output of the last convolutional layer is 4D tensor. ' AVG ' represents the global average pooling, ' Max ' represents the global maximum value pooling
Classes Number of categories in the picture category, available when Include_top=true Weight=none

For migration learning, you can refer to this article: How to implement image classification on very small datasets. It describes the process of transforming images and using existing models and fine-tune new classifiers. 3 Visualization of models

The Plot_model function is provided in the Utils package, which is used to present a model in the form of an image. This feature relies on Pydot-ng and Graphviz.
Pip Install Pydot-ng Graphviz

From keras.utils import Plot_model
model = keras.applications.InceptionV3 ()
Plot_model (model, to_file= ' Model.png ')
1 2 3 1 2 3

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.