提交 7d4e4404 编写于 作者: A Aston Zhang

reshape(())

上级 2aab0f6a
......@@ -109,7 +109,7 @@ def optimize(batch_size, rho, num_epochs, log_interval):
y_vals.append(squared_loss(net(X, w, b), y).mean().asnumpy())
print('epoch %d, loss %.4e' % (epoch, y_vals[-1]))
# 为了便于打印,改变输出形状并转化成numpy数组。
print('w:', w.reshape(1, -1).asnumpy(), 'b:', b.asscalar(), '\n')
print('w:', w.reshape((1, -1)).asnumpy(), 'b:', b.asscalar(), '\n')
x_vals = np.linspace(0, num_epochs, len(y_vals), endpoint=True)
utils.set_fig_size(mpl)
plt.semilogy(x_vals, y_vals)
......
......@@ -126,7 +126,7 @@ def optimize(batch_size, lr, num_epochs, log_interval):
print('epoch %d, learning rate %f, loss %.4e' % (epoch, lr,
y_vals[-1]))
# 为了便于打印,改变输出形状并转化成numpy数组。
print('w:', w.reshape(1, -1).asnumpy(), 'b:', b.asscalar(), '\n')
print('w:', w.reshape((1, -1)).asnumpy(), 'b:', b.asscalar(), '\n')
x_vals = np.linspace(0, num_epochs, len(y_vals), endpoint=True)
utils.set_fig_size(mpl)
plt.semilogy(x_vals, y_vals)
......
......@@ -146,7 +146,7 @@ def optimize(batch_size, lr, num_epochs, log_interval):
print('epoch %d, learning rate %f, loss %.4e' % (epoch, lr,
y_vals[-1]))
# 为了便于打印,改变输出形状并转化成numpy数组。
print('w:', w.reshape(1, -1).asnumpy(), 'b:', b.asscalar(), '\n')
print('w:', w.reshape((1, -1)).asnumpy(), 'b:', b.asscalar(), '\n')
x_vals = np.linspace(0, num_epochs, len(y_vals), endpoint=True)
utils.set_fig_size(mpl)
plt.semilogy(x_vals, y_vals)
......
......@@ -194,7 +194,7 @@ def optimize(batch_size, lr, num_epochs, log_interval, decay_epoch):
print('epoch %d, learning rate %f, loss %.4e' % (epoch, lr,
y_vals[-1]))
# 为了便于打印,改变输出形状并转化成numpy数组。
print('w:', w.reshape(1, -1).asnumpy(), 'b:', b.asscalar(), '\n')
print('w:', w.reshape((1, -1)).asnumpy(), 'b:', b.asscalar(), '\n')
x_vals = np.linspace(0, num_epochs, len(y_vals), endpoint=True)
utils.set_fig_size(mpl)
plt.semilogy(x_vals, y_vals)
......
......@@ -122,7 +122,7 @@ def optimize(batch_size, lr, mom, num_epochs, log_interval):
print('epoch %d, learning rate %f, loss %.4e' % (epoch, lr,
y_vals[-1]))
# 为了便于打印,改变输出形状并转化成numpy数组。
print('w:', w.reshape(1, -1).asnumpy(), 'b:', b.asscalar(), '\n')
print('w:', w.reshape((1, -1)).asnumpy(), 'b:', b.asscalar(), '\n')
x_vals = np.linspace(0, num_epochs, len(y_vals), endpoint=True)
utils.set_fig_size(mpl)
plt.semilogy(x_vals, y_vals)
......
......@@ -108,7 +108,7 @@ def optimize(batch_size, lr, gamma, num_epochs, log_interval):
print('epoch %d, learning rate %f, loss %.4e' % (epoch, lr,
y_vals[-1]))
# 为了便于打印,改变输出形状并转化成numpy数组。
print('w:', w.reshape(1, -1).asnumpy(), 'b:', b.asscalar(), '\n')
print('w:', w.reshape((1, -1)).asnumpy(), 'b:', b.asscalar(), '\n')
x_vals = np.linspace(0, num_epochs, len(y_vals), endpoint=True)
utils.set_fig_size(mpl)
plt.semilogy(x_vals, y_vals)
......
......@@ -401,8 +401,8 @@ def optimize(batch_size, trainer, num_epochs, decay_epoch, log_interval, X, y,
else:
print("epoch %d, loss %.4e" % (epoch, y_vals[-1]))
# 为了便于打印,改变输出形状并转化成numpy数组。
print('w:', np.reshape(net[0].weight.data().asnumpy(), (1, -1)),
'b:', net[0].bias.data().asnumpy()[0], '\n')
print('w:', net[0].weight.data().reshape((1, -1)).asnumpy(),
'b:', net[0].bias.data().asscalar(), '\n')
x_vals = np.linspace(0, num_epochs, len(y_vals), endpoint=True)
set_fig_size(mpl)
plt.semilogy(x_vals, y_vals)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册