fix helper name
This commit is contained in:
Родитель
b5bf92bdcc
Коммит
d6160b27e8
|
@ -56,22 +56,19 @@ class AbstractContext(object, metaclass=ABCMeta):
|
|||
'''
|
||||
|
||||
def __init__(self, name,
|
||||
graph=None,
|
||||
device_id=-1,
|
||||
root_nodes=None,
|
||||
clean_up=True,
|
||||
node_unit_test=False):
|
||||
device_id=-1,
|
||||
precision="float",
|
||||
clean_up=True):
|
||||
'''
|
||||
AbstractContext Constructer
|
||||
|
||||
:param name: context name
|
||||
:param graph: the computational graph to be used for training, testing and prediction
|
||||
:param device_id: whether to use CPU or a specific GPU. -1 for CPU larger values
|
||||
:param root_nodes: list of top nodes of the graph or single node itself
|
||||
:param clean_up: whether the temporary directory should be removed when the context is left
|
||||
are the GPUs indices.
|
||||
:param node_unit_test: set to True if you want to output the gradient of a node (backward pass)
|
||||
|
||||
:param clean_up: whether the temporary directory should be removed when the context is left
|
||||
are the GPUs indices.
|
||||
:param precision: either float or double
|
||||
'''
|
||||
if isinstance(name, str):
|
||||
tmpdir = name
|
||||
|
@ -88,6 +85,7 @@ class AbstractContext(object, metaclass=ABCMeta):
|
|||
|
||||
self.name = name
|
||||
self.device_id = device_id
|
||||
self.precision = precision
|
||||
self.clean_up = clean_up
|
||||
self.input_nodes = set()
|
||||
if root_nodes is None:
|
||||
|
@ -169,6 +167,7 @@ class AbstractContext(object, metaclass=ABCMeta):
|
|||
|
||||
tmpl_dict = {
|
||||
'DevideId': self.device_id,
|
||||
'Precision': self.precision,
|
||||
'ModelDescription': description,
|
||||
'ModelPath': model_filename,
|
||||
'Reader': '\n'.join(r.generate_config() for r in readers),
|
||||
|
@ -192,6 +191,7 @@ class AbstractContext(object, metaclass=ABCMeta):
|
|||
|
||||
tmpl_dict = {
|
||||
'DevideId': self.device_id,
|
||||
'Precision': self.precision,
|
||||
'ModelPath': model_filename,
|
||||
'Reader': reader_config,
|
||||
}
|
||||
|
@ -216,6 +216,7 @@ class AbstractContext(object, metaclass=ABCMeta):
|
|||
|
||||
tmpl_dict = {
|
||||
'DevideId': self.device_id,
|
||||
'Precision': self.precision,
|
||||
'ModelPath': model_filename,
|
||||
'PredictOutputFile': output_filename_base,
|
||||
'Reader': reader_config,
|
||||
|
@ -249,7 +250,8 @@ class AbstractContext(object, metaclass=ABCMeta):
|
|||
output_filename = os.path.join(self.directory, CNTK_OUTPUT_FILENAME)
|
||||
tmpl_dict = {
|
||||
'DevideId': self.device_id,
|
||||
'NodeUnitTest': self.node_unit_test,
|
||||
'Precision': self.precision,
|
||||
'NodeUnitTest': node_unit_test,
|
||||
'OutputFile': output_filename,
|
||||
'ModelDescription': description,
|
||||
'Reader': '\n'.join(r.generate_config() for r in readers),
|
||||
|
|
|
@ -11,7 +11,7 @@ the forward and the backward pass
|
|||
|
||||
import numpy as np
|
||||
import pytest
|
||||
from .ops_test_utils import test_helper, C, AA, I, cpu_gpu
|
||||
from .ops_test_utils import unittest_helper, C, AA, I, cpu_gpu
|
||||
from ...graph import *
|
||||
from ...reader import *
|
||||
import numpy as np
|
||||
|
@ -26,13 +26,13 @@ import numpy as np
|
|||
#Adding two 3x2 inputs of sequence length 1
|
||||
#([[30,40], [1,2], [0.1, 0.2]], [[10,20], [3,4], [-0.5, -0.4]]),
|
||||
])
|
||||
def test_op_add(left_operand, right_operand, cpu_gpu):
|
||||
def test_op_plus(left_operand, right_operand, cpu_gpu):
|
||||
|
||||
#Forward pass test
|
||||
|
||||
#==================
|
||||
#we compute the expected output for the forward pass
|
||||
# we need two surrounding brackets
|
||||
# the first for sequence of 1 element, since we have has_sequence_dimension=False
|
||||
# the first for sequences (length=1, since we have has_sequence_dimension=False)
|
||||
# the second for batch of one sample
|
||||
expected = [[AA(left_operand) + AA(right_operand)]]
|
||||
|
||||
|
@ -40,14 +40,16 @@ def test_op_add(left_operand, right_operand, cpu_gpu):
|
|||
b = I([right_operand], has_sequence_dimension=False)
|
||||
|
||||
left_as_input = a + right_operand
|
||||
test_helper(left_as_input, expected, cpu_gpu, False)
|
||||
unittest_helper(left_as_input, expected, cpu_gpu, False)
|
||||
|
||||
right_as_input = left_operand + b
|
||||
test_helper(right_as_input, expected, cpu_gpu, False)
|
||||
unittest_helper(right_as_input, expected, cpu_gpu, False)
|
||||
|
||||
#Backward pass test
|
||||
|
||||
#==================
|
||||
#the expected results for the backward pass is all ones
|
||||
expected = [[[np.ones_like(x) for x in left_operand]]]
|
||||
test_helper(left_as_input, expected, cpu_gpu, clean_up=True, backward_pass = True, input_node = a)
|
||||
test_helper(right_as_input, expected, cpu_gpu, clean_up=True, backward_pass = True, input_node = b)
|
||||
unittest_helper(left_as_input, expected, cpu_gpu, clean_up=True, backward_pass = True, input_node = a)
|
||||
unittest_helper(right_as_input, expected, cpu_gpu, clean_up=True, backward_pass = True, input_node = b)
|
||||
|
||||
|
|
@ -23,7 +23,7 @@ AA = np.asarray
|
|||
def cpu_gpu(request):
|
||||
return request.param
|
||||
|
||||
def test_helper(root_node, expected, device_id = -1, clean_up=True, backward_pass = False, input_node = None):
|
||||
def unittest_helper(root_node, expected, device_id = -1, clean_up=True, backward_pass = False, input_node = None):
|
||||
with get_new_context() as ctx:
|
||||
ctx.clean_up = clean_up
|
||||
ctx.device_id = device_id
|
||||
|
|
Загрузка…
Ссылка в новой задаче