从VGG19的任意中间层中抽取特征

from keras.applications.vgg19 import VGG19

from keras.preprocessing import image

from keras.applications.vgg19 import preprocess_input

from keras.models import Model

import numpy as np

base_model = VGG19(weights='imagenet')

model = Model(input=base_model.input, output=base_model.get_layer('block4_pool').output)

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)

block4_pool_features = model.predict(x)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

利用新数据集finetune InceptionV3

from keras.applications.inception_v3 import InceptionV3

from keras.preprocessing import image

from keras.models import Model

from keras.layers import Dense, GlobalAveragePooling2D

from keras import backend as K

# create the base pre-trained model

base_model = InceptionV3(weights='imagenet', include_top=False)

# add a global spatial average pooling layer

x = base_model.output

x = GlobalAveragePooling2D()(x)

# let's add a fully-connected layer

x = Dense(1024, activation='relu')(x)

# and a logistic layer -- let's say we have 200 classes

predictions = Dense(200, activation='softmax')(x)

# this is the model we will train

model = Model(input=base_model.input, output=predictions)

# first: train only the top layers (which were randomly initialized)

# i.e. freeze all convolutional InceptionV3 layers

for layer in base_model.layers:

layer.trainable = False

# compile the model (should be done *after* setting layers to non-trainable)

model.compile(optimizer='rmsprop', loss='categorical_crossentropy')

# train the model on the new data for a few epochs

model.fit_generator(...)

# at this point, the top layers are well trained and we can start fine-tuning

# convolutional layers from inception V3. We will freeze the bottom N layers

# and train the remaining top layers.

# let's visualize layer names and layer indices to see how many layers

# we should freeze:

for i, layer in enumerate(base_model.layers):

print(i, layer.name)

# we chose to train the top 2 inception blocks, i.e. we will freeze

# the first 172 layers and unfreeze the rest:

for layer in model.layers[:172]:

layer.trainable = False

for layer in model.layers[172:]:

layer.trainable = True

# we need to recompile the model for these modifications to take effect

# we use SGD with a low learning rate

from keras.optimizers import SGD

model.compile(optimizer=SGD(lr=0.0001, momentum=0.9), loss='categorical_crossentropy')

# we train our model again (this time fine-tuning the top 2 inception blocks

# alongside the top Dense layers

model.fit_generator(...)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

在定制的输入tensor上构建InceptionV3

from keras.applications.inception_v3 import InceptionV3

from keras.layers import Input

# this could also be the output a different Keras model or layer

input_tensor = Input(shape=(224, 224, 3)) # this assumes K.image_dim_ordering() == 'tf'

model = InceptionV3(input_tensor=input_tensor, weights='imagenet', include_top=True)

1

2

3

4

5

6

7

模型文档

## Xception模型 ```python keras.applications.xception.Xception(include_top=True, weights='imagenet', input_tensor=None,input_shape=None) ```

Xception V1 模型, 权重由ImageNet训练而言

在ImageNet上,该模型取得了验证集top1 0.790和top5 0.945的正确率

注意,该模型目前仅能以TensorFlow为后端使用,由于它依赖于"SeparableConvolution"层,目前该模型只支持tf的维度顺序(width, height, channels)

默认输入图片大小为299x299

参数

include_top:是否保留顶层的3个全连接网络

weights:None代表随机初始化,即不加载预训练权重。'imagenet’代表加载预训练权重

input_tensor:可填入Keras tensor作为模型的图像输出tensor

input_shape: 可选参数,仅当include_top=False时才应指定该参数。input_shape须为长3的tuple,图片的宽和高不得小于71.

返回值

Keras 模型对象

参考文献

License

预训练权重由我们自己训练而来,基于MIT license发布

## VGG16模型 ```python keras.applications.vgg16.VGG16(include_top=True, weights='imagenet', input_tensor=None, input_shape=None) ```

VGG16模型,权重由ImageNet训练而来

该模型再Theano和TensorFlow后端均可使用,并接受th和tf两种输入维度顺序

模型的默认输入尺寸时224x224

参数

include_top:是否保留顶层的3个全连接网络

weights:None代表随机初始化,即不加载预训练权重。'imagenet’代表加载预训练权重

input_tensor:可填入Keras tensor作为模型的图像输出tensor

input_shape: 可选参数,仅当include_top=False时才应指定该参数。input_shape须为长3的tuple,维度顺序依赖于image_dim_ordering,图片的宽和高不得小于48.

