亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Pytorch:獲取最后一層的正確尺寸

Pytorch:獲取最后一層的正確尺寸

精慕HU 2021-07-20 16:47:25
Pytorch 新手來了!我正在嘗試微調 VGG16 模型以預測 3 個不同的類別。我的部分工作涉及將 FC 層轉換為 CONV 層。但是,我的預測值不在 0 到 2(3 個類別)之間。有人能給我指出一個關于如何計算最后一層正確尺寸的好資源嗎?以下是 VGG16 的原始 fC 層:(classifier): Sequential(    (0): Linear(in_features=25088, out_features=4096, bias=True)    (1): ReLU(inplace)    (2): Dropout(p=0.5)    (3): Linear(in_features=4096, out_features=4096, bias=True)    (4): ReLU(inplace)    (5): Dropout(p=0.5)    (6): Linear(in_features=4096, out_features=1000, bias=True)  )我將 FC 層轉換為 CONV 的代碼: def convert_fc_to_conv(self, fc_layers):        # Replace first FC layer with CONV layer        fc = fc_layers[0].state_dict()        in_ch = 512        out_ch = fc["weight"].size(0)        first_conv = nn.Conv2d(512, out_ch, kernel_size=(1, 1), stride=(1, 1))        conv_list = [first_conv]        for idx, layer in enumerate(fc_layers[1:]):            if isinstance(layer, nn.Linear):                fc = layer.state_dict()                in_ch = fc["weight"].size(1)                out_ch = fc["weight"].size(0)                if idx == len(fc_layers)-4:                    in_ch = 3                conv = nn.Conv2d(out_ch, in_ch, kernel_size=(1, 1), stride=(1, 1))                conv_list += [conv]            else:                conv_list += [layer]            gc.collect()        avg_pool = nn.AvgPool2d(kernel_size=2, stride=1, ceil_mode=False)        conv_list += [avg_pool, nn.Softmax()]        top_layers = nn.Sequential(*conv_list)          return top_layers
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 478 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號