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

NotImplementedError: Module is missing the required “forward“ function

這篇具有很好參考價值的文章主要介紹了NotImplementedError: Module is missing the required “forward“ function。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

在做中文文本情感分析model類定義的時候報錯如下:

NotImplementedError: Module is missing the required “forward“ function,python,深度學習,pytorch

有兩種可能:

1.重寫父類函數(shù)時,函數(shù)名稱寫錯,我將寫成了?最終導致程序報錯:

import torch
import torch.nn as nn
import torch.nn.functional as F
import numpy as np

class Model(nn.Module):
    def __init__(self,config):
        super(Model, self).__init__()
        self.embeding = nn.Embedding(config.n_vocab, config.embed_size,padding_idx=config.n_vocab - 1)
        self.lstm = nn.LSTM(config.embed_size, config.hidden_size,
config.num_layers,
bidirectional=True,batch_first=True,
dropout=config.dropout)
        self.maxpool = nn.MaxPool1d(config.pad_size)
        self.fc = nn.Linear(config.hidden_size * 2 + config.embed_size, config.num_classes)
        self.softmax = nn.Softmax(dim=1)

    def forword(self,x):
        embed = self.embeding(x)
        out,_ = self.lstm(embed)
        out = torch.cat((embed,out),2)
        out = F.relu(out)
        out = out.permute(0,2,1)
        out = self.maxpool(out).reshape(out.size()[0],-1)
        out = self.fc(out)
        out = self.softmax(out)
        return out

if __name__ == "__main__":
    from configs import Config

    cfg = Config()
    cfg.pad_size = 640
    model_textcls = Model(config = cfg)
    input_tensor = torch.tensor([i for i in range(640)]).reshape([1,640])
    out_tensor = model_textcls.forward(input_tensor)
    print(out_tensor.size())
    print(out_tensor)

2.def forward函數(shù)與def __init__(self,config):一定要對齊。文章來源地址http://www.zghlxwxcb.cn/news/detail-627325.html

到了這里,關于NotImplementedError: Module is missing the required “forward“ function的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!

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

領支付寶紅包贊助服務器費用

相關文章

  • HttpMessageNotReadableException: Required request body is missing:

    HttpMessageNotReadableException: Required request body is missing:

    完整錯誤: Resolved [org.springframework.http.converter.HttpMessageNotReadableException: Required request body is missing: public java.lang.Object com.example.sx.study.Econtroller.test1(com.example.sx.study.Entity,org.springframework.validation.BindingResult)] 解決辦法: 在@RequestBody后加上( required = false ) 雖然通過此方法的確返回了

    2023年04月08日
    瀏覽(13)
  • Required request body is missing 報錯解決

    Required request body is missing 報錯解決

    用 PostMan 測試 POST 類型的接口時,出現(xiàn)錯誤: 直白的翻譯就是該傳的參數(shù)沒能傳遞到后端。我的傳參是表單格式: 后端接口的參數(shù)接收使用了注解 @RequestBody ,猜想應該是參數(shù)格式有問題,把它改成 JSON 格式傳遞,再次運行就 OK 了。

    2024年02月12日
    瀏覽(26)
  • postman請求時報錯Required request body is missing:

    postman請求時報錯Required request body is missing:

    postman調(diào)試端口時后臺報錯:Required request body is missing: postman這里使用了錯誤的書寫方式 將網(wǎng)頁請求參數(shù)以json的形式寫在Body的raw中

    2024年02月12日
    瀏覽(23)
  • Required request body is missing: 前端接口報錯錯誤解決

    Required request body is missing: 前端接口報錯錯誤解決

    在前幾天的工作中遇到了一個小小的問題 這是完整報錯: 這個接口在Apifox上經(jīng)過測試是沒有問題的,那么因此就是前端接口設置出了問題。 解決方法: 這個接口報錯的大意是:必需的請求正文缺失 因此檢查一下接口文檔,發(fā)現(xiàn)數(shù)據(jù)是寫在body里的 因此返回檢查接口代碼,代

    2024年02月15日
    瀏覽(18)
  • Api接口出現(xiàn)Required request body is missing的解決方法

    在使用PostMan 測試接口的時候,出現(xiàn)如下問題:

    2024年02月15日
    瀏覽(15)
  • post請求出現(xiàn)required request body is missing錯誤的問題所在?

    post請求出現(xiàn)required request body is missing錯誤的問題所在?

    后端接口查詢獲取數(shù)據(jù)庫中的數(shù)據(jù),前端接受數(shù)據(jù)進行列表展示。 后端接口swagger測試無誤,前端報錯500:required request body is missing 給出以下兩點原因及其方案: 1.后端原因:controller中該接口函數(shù)的參數(shù)應為請求體@RequestBody,而不是@RequestParam 改為: 2.前端原因:POST與GET請求

    2024年02月04日
    瀏覽(20)
  • Postman發(fā)送post請求時報400錯誤,Required request body is missing

    Postman發(fā)送post請求時報400錯誤,Required request body is missing

    項目形參位置存在@RequestBody注解,用Postman發(fā)送post請求時報400錯誤,Required request body is missing。 錯誤圖示: 解決方法: 方法一: 項目中形參位置不使用@RequestBody,在Postman進行Post請求時,在請求路徑后直接拼接參數(shù)。 方法二: 項目中形參位置使用@RequestBody,在Postman進行Po

    2024年02月11日
    瀏覽(26)
  • org.springframework.http.converter.HttpMessageNotReadableException: Required request body is missing

    報錯信息 控制臺輸出的是缺少必須的請求正文 發(fā)現(xiàn)從前端 走的請求 攜帶一個參數(shù) 到后端沒有接收到 前端代碼 后端代碼 原因: 報錯時:后臺代碼使用@RequestBody 注解報錯i 前端發(fā)送請求,沒有進這個controller 把@RequestBody 換成 @PathVariable 就好了 注解@RequestBody接收的參數(shù)是來自

    2024年02月03日
    瀏覽(22)
  • SpringBoot之Post請求@RequestBody為空拋出Required request body is missing異常的解決方案

    org.springframework.http.converter.HttpMessageNotReadableException: Required request body is missing 出現(xiàn)異常的原因:body為空,但是@RequestBody注解默認請求體不能為空。 這個純屬粗心大意的問題~ 如果是剛剛開發(fā)的項目,那么建議這樣寫。如果已經(jīng)存在的項目,肯定不能這樣寫,后面會介紹另外一

    2024年02月13日
    瀏覽(36)
  • 報錯 “Required request body is missing: public“ 的解決方案以及注意點(Vue, axios攔截器)

    報錯 “Required request body is missing: public“ 的解決方案以及注意點(Vue, axios攔截器)

    在使用axios攔截器時,返回500,報了\\\"Required request body is missing: public\\\"的錯誤,我的攔截器是這么寫的,參考了以下鏈接: http://www.45fan.com/article.php?aid=1D2dBLoGSZ31XuGv#_label1 我這里的基礎地址在我本地換成了接口的域名地址。 然后在api/index.js的文件里面,這樣應用的:? 然后報錯

    2024年02月10日
    瀏覽(38)

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

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

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

二維碼1

領取紅包

二維碼2

領紅包