国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

only batches of spatial targets supported (3D tensors) but got targets of dimension

這篇具有很好參考價(jià)值的文章主要介紹了only batches of spatial targets supported (3D tensors) but got targets of dimension。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

問(wèn)題產(chǎn)生的原因是使用nn.CrossEntropyLoss()來(lái)計(jì)算損失的時(shí)候,target的維度超過(guò)4

import torch
import torch.nn as nn

logit = torch.ones(size=(4, 32, 256, 256))  # b,c,h,w
target = torch.ones(size=(4, 1, 256, 256))

criterion = nn.CrossEntropyLoss()
loss = criterion(logit, target)

only batches of spatial targets supported (3D tensors) but got targets of dimension

如實(shí)target中的C不是1,則可以:

import torch
import torch.nn as nn

logit = torch.ones(size=(4, 32, 256, 256))  # b,c,h,w
target = torch.ones(size=(4, 2, 256, 256))

criterion = nn.CrossEntropyLoss()
losses = 0
for i in range(2):
    loss = criterion(logit, target[:, i, ...].long())
    losses += loss

?可以看到代碼里面有個(gè).long(),如果不用的話則會(huì)報(bào)錯(cuò):

RuntimeError: expected scalar type Long but found Float文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-508363.html

到了這里,關(guān)于only batches of spatial targets supported (3D tensors) but got targets of dimension的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • 記錄解決RuntimeError: Sizes of tensors must match except in dimension 1. Expected size 27 but got size

    記錄解決RuntimeError: Sizes of tensors must match except in dimension 1. Expected size 27 but got size

    在做目標(biāo)檢測(cè)服務(wù)過(guò)程中,將yolov7模型通過(guò)flask打包成預(yù)測(cè)服務(wù)API,此次訓(xùn)練的圖像輸入大小是1280,輸入預(yù)測(cè)圖片是如果圖像大于1280則預(yù)測(cè)成功,小于1280則報(bào)RuntimeError: Sizes of tensors must match except in dimension 1. Expected size 27 but got size。 由于只有小圖片預(yù)測(cè)報(bào)錯(cuò),猜測(cè)是圖像處理

    2024年02月11日
    瀏覽(35)
  • Python執(zhí)行selenium報(bào)錯(cuò)This version of ChromeDriver only supports Chrome version并配置環(huán)境變量

    Python執(zhí)行selenium報(bào)錯(cuò)This version of ChromeDriver only supports Chrome version并配置環(huán)境變量

    1.This version of ChromeDriver only supports Chrome version 這個(gè)報(bào)錯(cuò)的意思是chrome驅(qū)動(dòng)的版本不匹配,所以需要查看自己的chrome的版本,再根據(jù)版本下載對(duì)應(yīng)的chromedriver.exe,具體操作步驟如下 第一步查看chrome的版本: 第二步下載對(duì)應(yīng)的chromedriver.exe: http://chromedriver.storage.googleapis.com/ind

    2024年02月16日
    瀏覽(28)
  • python/selenium中msedgedriver版本自動(dòng)更新,解決“This version of MSEdgeDriver only supports MSEdge version 100“

    目錄 前言 一、如何識(shí)別Edge瀏覽器的版本? 二、自動(dòng)更新代碼 1.引入庫(kù) 2.構(gòu)造解壓文件函數(shù) 3.更新msedgedriver文件

    2024年02月03日
    瀏覽(111)
  • 張量(Tensor)維度尺寸對(duì)不齊(Expected size xx but got size xx for tensor)

    本文以 U-Net 舉例,演示如何解決 張量(Tensor)維度尺寸對(duì)不齊 的問(wèn)題 U-Net 的網(wǎng)絡(luò)架構(gòu)可以參考這篇文章:U-Net原理分析與代碼解讀 這是本文演示所用的 U-Net代碼 : 假設(shè)本文輸入的圖像是 600乘以400像素 的尺寸,那么對(duì)于本文U-Net代碼所需的 512乘以512像素 的輸入是肯定 不匹配

    2024年02月02日
    瀏覽(34)
  • selenium執(zhí)行出現(xiàn)異常,SessionNotCreatedException ChromeDriver only supports

    selenium執(zhí)行出現(xiàn)異常,SessionNotCreatedException ChromeDriver only supports

    運(yùn)行程序報(bào)錯(cuò): selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 114 Current browser version is 121.0.6167.85 with binary path /Applications/Google Chrome.app/Contents/MacOS/Google Chrome 系統(tǒng)的chrome瀏覽器自動(dòng)升級(jí)了,導(dǎo)致selenium依賴的chrome內(nèi)

    2024年01月25日
    瀏覽(24)
  • 解決only one element tensors can be converted to Python scalars

    目錄 解決 \\\"only one element tensors can be converted to Python scalars\\\" 錯(cuò)誤 問(wèn)題源頭 解決方法 方法一:使用??item()??方法 方法二:使用索引操作 總結(jié) 語(yǔ)法 參數(shù) 返回值 使用場(chǎng)景 示例 當(dāng)我們使用PyTorch進(jìn)行深度學(xué)習(xí)任務(wù)時(shí),有時(shí)會(huì)遇到以下錯(cuò)誤信息:\\\"only one element tensors can be conve

    2024年02月03日
    瀏覽(31)
  • ERROR: There can be only one Game target per project.

    ERROR: There can be only one Game target per project.

    UATHelper: Packaging (Windows (64-bit)): ERROR: There can be only one Game target per project. D:dockIntermediateSource 把舊的文件刪去 一般會(huì)出現(xiàn)在更改項(xiàng)目名稱后 感謝 There can be only one Game target per project - Development Discussion / Content Creation - Unreal Engine ForumsThere can be only one Game target per project -?

    2024年02月08日
    瀏覽(33)
  • Pandas告警UserWarning: pandas only supports SQLAlchemy connectable

    Pandas告警UserWarning: pandas only supports SQLAlchemy connectable

    使用老的書(shū)寫(xiě)方式從數(shù)據(jù)庫(kù)導(dǎo)入數(shù)據(jù)到pandas, 會(huì)打出一條warning信息: 老的書(shū)寫(xiě)方式為: 按照提示,推薦使用SQLAlchemy,需要先安裝SQLAlchemy庫(kù): 新版本的pandas庫(kù)中con參數(shù)使用sqlalchemy庫(kù)創(chuàng)建的create_engine對(duì)象 。創(chuàng)建create_engine對(duì)象(格式類似于URL地址)

    2024年02月16日
    瀏覽(24)
  • backurl: heytapbrowser://main/iflow?sub_target=only_enter_iflow

    backurl: heytapbrowser://main/iflow?sub_target=only_enter_iflow 各瀏覽器/搜索引擎蜘蛛useragent舉例: 1、IE10 Mozilla/5.0 (MSIE 10.0; Windows NT 6.1; Trident/5.0) 2、iPhone6 Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25 3、iPad Mozilla/5.0 (iPad; CPU OS 6_0

    2024年02月06日
    瀏覽(13)
  • RuntimeError: stack expects each tensor to be equal size, but got at entry

    RuntimeError: stack expects each tensor to be equal size, but got at entry

    參考鏈接:??????解決Pytorch dataloader時(shí)報(bào)錯(cuò)每個(gè)tensor維度不一樣的問(wèn)題_python_腳本之家 記錄一下自己遇到的bug: 問(wèn)題描述:? 問(wèn)題分析: torch.stack(batch, 0, out=out)出錯(cuò),原因可能是: 同一個(gè)batch的數(shù)據(jù)圖片的維度(H, W, C)要相同(可以見(jiàn)官方文檔:其shape必須一致) 問(wèn)

    2024年02月15日
    瀏覽(23)

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包