Sometimes you need to run a lot of networks, such as comparison experiments, you can directly use the Application module of Keras (note here, tF2.x has more models, it is recommended to update to 2.x).

picture_size=224
x_shape = [pictrue_size, pictrue_size, 3]  
base_model = keras.applications.MobileNet(input_tensor=keras.layers.Input((pictrue_size,pictrue_size,3)),include_top=False,pooling='avg',weights=None)
# after using VGG16 network and then become not supposed to use
output = keras.layers.Dense(1, activation='sigmoid')(base_model.output)     #output
model = keras.models.Model(inputs=[base_model.input], outputs=[output])   # models # models # models #
Copy the code
keras.applications.MobileNet(input_tensor=keras.layers.Input((pictrue_size,pictrue_size,3)),include_top=False,pooling='avg',weights=None)
Copy the code

Set weights to None to avoid pre-learned weights. Set include_top to False and perform a global average pooling to get 11X feature map, another good way to tell you to change your code, directly into the function to see the include_top condition, and then the function in the writing method to migrate to their own code

Above is the writing method of mobilenet, you can carry on the reference

The above code is used to make a dichotomy, using sigmoid function. If you need to use multiple classifications, just change this line of code:

classes =1000
output = keras.layers.Dense(classes, activation='softmax')(base_model.output)     #output
Copy the code

For data reading, I have been using keras. Preprocessing, image. ImageDataGenerator the function, for other types of data, everyone should learn it is good.