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

RuntimeError mat1 and mat2 shapes cannot be multiplied

這篇具有很好參考價(jià)值的文章主要介紹了RuntimeError mat1 and mat2 shapes cannot be multiplied。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

詳細(xì)顯示如下

x = self.fc(x)
File “D:\Python36\lib\site-packages\torch\nn\modules\module.py”, line 1102, in _call_impl
return forward_call(*input, **kwargs)
File “D:\Python36\lib\site-packages\torch\nn\modules\linear.py”, line 103, in forward
return F.linear(input, self.weight, self.bias)
File “D:\Python36\lib\site-packages\torch\nn\functional.py”, line 1848, in linear
return torch._C._nn.linear(input, weight, bias)
RuntimeError: mat1 and mat2 shapes cannot be multiplied (8x704 and 2304x4)

根據(jù)提示,全連接層兩個(gè)需要相乘的矩陣維度不匹配,代碼中batchSize為8,最后的類別數(shù)量為4。

原因,樣本總數(shù)不是批次的倍數(shù),有余數(shù),因此,最后一個(gè)批次的樣本會(huì)產(chǎn)生該問題。

解決方案1,dataloader中需要設(shè)置參數(shù)drop_last=True。即丟棄最后一個(gè)不足batchSize的樣本。

trainLoader = DataLoader(dataset=trainSet, batch_size=batchSize, shuffle=True, drop_last=True)

解決方案2,reshape時(shí)使用樣本的數(shù)量文章來源地址http://www.zghlxwxcb.cn/news/detail-418987.html

......
for seq, y_train in trainLoader:
	sampleSize = seq.shape[0]
	optimizer.zero_grad()
    y_pred = model(seq.reshape(sampleSize, 1, -1)) # Dataloader中drop_last=False
    # y_pred = model(seq.reshape(batchSize, 1, -1))
......

