土壤分析:基于光谱与图像的多维特性反演

FreeGuideOnline 最新 2026-06-26

python class FusionModel(nn.Module): def init(self): self.spec_net = nn.Sequential( nn.Conv1d(1,16,5), nn.ReLU(), nn.MaxPool1d(2), nn.Conv1d(16,32,5), nn.ReLU(), nn.AdaptiveAvgPool1d(1) ) # 输出 32 维 self.img_net = models.mobilenet_v2(pretrained=True) self.img_net.classifier = nn.Identity() # 输出 1280 维 self.fusion = nn.Sequential( nn.Linear(32+1280, 64), nn.ReLU(), nn.Dropout(0.3), nn.Linear(64, 1) ) def forward(self, spec, img): s = self.spec_net(spec).squeeze() i = self.img_net(img) return self.fusion(torch.cat([s,i], dim=1))