比较乱,有空成型再整理
杂项
一维二维卷积
模型layers各个API
loss
优化器
https://blog.csdn.net/brucewong0516/article/details/78838124
参数调用
之前都是 from keras.applications import VGG16 conv_base = VGG16(weights='imagenet', include_top=False, input_shape=(150, 150, 3) ) 现在是,用于演示 from keras.applications.vgg16 import VGG16 vgg16 = VGG16(weights='imagenet')
model输入都是Tensor,处理方法:
from keras.preprocessing import image #from keras.applications.vgg16 import preprocess_input, decode_predictions import numpy as np img_path = 'D:\\Jupyter\\elephant.jpg' img = image.load_img(img_path, target_size=(150, 150)) img_tensor = image.img_to_array(img) img_tensor = np.expand_dims(img_tensor, axis=0) #x = preprocess_input(x) img_tensor /= 255. print(model.predict(img_tensor))
from keras.preprocessing import image from keras.applications.vgg16 import preprocess_input, decode_predictions import numpy as np img_path = 'D:\\Jupyter\\elephant.jpg' img = image.load_img(img_path, target_size=(224, 224)) x = image.img_to_array(img) x = np.expand_dims(x, axis=0) x = preprocess_input(x) preds = vgg16.predict(x) print('Predict:', decode_predictions(preds, top=3))
Keras中文文档
https://keras-cn.readthedocs.io/en/latest/other/regularizers/
Keras的后端—-更高层级的构建模块
模型
keras系列︱Application中五款已训练模型、VGG16框架(Sequential式、Model式)解读(二)
http://www.cnblogs.com/Anita9002/p/8136535.html
VGG16结构:
https://blog.csdn.net/cai13160674275/article/details/71078554
模型官方下载:
model model.layers, model.get_layer(layer_name).output model.perdict() https://blog.csdn.net/zds13257177985/article/details/80638384
layer layer.name layer.input #img_tensor[1, 150, 150, 3] layer.output #model有n层,n个特征图,每个特征图有对应n_features特征数 #[1,size,size,n_features(特征数)]
读入图像相关
- ImageDataGenerator两种方法
- Vgg16处理输入图像那里
#书 p143 img_path = 'elephant.jpg' img = image.load_img(img_path, target_size=(224, 224)) x = image.img_to_array(img) x = np.expand_dims(x, axis=0) x = preprocess_input(x) preds = model.predict(x) #对批量进行预处理(使其颜色标准化) x = preprocess_input(x) #x[1,224,224,3] #将预测向量解读为人类可读形式(其实就是one-hot解码) predict = model.predict(x) print('Predicted:', decode_predictions(preds, top=3)[0])
- 输入numpy矩阵【n,height,weight,channels】,label【1,categories_num】
训练集,验证集,测试集
在测试数据上最终评估模型
test_generator = test_datagen.flow_from_directory( test_dir, target_size=(150, 150), batch_size=20, class_mode='binary') test_loss, test_acc = model.evaluate_generator(test_generator, steps=50) print('test acc:', test_acc)