到了這里,關(guān)于RuntimeError mat1 and mat2 shapes cannot be multiplied的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場。本站僅提供信息存儲(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: mat1 dim 1 must match mat2 dim 0 解決方法

    RuntimeError: mat1 dim 1 must match mat2 dim 0 解決方法

    RuntimeError: mat1 dim 1 must match mat2 dim 0 這個(gè)錯(cuò)誤的大概意思是:矩陣mat1 的第二維度要與mat2的第一維度不匹配 在新增別的數(shù)據(jù)集進(jìn)行訓(xùn)練時(shí)報(bào)當(dāng)前錯(cuò)誤,原因是輸入的圖像大小與之前不一樣,這是新手在學(xué)習(xí)時(shí)常會(huì)遇到的問題。 先看報(bào)錯(cuò)信息,確定報(bào)錯(cuò)位置 我的這個(gè)代碼是

    2024年02月15日
    瀏覽(21)
  • RuntimeError: Input type (unsigned char) and bias type (float) should be the same錯(cuò)誤

    這個(gè)錯(cuò)誤通常是由于輸入數(shù)據(jù)類型與模型參數(shù)的類型不匹配導(dǎo)致的。在PyTorch中,當(dāng)輸入的張量類型與模型的參數(shù)類型不匹配時(shí),PyTorch會(huì)嘗試將它們轉(zhuǎn)換為相同的類型,但是當(dāng)它們的類型不可轉(zhuǎn)換時(shí),就會(huì)出現(xiàn)這個(gè)錯(cuò)誤。 解決辦法是確保輸入的張量類型與模型的參數(shù)類型相同

    2024年02月15日
    瀏覽(16)
  • RuntimeError: Input type (torch.cuda.FloatTensor) and weight type (torch.FloatTensor) should be the

    RuntimeError: Input type (torch.cuda.FloatTensor) and weight type (torch.FloatTensor) should be the

    問題描述: mobilenetv3在殘差塊中加入了注意力機(jī)制?用GPU 進(jìn)行訓(xùn)練時(shí)報(bào)的錯(cuò) 解決方法1: 1,不用GPU 用CPU 就可以 CUDA 設(shè)置為False,確實(shí)可以解決,但是不用GPU 好像意義不大 解決方法2 : 用仍然用GPU ,看下面的的解決方案: 報(bào)錯(cuò)的原因:2 1,我直接在倒殘差塊的前向傳播內(nèi)對(duì)導(dǎo)

    2024年02月16日
    瀏覽(24)
  • Commit cannot be completed since the group has already rebalanced and assign

    Commit cannot be completed since the group has already rebalanced and assign

    這里是說提交commit失敗, 因?yàn)檫@個(gè)組已經(jīng)重新分配了 正常情況下, kafka會(huì)有一個(gè)配置用于設(shè)置一條消息的過期時(shí)間, 在規(guī)定時(shí)間內(nèi), 如果消費(fèi)者提交了消費(fèi)完成的信息, 那么就可以正常的分配下一條記錄給消費(fèi)者, 并且將當(dāng)前記錄的狀態(tài)記為\\\"已消費(fèi)\\\"狀態(tài), 對(duì)消息隊(duì)列做一個(gè)標(biāo)識(shí)

    2024年02月11日
    瀏覽(22)
  • ERROR: Could not build wheels for pycocotools which use PEP 517 and cannot be installed directl

    ERROR: Could not build wheels for pycocotools which use PEP 517 and cannot be installed directl

    安裝yolov5依賴庫時(shí),最后pycocotools報(bào)錯(cuò) 重點(diǎn)是以下原因: error: Microsoft Visual C++ 14.0 or greater is required. Get it with \\\"Microsoft C++ Build Tools\\\": https://visualstudio.microsoft.com/visual-cpp-build-tools/ 嘗試的解決方法如下: 1、直接下載VS2022中,工作負(fù)荷里有關(guān)C++和Python的(未成功) 結(jié)果報(bào)錯(cuò) vs2

    2024年02月02日
    瀏覽(36)
  • git fatal: ‘xxx‘ is not a commit and a branch ‘xxx‘ ‘ cannot be created from it

    當(dāng)拉取一個(gè)git遠(yuǎn)程倉庫分支時(shí)報(bào)錯(cuò): 命令:git checkout -b 本地分支名 遠(yuǎn)程分支名 報(bào)錯(cuò):fatal: \\\'origin/dev_v2.8.4_v10.74.1\\\' is not a commit and a branch \\\'dev_v2.8.4_v10.74.1\\\' cannot be created from it 遠(yuǎn)程新建的分支沒有更新到本地。實(shí)際上,git倉庫分為本地倉庫和遠(yuǎn)程倉庫,我們用 checkout 命令是從本

    2024年02月10日
    瀏覽(21)
  • Could not build wheels for opencv-python which use PEP 517 and cannot be installed directly

    Could not build wheels for opencv-python which use PEP 517 and cannot be installed directly

    當(dāng)我們運(yùn)行代碼要運(yùn)用到cv2庫時(shí),提示我們沒有安裝cv2,而直接用pip install opencv-python下載卻顯示下載失?。?Could not build wheels for opencv-python which use PEP 517 and cannot be installed directly 直接運(yùn)用conda安裝: 隨后完成cv2的安裝。

    2024年02月10日
    瀏覽(37)
  • ERROR: Could not build wheels for opencv-python which use PEP 517 and cannot be installed directly

    ERROR: Could not build wheels for opencv-python which use PEP 517 and cannot be installed directly

    pip install --upgrade -r requirements.txt -i https://mirror.baidu.com/pypi/simple Looking in indexes: https://mirror.baidu.com/pypi/simple Collecting prettytable Downloading https://mirror.baidu.com/pypi/packages/5f/ab/64371af206988d7b15c8112c9c277b8eb4618397c01471e52b902a17f59c/prettytable-3.3.0-py3-none-any.whl (26 kB) Collecting ujson Downloading https://

    2024年01月22日
    瀏覽(25)
  • 【Git報(bào)錯(cuò)】fatal: ‘origin/XXX‘ is not a commit and a branch ‘XXX‘ cannot be created from it

    【Git報(bào)錯(cuò)】fatal: ‘origin/XXX‘ is not a commit and a branch ‘XXX‘ cannot be created from it

    發(fā)現(xiàn)問題 遠(yuǎn)程已有分支,本地需要新建對(duì)應(yīng)分支,于是執(zhí)行命令: git checkout --track origin/XXX 時(shí)報(bào)錯(cuò)。 原因: 遠(yuǎn)程真的沒有這個(gè)分支,所以失敗 這個(gè)情況沒什么好說的 遠(yuǎn)程有這個(gè)分支,但是本地認(rèn)為遠(yuǎn)程沒有這個(gè)分支 執(zhí)行如下命令,查看本地緩存的所有遠(yuǎn)程分支,看看你要

    2024年02月16日
    瀏覽(22)
  • Could not build wheels for opencv-python-headless which use PEP 517 and cannot be installed directly

    筆者是python環(huán)境下安裝 albumentations 出現(xiàn)的,該庫經(jīng)常用于圖像增強(qiáng),在cv領(lǐng)域有很大的知名度。在使用下邊的命令進(jìn)行安裝后 就報(bào)了 ERROR:Could not build wheels for opencv-python-headless which use PEP 517 and cannot be installed directly 。 albumentations庫依賴opencv,在直接使用pip命令安裝時(shí),albumen

    2024年02月15日
    瀏覽(22)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

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

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

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包