返回值

Keras 模型对象

参考文献

License

## VGG19模型 ```python keras.applications.vgg19.VGG19(include_top=True, weights='imagenet', input_tensor=None, input_shape=None) ``` VGG19模型,权重由ImageNet训练而来

该模型再Theano和TensorFlow后端均可使用,并接受th和tf两种输入维度顺序

模型的默认输入尺寸时224x224

参数

include_top:是否保留顶层的3个全连接网络

weights:None代表随机初始化,即不加载预训练权重。'imagenet’代表加载预训练权重

input_tensor:可填入Keras tensor作为模型的图像输出tensor

input_shape: 可选参数,仅当include_top=False时才应指定该参数。input_shape须为长3的tuple,维度顺序依赖于image_dim_ordering,图片的宽和高不得小于48.

返回值

Keras 模型对象

参考文献

License

## ResNet50模型 ```python keras.applications.resnet50.ResNet50(include_top=True, weights='imagenet', input_tensor=None, input_shape=None) ```

50层残差网络模型,权重训练自ImageNet

该模型再Theano和TensorFlow后端均可使用,并接受th和tf两种输入维度顺序

模型的默认输入尺寸时224x224

参数

include_top:是否保留顶层的全连接网络

weights:None代表随机初始化,即不加载预训练权重。'imagenet’代表加载预训练权重

input_tensor:可填入Keras tensor作为模型的图像输出tensor

input_shape: 可选参数,仅当include_top=False时才应指定该参数。input_shape须为长3的tuple,维度顺序依赖于image_dim_ordering,图片的宽和高不得小于197.

返回值

Keras 模型对象

参考文献

License

预训练权重由Kaiming He发布的预训练权重移植而来,基于MIT License

## InceptionV3模型 ```python keras.applications.inception_v3.InceptionV3(include_top=True, weights='imagenet', input_tensor=None,input_shape=None) ``` InceptionV3网络,权重训练自ImageNet

该模型再Theano和TensorFlow后端均可使用,并接受th和tf两种输入维度顺序

模型的默认输入尺寸时299x299

参数

include_top:是否保留顶层的全连接网络

weights:None代表随机初始化,即不加载预训练权重。'imagenet’代表加载预训练权重

input_tensor:可填入Keras tensor作为模型的图像输出tensor

input_shape: 可选参数,仅当include_top=False时才应指定该参数。input_shape须为长3的tuple,其维度顺序依赖于所使用的image_dim_ordering,图片的宽和高不得小于139.

返回值

Keras 模型对象

参考文献

License

预训练权重由我们自己训练而来,基于MIT License

## MusicTaggerCRNN模型 ```python keras.applications.music_tagger_crnn.MusicTaggerCRNN(weights='msd', input_tensor=None, include_top=True) ``` 该模型时一个卷积循环模型,以向量化的MelSpectrogram音乐数据为输入,能够输出音乐的风格. 你可以用`keras.applications.music_tagger_crnn.preprocess_input`来将一个音乐文件向量化为spectrogram.注意,使用该功能需要安装[Librosa](http://librosa.github.io/librosa/),请参考上面的使用范例. ### 参数 * include_top:是否保留顶层的全连接网络 * weights:None代表随机初始化,即不加载预训练权重。'imagenet'代表加载预训练权重 * input_tensor:可填入Keras tensor作为模型的图像输出tensor

返回值

Keras 模型对象

参考文献

License

预训练权重由我们自己训练而来,基于MIT License

引用

返回列表预训练特征提取及应用预训练的卷积神经网络特征提取及应用

