How to correctly use an intermediate layer of a vgg model

willz

What I did is:

from keras.applications.vgg16 import VGG16
from keras.layers import *
from keras.models import Model
import numpy as np 

vgg_model = VGG16(weights='imagenet', include_top=False, input_shape = (224,224, 3)) 

block5_conv3 = vgg_model.get_layer("block5_conv3").output

input_image = Input(shape=(224,224, 3), name='image_input')
vgg_out = vgg_model(input_image)

f0 = Flatten()(block5_conv3)

test_model = Model(inputs=input_image, outputs=f0)
print(test_model.summary())

But I got the following error message:

Traceback (most recent call last):
  File "test.py", line 15, in <module>
    test_model = Model(inputs=input_image, outputs=f0)
  File "C:\Users\wzhou\AppData\Local\Continuum\Anaconda2\envs\tensorflow\lib\site-packages\keras\legacy\interfaces.py", line 91, in wrapper
    return func(*args, **kwargs)
  File "C:\Users\wzhou\AppData\Local\Continuum\Anaconda2\envs\tensorflow\lib\site-packages\keras\engine\network.py", line 93, in __init__
    self._init_graph_network(*args, **kwargs)
  File "C:\Users\wzhou\AppData\Local\Continuum\Anaconda2\envs\tensorflow\lib\site-packages\keras\engine\network.py", line 237, in _init_graph_network
    self.inputs, self.outputs)
  File "C:\Users\wzhou\AppData\Local\Continuum\Anaconda2\envs\tensorflow\lib\site-packages\keras\engine\network.py", line 1430, in _map_graph_network
    str(layers_with_complete_input))
ValueError: Graph disconnected: cannot obtain value for tensor Tensor("input_1:0", shape=(?, 224, 224, 3), dtype=float32) at layer "input_1". The following previous layers were accessed without issue: []

I feel something is wrong with the way that I did it but couldn't figure out the right way.

today

There is no need to define an Input layer in this case. You can use the input property of VGG model:

vgg_model = VGG16(weights='imagenet', include_top=False, input_shape = (224,224, 3)) 

block5_conv3 = vgg_model.get_layer("block5_conv3").output
f0 = Flatten()(block5_conv3)

test_model = Model(inputs=vgg_model.input, outputs=f0)

Alternatively, you can define and use a backend function:

from keras import backend as K

# ... (use the code above except the last line)

func = K.function([vgg_model.input], [f0])

# to call it:
outputs = func([your_image_arrays])

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

How to replace (or insert) intermediate layer in Keras model?

分類Dev

mapbox gl js: use intermediate rendering step as mask for custom layer

分類Dev

How to use OnTouchEvent Correctly?

分類Dev

How to fix "the model is used as in intermediate model but it does not have foreign key to a model"?

分類Dev

How to use LIBGDX FrameBuffer correctly

分類Dev

How to use gzip correctly in a makefile?

分類Dev

How to remove the FC layer off of a fine turned model keras

分類Dev

Vue - How to use computed properties correctly in VueJS?

分類Dev

How to use redux-observable and promise correctly?

分類Dev

How to use the result of a full outer join correctly?

分類Dev

how to use correctly bcrypt php class

分類Dev

How to correctly use in sys/select.h

分類Dev

How to use System.import() correctly?

分類Dev

Pytorch: Converting a VGG model into a sequential model, but getting different outputs

分類Dev

How to use the custom model in MVC

分類Dev

How to use Symbols with Mongoose model?

分類Dev

How to correctly update the Model after the ViewModel has changed?

分類Dev

How to correctly display data stored in an external model without refreshing the page?

分類Dev

How to correctly pass a model as a string using jsonEncode / jsonDecode in dart

分類Dev

Mongoose Deep Populate limiting intermediate model

分類Dev

Laravel Eager Loading through an intermediate Model

分類Dev

Can Firebase be connected to Angular directly without any intermediate layer?

分類Dev

In graph data structure how can we use intermediate node to calculate distance of any other two nodes?

分類Dev

How to use keras embedding layer with 3D tensor input?

分類Dev

How to create a scope for an intermediate table?

分類Dev

How to SSH via intermediate server

分類Dev

How to ignore some input layer, while predicting, in a keras model trained with multiple input layers?

分類Dev

How to use model types between projects?

分類Dev

How to use linux device model and /sys filesystem?

Related 関連記事

  1. 1

    How to replace (or insert) intermediate layer in Keras model?

  2. 2

    mapbox gl js: use intermediate rendering step as mask for custom layer

  3. 3

    How to use OnTouchEvent Correctly?

  4. 4

    How to fix "the model is used as in intermediate model but it does not have foreign key to a model"?

  5. 5

    How to use LIBGDX FrameBuffer correctly

  6. 6

    How to use gzip correctly in a makefile?

  7. 7

    How to remove the FC layer off of a fine turned model keras

  8. 8

    Vue - How to use computed properties correctly in VueJS?

  9. 9

    How to use redux-observable and promise correctly?

  10. 10

    How to use the result of a full outer join correctly?

  11. 11

    how to use correctly bcrypt php class

  12. 12

    How to correctly use in sys/select.h

  13. 13

    How to use System.import() correctly?

  14. 14

    Pytorch: Converting a VGG model into a sequential model, but getting different outputs

  15. 15

    How to use the custom model in MVC

  16. 16

    How to use Symbols with Mongoose model?

  17. 17

    How to correctly update the Model after the ViewModel has changed?

  18. 18

    How to correctly display data stored in an external model without refreshing the page?

  19. 19

    How to correctly pass a model as a string using jsonEncode / jsonDecode in dart

  20. 20

    Mongoose Deep Populate limiting intermediate model

  21. 21

    Laravel Eager Loading through an intermediate Model

  22. 22

    Can Firebase be connected to Angular directly without any intermediate layer?

  23. 23

    In graph data structure how can we use intermediate node to calculate distance of any other two nodes?

  24. 24

    How to use keras embedding layer with 3D tensor input?

  25. 25

    How to create a scope for an intermediate table?

  26. 26

    How to SSH via intermediate server

  27. 27

    How to ignore some input layer, while predicting, in a keras model trained with multiple input layers?

  28. 28

    How to use model types between projects?

  29. 29

    How to use linux device model and /sys filesystem?

ホットタグ

アーカイブ