python - 神经网络检测两幅图像之间的相机位置变化
问题描述
我想在一组照片上训练一个模型,以相机位置和相机角度作为输出,但我找不到有关接受两张图片作为输入的网络架构的信息。我应该关注什么?
解决方案
Keras 提供两种模型 api
- 顺序:用于线性模型1输入1输出全部顺序
- 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
这是您的模型,有两个输入作为图像
推荐阅读
- keras - keras.layers.BatchNormalization() 中的第一个轴是 0 还是 1?
- flutter - Flutter:无法访问音频播放器包的资源
- r - 如何在 R 中抑制 download.file()“正在尝试 URL ...”消息?
- mysql - 如果sql查询中的记录相同,如何分配相同的唯一行号?
- reactjs - 在 Ionic/React 中使用“history.push”并将“IonTabs”作为嵌套路由后,页面未呈现
- java - 使用函数返回的值作为新数组的名称
- vba - 如果满足条件,如何删除书签之前的一串文本?
- c# - EF Core - 多对多与另一个外键
- django - 为什么即使路由器不允许迁移,也会创建 django_migrations 表?
- angular - Rxjs:对Typescript的角度可拖动矩形差异鼠标响应