|
|
|
@ -261,7 +261,7 @@ class StaticGraphAdapter(object):
|
|
|
|
|
self.mode = 'eval'
|
|
|
|
|
return self._run(inputs, labels)
|
|
|
|
|
|
|
|
|
|
def test_batch(self, inputs):
|
|
|
|
|
def predict_batch(self, inputs):
|
|
|
|
|
self.mode = 'test'
|
|
|
|
|
return self._run(inputs, None)
|
|
|
|
|
|
|
|
|
@ -723,7 +723,7 @@ class DynamicGraphAdapter(object):
|
|
|
|
|
else:
|
|
|
|
|
return metrics
|
|
|
|
|
|
|
|
|
|
def test_batch(self, inputs):
|
|
|
|
|
def predict_batch(self, inputs):
|
|
|
|
|
self.model.network.eval()
|
|
|
|
|
self.mode = 'test'
|
|
|
|
|
inputs = [to_variable(x) for x in to_list(inputs)]
|
|
|
|
@ -894,10 +894,13 @@ class Model(object):
|
|
|
|
|
Run one training step on a batch of data.
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
inputs (list): A list of numpy.ndarray, each is a batch of
|
|
|
|
|
input data.
|
|
|
|
|
labels (list): A list of numpy.ndarray, each is a batch of
|
|
|
|
|
input label. If has no labels, set None. Default is None.
|
|
|
|
|
inputs (numpy.ndarray|Tensor|list): Batch of input data. It could
|
|
|
|
|
be a numpy array or paddle.Tensor, or a list of arrays or
|
|
|
|
|
tensors (in case the model has multiple inputs).
|
|
|
|
|
labels (numpy.ndarray|Tensor|list): Batch of labels. It could be
|
|
|
|
|
a numpy array or paddle.Tensor, or a list of arrays or tensors
|
|
|
|
|
(in case the model has multiple labels). If has no labels,
|
|
|
|
|
set None. Default is None.
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
A list of scalar training loss if the model has no metrics,
|
|
|
|
@ -941,10 +944,13 @@ class Model(object):
|
|
|
|
|
Run one evaluating step on a batch of data.
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
inputs (list): A list of numpy.ndarray, each is a batch of
|
|
|
|
|
input data.
|
|
|
|
|
labels (list): A list of numpy.ndarray, each is a batch of
|
|
|
|
|
input label. If has no labels, set None. Default is None.
|
|
|
|
|
inputs (numpy.ndarray|Tensor|list): Batch of input data. It could
|
|
|
|
|
be a numpy array or paddle.Tensor, or a list of arrays or
|
|
|
|
|
tensors (in case the model has multiple inputs).
|
|
|
|
|
labels (numpy.ndarray|Tensor|list): Batch of labels. It could be
|
|
|
|
|
a numpy array or paddle.Tensor, or a list of arrays or tensors
|
|
|
|
|
(in case the model has multiple labels). If has no labels,
|
|
|
|
|
set None. Default is None.
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
A list of scalar testing loss if the model has no metrics,
|
|
|
|
@ -984,13 +990,14 @@ class Model(object):
|
|
|
|
|
self._update_inputs()
|
|
|
|
|
return loss
|
|
|
|
|
|
|
|
|
|
def test_batch(self, inputs):
|
|
|
|
|
def predict_batch(self, inputs):
|
|
|
|
|
"""
|
|
|
|
|
Run one testing step on a batch of data.
|
|
|
|
|
Run one predicting step on a batch of data.
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
inputs (list): A list of numpy.ndarray, each is a batch of
|
|
|
|
|
input data.
|
|
|
|
|
inputs (numpy.ndarray|Tensor|list): Batch of input data. It could
|
|
|
|
|
be a numpy array or paddle.Tensor, or a list of arrays or
|
|
|
|
|
tensors (in case the model has multiple inputs).
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
A list of numpy.ndarray of predictions, that is the outputs
|
|
|
|
@ -1019,10 +1026,10 @@ class Model(object):
|
|
|
|
|
model = paddle.Model(net, input, label)
|
|
|
|
|
model.prepare()
|
|
|
|
|
data = np.random.random(size=(4,784)).astype(np.float32)
|
|
|
|
|
out = model.test_batch([data])
|
|
|
|
|
out = model.predict_batch([data])
|
|
|
|
|
print(out)
|
|
|
|
|
"""
|
|
|
|
|
loss = self._adapter.test_batch(inputs)
|
|
|
|
|
loss = self._adapter.predict_batch(inputs)
|
|
|
|
|
if fluid.in_dygraph_mode() and self._input_shapes is None:
|
|
|
|
|
self._update_inputs()
|
|
|
|
|
return loss
|
|
|
|
@ -1847,10 +1854,9 @@ class Model(object):
|
|
|
|
|
logs[k] = v
|
|
|
|
|
else:
|
|
|
|
|
if self._inputs is not None:
|
|
|
|
|
outs = getattr(self,
|
|
|
|
|
mode + '_batch')(data[:len(self._inputs)])
|
|
|
|
|
outs = self.predict_batch(data[:len(self._inputs)])
|
|
|
|
|
else:
|
|
|
|
|
outs = getattr(self, mode + '_batch')(data)
|
|
|
|
|
outs = self.predict_batch(data)
|
|
|
|
|
|
|
|
|
|
outputs.append(outs)
|
|
|
|
|
|
|
|
|
|