keras
keras 简记
keras 框架使用
1.we can start with import of tensorflow
1 

2.We always need normalize our data
1 

3.Then, let’s design our model.
Sequential: That defines a SEQUENCE of layers in the neural network
Flatten: Remember earlier where our images were a square, when you printed them out? Flatten just takes that square and turns it into a 1 dimensional set.
Dense: Adds a layer of neurons
Each layer of neurons need an activation function to tell them what to do. There’s lots of options, but just use these for now.
Relu effectively means “If X>0 return X, else return 0” – so what it does it it only passes values 0 or greater to the next layer in the network.
Softmax takes a set of values, and effectively picks the biggest one, so, for example, if the output of the last layer looks like [0.1, 0.1, 0.05, 0.1, 9.5, 0.1, 0.05, 0.05, 0.05], it saves you from fishing through it looking for the biggest value, and turns it into [0,0,0,0,1,0,0,0,0] – The goal is to save a lot of coding!
1 

4.The next thing to do is to actually build it. We do this by compiling it with an optimizer and loss function.
1 

5.we can evaluate our model by using model.evaluate
1 

addtional:
If I want to stop my training when I reach a desired value, I can use the myCallbak class
1 

Keras with convolutions
1.The first thing we need know is that the first convolution expects a single tensor containing everything. So instead of 60000 28x28x1 items in a list,we have a single 4D list that is 60000x28x28x1.
1 

2.Instread of the input layer at the top, we’re going to add a convolution. The parameters are:
 the number of filter. Purely arbitrary, but good to start with something in the order of 32
 the size of the Convolution
 the activation function
 in the first layer, the shape of the input data
1 

keras imageGenerator
顺便记两个单词 adorable 可爱的 dominant 占优势的，突出的 condense 使压缩
Let’s set up our data generators that will read pictures in our source folders,convert them to float32 tensors,and feed them(with their labels)to our network.
We’ll have one generator for the training images and one for the validation images. Our generators will yield batches of images of size 300x300 and their labels (binary).
In Keras this can be done via the keras.preprocessing.image.ImageDataGenerator
class using the rescale
parameter. This ImageDataGenerator
class allows you to instantiate generators of augmented image batches (and their labels) via .flow(data, labels)
or .flow_from_directory(directory)
. These generators can then be used with the Keras model methods that accept data generators as inputs: fit_generator
, evaluate_generator
, and predict_generator
.
1 
