optimizer can only optimize Tensors, but one of the params is set的一個可能原因
下面的程式碼會提示錯誤:
[{mlp.parameters() for mlp in mlps},lr=LR]]
改成下面的可以解決錯誤:
[{"params":mlp.parameters()} for mlp in mlps,lr=LR]
可能是因為這裡的引數應該是一個字典型別,或者是一個tensor。
當代碼是這樣的時候:
optimizer=torch.optim.Adam([mlps[1].parameters(),mlps[2].parameters()],lr=LR)
提示錯誤:
TypeError: optimizer can only optimize Tensors, but one of the params is Module.parameters
改成下面的可以正常執行:
optimizer=torch.optim.Adam([{"params":mlps[1].parameters()},{"params":mlps[2].parameters()}],lr=LR)
具體原因請看:python列表推導生成字典的注意事項
後面的學習率等等引數,如果在字典中指定,那麼後面的引數lr將對這個鍵值對不起作用;如果不在字典中指定,就會使用後面的引數,如果使用了字典形式,又沒有在字典中指定學習率,也沒有在後面的引數中指定學習率,就會使用預設值0.001。
相關推薦
optimizer can only optimize Tensors, but one of the params is set的一個可能原因
下面的程式碼會提示錯誤: [{mlp.parameters() for mlp in mlps},lr=LR]] 改成下面的可以解決錯誤: [{"params":mlp.parameters()} for mlp in mlps,lr=LR] 可能是因為這裡的引數應該是一個字典型
One of the World's 7,000 Languages Dies Every Three Months. Can Apps Help Save Them?
Like his ancestors, 65-year-old Clayton Long spent his childhood immersed in Navajo culture, greeting fellow clan members with old, breathful Navajo words
VMware啟動Centos時出現錯誤Cannot open the disk 'xxxxxxx.vmdk' or one of the snapshot disks it depends on. .
每次 pan 鎖定 mic 數據 als log xxxxxx end 今天拔裝虛擬機的硬盤的時候,沒有關掉虛擬機,導致虛擬打開的時候出現:Cannot open the disk ‘xxxxxxx.vmdk‘ or one of the snapshot disk
32-bit Linux Android emulator binaries are DEPRECATED, to use them you will have to do at least one of the following
environ 解決 一行 body blog _for side bit allow ERROR: 32-bit Linux Android emulator binaries are DEPRECATED, to use them you will have to do
使用Mysql Workbench 導入數據庫提示 ERROR 1227 (42000) at line 18: Access denied; you need (at least one of) the SUPER privilege(s) for
很多 workbench enc mys mysql 創建 oot info ima 今天再復制服務器上數據庫的時候(使用Mysql Workbench )提示1227錯誤, 數據庫版本5.7.18,復制到的數據庫也是5.7.18。 總結一下網上的幾種方法: 方法一:
Hadoop上傳檔案報錯could only be written to 0 of the 1 minReplication nodes.
報錯:org.apache.hadoop.ipc.RemoteException(java.io.IOException): File /home/navy/files/yc.txt could only be written to 0 of the 1 minReplic
One of the configured repositories failed
One of the configured repositories failed (Unknown), and yum doesn't have enough cached data to continue. At this point the only safe thing yum
Lunux yum 報錯:One of the configured repositories failed (Unknown), and yum doesn't have.
1. 請先確定你是無法聯網還是配置問題。 ping www.baidu.com 如果是正常ping那可以看這個帖子完成配置 2. 如果是 ping 有問題,那就: 1. 在
Apple and Amazon deny report they were hit by one of the most damaging hacks ever
A new report claims that China managed to spy on large swathes of the world by smuggling tiny computer chips into electronic hardware used to power iPhones
How we rolled out one of the largest Python 3 migrations ever
Dropbox is one of the most popular desktop applications in the world: You can install it today on Windows, macOS, and some flavors of Linux. What you ma
A Conversation with One of the Few Scientists in Congress
A Conversation with One of the Few Scientists in CongressRep. Bill Foster weighs in on the most important science issues facing the countryBy Dina Fine Mar
DotNetCore跨平臺~問題~NETCoreAPP, Version=v1.0' compatible with one of the target runtimes: 'win10-x64
回到目錄 新建console專案之後,編譯程式出現以下錯誤: Can not find runtime target for framework '.NETCoreAPP, Version=v1.0' compatible with one of the target runtimes: 'win10-x
The stunning HP Spectre x360 laptop is $500 off at Best Buy for Cyber Monday weekend — one of the best deals we've seen by far
After all the Black Friday and Cyber Monday deals we've seen in the past few days, we have one thing to say: We get it. Laptops are a big deal. Except for
Vuforia SDK匯入問題Vuforia.UnityExtensions Consider removing one of the references or sign the assembl
匯入Vuforia SDK後就報錯,在csdn搜了一下,根本沒有這方面的資訊,去百度找了一下,有一點收穫所以分享出來,但是我在百度找到的解決方案並沒有解決我現在的這個問題。 大佬若是有解決方案還請不要栗色,拿出來分享一下。 錯誤關鍵詞: UnityExtensions.dll
VMware啟動報錯one of the snapshot disks it depends on ...Failed to lock the file
解決辦法一: 1、在VMware該虛擬機器路徑下的所有.lck檔案和資料夾下刪除或遷移至其它目錄,一般就可以解決了。 2、如果再次啟動VMware的Windows Vista系統失敗,嘗試右鍵虛擬機器出錯的系統->Settings->Hardware
匯入adt專案進入android studio報Error:(2) Error parsing XML: prefix must not be bound to one of the reserved
在匯入Adt用ant編譯的專案進入android studio後,編譯報如下錯誤: Error:(2) Error parsing XML: prefix must not be bound to one of the reserved namespace names 在彈
studio2.3.1中please select at least one of the signature versions to use及提示未安裝
android studio2.3.1版本打包簽名時彈出提示please select at least one of the signature versions to use解決方式 需要勾選 這種方式的簽名(只勾選v2),僅支援7.0及以上版本,不能在7.0以下版本
1227- Access denied; you need (at least one of) the SYSTEM_USER privilege(s) for operation
Centos7 MySQL8.0.16修改 root% 使用者密碼時遇到如下錯誤: 解決如下: 修改mysql登入設定
Version 1.7.0_80 of the JVM is not suitable for this product.Version: 1.8 or greater is required.
2種 方法 mar 技術 bin 啟動 product 分享圖片 1.7 Eclipse啟動失敗,設置eclipse啟動jdk有2種方法 第一種: 直接安裝eclipse對應的jdk版本,並設置環境變量 第二種: 修改eclipse配置文件eclipse.ini
Java:The hierarchy of the type is inconsistent錯誤
ons clas imp 另一個 jar包 service type port 舉例 原因一 在繼承(extends)/實現(implements) 的某個 類/接口 中,這個類/接口所依賴的其他jar,在本類中不能依賴或者引用。 舉例:Class A 繼承(extend