Beispiel #1
0
def load_model(path):
    if os.path.isfile(path):
        return _nnef.parse_file(path)
    
    graph_filename = os.path.join(path, 'graph.nnef')
    quant_filename = os.path.join(path, 'graph.quant')

    graph = _nnef.parse_file(graph_filename, quant_filename if os.path.isfile(quant_filename) else None)

    for operation in graph.operations:
        if operation.name == 'variable':
            variable_filename = os.path.join(path, operation.attribs['label'] + '.dat')
            tensor_name = operation.outputs['output']
            with open(variable_filename) as variable_file:
                data, compression = read_tensor(variable_file)
            
            tensor = graph.tensors[tensor_name]
            
            if list(tensor.shape) != list(data.shape):
                raise Error('shape {} in variable file does not match shape {} defined in network structure'.format(data.shape, tensor.shape))
            
            graph.tensors[tensor_name] = Tensor(tensor.name, tensor.dtype, tensor.shape, data, compression, tensor.quantization)

    return graph
Beispiel #2
0
def parse_file(input, quantization=None, atomics=StandardOperations):
    return _nnef.parse_file(input, quantization=quantization, atomics=atomics)
Beispiel #3
0
def parse_file(graph_fn, quant_fn=None, stdlib=None, lowered=[]):
    return _nnef.parse_file(graph_fn,
                            quantization=quant_fn,
                            stdlib=stdlib,
                            lowered=lowered)
Beispiel #4
0
def parse_file(string,
               flat=False,
               layers=False,
               atomics=StandardOperations,
               shape_prop={}):
    return _nnef.parse_file(string, flat, layers, atomics, shape_prop)