필터 지우기
필터 지우기

Keras Network: Placeholder for 'BilinearUpSampling2D'

조회 수: 3 (최근 30일)
jose daniel hoyos giraldo
jose daniel hoyos giraldo 2022년 9월 3일
댓글: Sivylla Paraskevopoulou 2022년 9월 13일
Hello, I'm trying to use a keras network for depth estimation from a monocular view.
I'm following this: https://www.mathworks.com/help/deeplearning/ref/importkerasnetwork.html
The problem is that when I try:
placeholderLayers = findPlaceholderLayers(lgraph)
I got layers of this type:
2 'up1_upsampling2d' PLACEHOLDER LAYER Placeholder for 'BilinearUpSampling2D' Keras layer
which I dont know how to deal with.
Thanks!

답변 (1개)

Sivylla Paraskevopoulou
Sivylla Paraskevopoulou 2022년 9월 6일
편집: Sivylla Paraskevopoulou 2022년 9월 6일
You have a few options:
  1. Instead of the importKerasNetwork function, use the importTensorFlowNetwork function. The importTensorFlowNetwork function is the newest and recommended function. The importTensorFlowNetwork function generates a custom layer when you import a TensorFlow layer that the software cannot convert into an equivalent built-in MATLAB layer. Then, you will have a network that is ready to use. Note, that you must convert your TensorFlow model from .h5 format to SavedModel format to use the importTensorFlowNetwork function. For more information on the differences between importKerasNetwork and importTensorFlowNetwork functions, see Importing Models from TensorFlow, PyTorch, and ONNX.
  2. You can replace the placeholder layer with a resize2dLayer or resize3dLayer.
  3. You can replace the placeholder layer with your own custom layer.
  댓글 수: 2
jose daniel hoyos giraldo
jose daniel hoyos giraldo 2022년 9월 8일
Hello, thanks for answering.
I tried the 1 option but I was unable to convert the keras network to tensorflow becasue these "custom" layers ( 'BilinearUpSampling2D'). On the other hand, I tried second option with this code:
modelfile = 'kitti.h5';
lgraph = importKerasLayers(modelfile,'ImportWeights',true);
placeholders = findPlaceholderLayers(lgraph)
input1 = placeholders(1);
upsampling1 = placeholders(2);
upsampling2 = placeholders(3);
upsampling3 = placeholders(4);
upsampling4 = placeholders(5);
gnLayer1 = resize2dLayer('Scale',1);
lgraph = replaceLayer(lgraph,'up1_upsampling2d',gnLayer1);
lgraph = replaceLayer(lgraph,'up2_upsampling2d',gnLayer1);
lgraph = replaceLayer(lgraph,'up3_upsampling2d',gnLayer1);
lgraph = replaceLayer(lgraph,'up4_upsampling2d',gnLayer1);
net = assembleNetwork(lgraph)
But it says:
Error using assembleNetwork
Invalid network.
Caused by:
Network: Missing output layer. The network must have at least one output layer.
Network: Missing input layer. The network must have at least one input layer.
Layer 'conv3': Unconnected output. Each layer output must be connected to the
input of another layer.
Layer 'input_1': Unconnected input. Each layer input must be connected to the
output of another layer.
By the way, I used the scale factor as 1 because I cant see information in the keras loaded from matlab about the size of the image.
Thanks
Sivylla Paraskevopoulou
Sivylla Paraskevopoulou 2022년 9월 13일
The assembleNetwork function expects the assembled layers to include input and output layers. You can add layers by using the addLayers function.
Also, it looks like you are replacing the placeholder upsampling layers with gaussian noise layers. I don't think these two types of layers have the same functionality.
I still think it would be easier to convert your model from .h5 to SavedModel using Python and then import it by using the importTensorFlowNetwork function.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Image Data Workflows에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by