提交 c96fe02f 编写于 作者: L lyuwenyu 提交者: jzhang533

add test

上级 2e933629
......@@ -718,6 +718,20 @@ class TestModelFunction(unittest.TestCase):
model.save(save_dir, training=False)
shutil.rmtree(save_dir)
def test_accumulate(self, ):
dim = 20
data = np.random.random(size=(4, dim)).astype(np.float32)
label = np.random.randint(0, 10, size=(4, 1)).astype(np.int64)
net = MyModel()
optim = fluid.optimizer.SGD(learning_rate=0.001,
parameter_list=net.parameters())
inputs = [InputSpec([None, dim], 'float32', 'x')]
labels = [InputSpec([None, 1], 'int64', 'label')]
model = Model(net, inputs, labels)
model.prepare(optim, loss=CrossEntropyLoss(reduction="sum"))
loss1, = model.train_batch([data], [label], update=True)
loss2, = model.train_batch([data], [label], update=False)
class TestModelWithLRScheduler(unittest.TestCase):
def test_fit_by_step(self):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册