current position：Home>Pytorch loss = criterion (outputs, y), y has multiple values
Pytorch loss = criterion (outputs, y), y has multiple values
2022-02-03 01:38:03 【CSDN Q & A】
pytorch loss = criterion(outputs, y) ,y What if there are multiple values ？
Namely outputs Output 1 It's worth ,y There are several values , as long as outputs be equal to y in 1 Just a value ,loss = criterion(outputs, y) How to write ？
Part of the code is as follows ：
for epoch in range(num_epochs): train_loss =  # The data in the loader is traversed for batch, data in enumerate(train_loader): #batch Is the number Indicates that several... Have been carried out batch #data Is a binary , The input and label of a data record are stored respectively # The first dimension of each data is batch_size = 30 Array of lstm.train() # sign LSTM In training ,Dropout Start working init_hidden = lstm.initHidden(len(data)) # initialization LSTM The implicit unit variable optimizer.zero_grad() x,y = Variable(data), Variable(data) # Extract input and output pairs from data if use_cuda: x = x.cuda() y = y.cuda() outputs = lstm(x, init_hidden) # Input LSTM, To produce output outputs loss = criterion(outputs, y) # Bring in the loss function and generate loss loss.backward() # Back propagation optimizer.step() # Update gradient if use_cuda: loss = loss.cpu() train_loss.append(loss.data.numpy()) # Record loss
Refer to the answer 1：
Great gods , How to solve this problem ？
Refer to the answer 2：
author[CSDN Q & A],Please bring the original link to reprint, thank you.
The sidebar is recommended
- *Isn't a numerical value? Because a is the address
- The picture of U disk retrieved by app in Android 8.1 development board
- C language beginners' doubts, no, require recursion
- How to use bat or VBS to open Ethernet status window
- Base selection questions, C + + has just begun to learn, can someone give some ideas
- C language function problem,.?!
- Java class related problems
- What library is checkfasta in Python? Why can't you find it
- Problems encountered when deploying HTTPS certificates using docker nginx
- Why can't vs2022 run this code, but the compiler on the mobile phone can
guess what you like
Java type conversion problem, is there a useful tool?
C language function problem, confusion,.?!
Please do me a favor and solve it
Python learning has something you don't understand
How does Baidu Post Bar get posts in it
Who will prompt the board of STC89C52 if there is no professional course
Can C language assign a value to the whole array
How to prevent the page from sliding up and down when the wechat applet slides left and right
Does anyone know why the information in this form can't come out? Hurry!
Operation of strlen function
- Why is it an endless loop? And what does I + + in printf mean
- C language function problem,.?!
- In which industries does C + + graphics development develop c++
- Why can't I output with structure
- How to save the processed file after Python data processing? It is found that the file has not changed after saving
- How can this mistake be corrected?
- Python calculates the triple accumulation sum of arrays
- Through the request forwarding command of the servlet program, will the access to the target resources protected by the filter filter be filtered by the filter?
- Pycharm loads TTF font file and displays garbled code
- Hello, is there a corresponding code implementation for the super resolution from a single image you mentioned in the super resolution article two years ago?
- Why are the results the same
- The MySQL geometry type retains 6 decimal places
- The removeall() and addall() methods in the list set are the same as the list What is the difference between the difference set and the sum set of two sets?
- Vue project number is automatically generated according to the city and county
- How to generate Vue number automatically
- Please * God, what about the win service flash back
- The users table space of Oracle is migrated to another file path and must be moved under the database shutdown?
- How can I do this?
- Pointer assignment problem, how to assign
- Operation of if function and for function
- Edge browser can't open the new web address. It can only open the web address in favorites
- In Python, what is strip () used for? Is errmsg a keyword or a function? What is it used for
- How does Java cut and drag pictures onto the canvas
- Check whether the data obtained by post already exists in the database
- How to solve the problem of RTC?
- The strategy problem of medical classifier doesn't understand the solution at all
- When making asynchronous non blocking requests, if the protocol is HTTPS, the request will report an error and fail. How to adjust this?
- Why didn't the lazy init tag take effect? Shouldn't it be created when getting the object? Not when spring initializes
- Vue array push object problem
- An error is reported when IntelliJ idea creates a Java class
- Can you change this des encrypted C version to Java version
- Using Python + pandas to extract the data in Excel, there are "0" and "data type". How can we remove these two things?
- Hive starts with an error exception in thread 'main' Java lang.NoSuchMethodError: com. google. common.， Now the whole person is not good
- How to keep the data on the left side of the antd Vue shuttle box
- MySQL SQL field extraction
- The oracledbconsoleorcl service terminated due to the following service specific error: the system could not find the specified file.
- Please answer the questions about ＃ C ＃!
- The index is not triggered when MySQL uses the sum function
- How to learn asp NET Core？？
- Indentation problem of for loop