matlab2017调用vgg19,从VGG19的任意中间层中抽取特征相关推荐

  1. matlab2017调用vgg19,TensorFlow vgg19 图像识别

    下载vgg预训练模型 https://github.com/fchollet/deep-learning-models/releases/download/v0.1/vgg19_weights_tf_ ...

  2. JAVA调用 keras,keras vgg19 模型使用

    参考,一些常见模型的使用,不过预处理函数需要修改 还算是比较准确的 from keras.preprocessing import image from keras.applications.vgg1 ...

  3. c++语言程序中,要调用的函数必须在main()函数中定义,惠州学院C++考试复习题

    惠州学院C++复习题 一.选择题 1.C++的源文件的扩展名是_____C____. A.h B.obj C.cpp D.exe 2.下列选项能够作为C++变量名的是___C____. A.false ...

  4. 曲线任意里程中边桩坐标正反算及放样fx-4850程序(第五次修改)

    有个4800线元法程序,改成5800后,运行后计算某点1的坐标不对,再次运行同样计算该点的坐标,又是对的了,同样计算某点2仍是第二次才能算对,谁能知道怎么回事? 下面是该4800程序      曲线任 ...

  5. 新思路: JS获取任意数据中最大的数字

    作者: 万千钧 转载请注明出处 先说一下正常的思路 判断数据类型 根据不同类型判断是否是最大数字 过程中如果发现新的数组或者对象, 重复步骤一 另外一个思路 通过将数据转换成JSON, 然后通过正则匹 ...

  6. 【Groovy】集合遍历 ( 调用集合的 every 方法判定集合中的所有元素是否符合闭包规则 | =~ 运算符等价于 contains 函数 | 代码示例 )

    文章目录 一.调用集合的 every 方法判定集合中的所有元素是否符合闭包规则 二.代码示例 一.调用集合的 every 方法判定集合中的所有元素是否符合闭包规则 集合的 every 方法 , 用于 ...

  7. 任意1-10中的4个数字,使用加减乘除计算得出24结果的可能组合(java版),很多人小时候都玩过...

    目录 需求: 需求该如何分析呢,怎么划分成小需求呢? 如何把小需求编排成完整需求: 学有所得 学会分析需求,由哪些组成(规则,逻辑等); 能把的需求分解成很多子需求.或孙需求.或童孙需求,直到每个需求 ...

  8. linux下java调用python脚本,java - 在Linux Terminal中以编程方式从Java调用python脚本 - 堆栈内存溢出...

    我正在开发一个Java应用程序,用于检查源文件中的补丁程序(是否存在). 用于检测补丁程序更改的核心逻辑位于python脚本[titled'patch.py​​']中,并且我的Java应用程序与此Py ...

  9. .net调用c++方法时如何释放c++中分配的内存_C/C++常见面试题总结

    第一部分:计算机基础 1. C/C++内存有哪几种类型? C中,内存分为5个区:堆(malloc).栈(如局部变量.函数参数).程序代码区(存放二进制代码).全局/静态存储区(全局变量.static变 ...

  10. jupyter调用py文件_解决Jupyter notebook中.py与.ipynb文件的import问题

    在jupyter notebook中,因为其解析文件的方式是基于json的,所以其默认保存的文件格式不是.py而是.ipynb.而.ipynb文件并不能简单的import进.py或者.ipynb文件中 ...

最新文章

  1. Linux删除 指定数目行【或者所有行】删除光标到行首
  2. tableau实战系列(三十九)-Tableau可视化之多种地图绘制汇总
  3. Algorithm:C++语言实现之链表相关算法(单链公共结点问题、一般LCA、括号匹配、最长括号匹配、逆波兰表达式Reverse Polish Notation、直方图矩形面积、收集雨水问题)
  4. CATALAN数 学习
  5. vue+Element ui中使用 upload实现Excel文件上传
  6. python ssh
  7. 对CORS OPTIONS预检请求的一些思考
  8. 2021-11-05深度学习
  9. asp.net返回值当文件下载问题
  10. 论高校计算机信息管理能力的提升,论高校计算机信息管理能力的提升
  11. 由一个bug引发的SQLite缓存一致性探索
  12. linux ssh反向代理
  13. Unity3D自带例子AngryBots的分析
  14. openGL使用高度贴图模拟地球表面凹凸效果
  15. Magick.NET图片处理:解决Tga格式图片转Jpg后上下镜像问题
  16. day 32 子进程的开启 及其用法
  17. 细数互联网企业组织架构大调整
  18. MAC修改主机名、计算机名
  19. JAVA内存文件映射
  20. Windows系统删除蓝牙图标

热门文章

  1. 测试驱动开发(TDD)开发思路
  2. matlab节约里程法_新手求大神指导,MATLAB中怎么使用节约里程法
  3. Reflector使用详解,把DLL文件转换为.cs文件
  4. JDK安装与环境变量配置(Win10)
  5. 在微信公众平台做HTML 5游戏的一些经验
  6. Excel 培训笔记
  7. MediaCreationTool.bat操作手册
  8. Xposed框架未安装解决方法
  9. 选择排序 ( 直接选择排序 堆排序 )
  10. JS实现随机切换姓名与头像