-
Notifications
You must be signed in to change notification settings - Fork 128
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
error in copy-task-plots.ipynb #19
Comments
Did you solve this problem? |
You should change def evaluate(net, criterion, X, Y):
"""Evaluate a single batch (without training)."""
inp_seq_len = X.size(0)
outp_seq_len, batch_size, _ = Y.size()
# New sequence
net.init_sequence(batch_size)
# Feed the sequence + delimiter
states = []
for i in range(inp_seq_len):
o, state = net(X[i])
states += [state]
# Read the output (no input given)
y_out = torch.zeros(Y.size())
for i in range(outp_seq_len):
y_out[i], state = net()
states += [state]
loss = criterion(y_out, Y)
y_out_binarized = y_out.clone().data
y_out_binarized.apply_(lambda x: 0 if x < 0.5 else 1)
# The cost is the number of error bits per sequence
cost = torch.sum(torch.abs(y_out_binarized - Y.data))
result = {
'loss': loss.item(),
'cost': cost / batch_size,
'y_out': y_out,
'y_out_binarized': y_out_binarized,
'states': states
}
return result def draw_sequence(y, u=12):
seq_len = y.size(0)
seq_width = y.size(2)
inset = u // 8
pad = u // 2
width = seq_len * u + 2 * pad
height = seq_width * u + 2 * pad
im = Image.new('L', (width, height))
draw = ImageDraw.ImageDraw(im)
draw.rectangle([0, 0, width, height], fill=250)
for i in range(seq_len):
for j in range(seq_width):
val = 1 - y[i, 0, j].item()
draw.rectangle([pad + i*u + inset,
pad + j*u + inset,
pad + (i+1)*u - inset,
pad + (j+1)*u - inset], fill=cmap(val))
return im |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
when run the code piece
there comes the error information:
how to solve it?
The text was updated successfully, but these errors were encountered: