首页 > 解决方案 > 神经网络检测两幅图像之间的相机位置变化

问题描述

我想在一组照片上训练一个模型,以相机位置和相机角度作为输出,但我找不到有关接受两张图片作为输入的网络架构的信息。我应该关注什么?

标签: pythontensorflowkeras

解决方案


Keras 提供两种模型 api

  1. 顺序:用于线性模型1输入1输出全部顺序
  2. Model api:用于制作任何输入张量和任何输出张量的模型。

你的问题模型可以这样形成:

from tensorflow.keras.layers import Input, concatenate, add, Dense, Conv2d
from tensorflow.keras.models import Model

input1 = Input(shape=(224, 224, 3))  # where (224, 224, 3) is the image dimensions
input2 = Input(shape=(224, 224, 3))  #I'm supposing your both images have same shape
x = concatenate([input1, input2]) or add([input1, input2]) #whatever suits
x = Conv2D(filters=32, kernel_size=3, padding='same')(x) #taking input above layer for this(Conv2D) layer
x = Conv2D(filters=32, kernel_size=3, padding='same')(x) #taking input above layer for this(Conv2D) layer
x = Flatten()(x)
x = Dense(10)(x)
model = Model([ipnut1, input2], x)   #this keras Model Functional api took two arguments 1. list of input tensor or a input tensor   2. list of output tensor or a tensor
model.summary()

Model: "functional_1"
__________________________________________________________________________________________________
Layer (type)                    Output Shape         Param #     Connected to                     
==================================================================================================
input_1 (InputLayer)            [(None, 224, 224, 3) 0                                            
__________________________________________________________________________________________________
input_2 (InputLayer)            [(None, 224, 224, 3) 0                                            
__________________________________________________________________________________________________
concatenate (Concatenate)       (None, 224, 224, 6)  0           input_1[0][0]                    
                                                                 input_2[0][0]                    
__________________________________________________________________________________________________
conv2d (Conv2D)                 (None, 224, 224, 32) 1760        concatenate[0][0]                
__________________________________________________________________________________________________
conv2d_1 (Conv2D)               (None, 224, 224, 32) 9248        conv2d[0][0]                     
__________________________________________________________________________________________________
flatten (Flatten)               (None, 1605632)      0           conv2d_1[0][0]                   
__________________________________________________________________________________________________
dense_3 (Dense)                 (None, 10)           16056330    flatten[0][0]                    
==================================================================================================
Total params: 16,067,338
Trainable params: 16,067,338
Non-trainable params: 0

这是您的模型,有两个输入作为图像

这是模型的可视化


推荐阅读