有什么办法,我可以在PyTorch中打印模型的摘要,就像Keras中的model.summary()
方法一样,如下所示?
Model Summary:
____________________________________________________________________________________________________
Layer (type) Output Shape Param # Connected to
====================================================================================================
input_1 (InputLayer) (None, 1, 15, 27) 0
____________________________________________________________________________________________________
convolution2d_1 (Convolution2D) (None, 8, 15, 27) 872 input_1[0][0]
____________________________________________________________________________________________________
maxpooling2d_1 (MaxPooling2D) (None, 8, 7, 27) 0 convolution2d_1[0][0]
____________________________________________________________________________________________________
flatten_1 (Flatten) (None, 1512) 0 maxpooling2d_1[0][0]
____________________________________________________________________________________________________
dense_1 (Dense) (None, 1) 1513 flatten_1[0][0]
====================================================================================================
Total params: 2,385
Trainable params: 2,385
Non-trainable params: 0
Run Code Online (Sandbox Code Playgroud) 我在 PyTorch 中使用一个简单的对象检测模型并使用 Pytoch 模型进行推理。
当我在代码上使用简单的迭代器时
for k, image_path in enumerate(image_list):
image = imgproc.loadImage(image_path)
print(image.shape)
with torch.no_grad():
y, feature = net(x)
result = image.cuda()
Run Code Online (Sandbox Code Playgroud)
它打印我们可变大小的图像,例如
torch.Size([1, 3, 384, 320])
torch.Size([1, 3, 704, 1024])
torch.Size([1, 3, 1280, 1280])
Run Code Online (Sandbox Code Playgroud)
因此,当我使用应用相同转换的 DataLoader 使用批量推理时,代码未运行。但是,当我将所有图像的大小调整为 600.600 时,批处理成功运行。
我有两个疑问,
首先,为什么 Pytorch 能够在深度学习模型中输入动态大小的输入,以及为什么动态大小的输入在批处理中失败。
python machine-learning computer-vision deep-learning pytorch