Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: iteration over a 0-d tensor #2

Open
duguiming111 opened this issue May 27, 2019 · 3 comments
Open

TypeError: iteration over a 0-d tensor #2

duguiming111 opened this issue May 27, 2019 · 3 comments

Comments

@duguiming111
Copy link

TypeError: iteration over a 0-d tensor,请问你在运行得时候遇到过这个问题吗

@Machine-Tom
Copy link

I have met the same question. Have you solved it?

@ZhijianChan
Copy link

修改两个地方,在pytorch1.0下面可以运行:

1)repackage_hidden函数

def repackage_hidden(h):
	"""用新的变量重新包装隐藏层,将它们从历史中分离。"""
    if type(h) == tuple:  # lstm
    	return tuple(repackage_hidden(v) for v in h)
    else:  # rnn/gru
    	return Variable(h.data)

2)train函数内

total_loss += loss.tolist()  # loss累计

if ibatch % config.log_interval == 0 and ibatch > 0:  # 每隔多少个批次输出一次状态
	cur_loss = total_loss / config.log_interval

@purpletpig
Copy link

I have met the same question too. Have you solved it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants