【发布时间】:2020-04-19 02:18:56
【问题描述】:
我有这个模型:
class model(nn.Module):
def __init__(self):
super().__init__()
self.conv1 = nn.Conv2d(in_channels=12,out_channels=64,kernel_size=3,stride= 1,padding=1)
# self.conv2 = nn.Conv2d(in_channels=64,out_channels=64,kernel_size=3,stride= 1,padding=1)
self.fc1 = nn.Linear(24576, 128)
self.bn = nn.BatchNorm1d(128)
self.dropout1 = nn.Dropout2d(0.5)
self.fc2 = nn.Linear(128, 10)
self.fc3 = nn.Linear(10, 3)
def forward(self, x):
x = F.relu(self.conv1(x))
# x = F.relu(self.conv2(x))
x = F.max_pool2d(x, (2,2))
# print(x.shape)
x = x.view(-1,24576)
x = self.bn(F.relu(self.fc1(x)))
x = self.dropout1(x)
embeding_stage = F.relu(self.fc2(x))
x = self.fc3(embeding_stage)
return x
我想保存 embeding_stage 层,就像我在这里保存模型一样:
model = model()
torch.save(model.state_dict(), 'C:\project\count_speakers\model_pytorch.h5')
谢谢, 阿亚尔
【问题讨论】:
-
保存
embeding_stage是什么意思?你想保存self.fc2()层吗? -
为什么
torch.save不能满足您的需求?
标签: pytorch