如何修改PyTorch的Prediction結果?

output = model(images)             #模型輸出得到Output
_, preds = torch.max(output, 1) #轉換成實際的label(preds)
# 將preds搭配lambda function,只要preds中的預測結果有大於1的數值,則全轉換成1
preds = torch.tensor([(lambda i: 1 if i > 1 else i)(i) for i in preds]).cuda()
target = torch.tensor([(lambda i: 1 if i > 1 else i)(i) for i in target]).cuda()# 如此一來,我們的模型就能以2個label的方式進行輸出

--

--

--

Machine Learning | Deep Learning | https://linktr.ee/yanwei

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Yanwei Liu

Yanwei Liu

Machine Learning | Deep Learning | https://linktr.ee/yanwei

More from Medium

VAR-CNN(Football): Foul or Clean Tackle

12 Activation Functions That You May Want To Consider — Part-1

The computer vision bias trilogy: Data representativity

Predicting Sine Wave Output and Visualizing the Deep Learning Network