示例#1
0
def _set_shape(graph, value, shape):
    if isinstance(value, nnef.Identifier):
        tensor = graph.tensors[value]
        graph.tensors[value] = nnef.Tensor(tensor.name, tensor.dtype, shape, tensor.data, tensor.compression, tensor.quantization)
    elif isinstance(value, list):
        for v, s in zip(value, shape):
            _set_shape(graph, v, s)
示例#2
0
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import nnef
import numpy as np
from collections import OrderedDict

input = nnef.Tensor('input', dtype='scalar')
filter = nnef.Tensor('filter',
                     dtype='scalar',
                     data=np.random.randn(32, 3, 5, 5))
output = nnef.Tensor('output', dtype='scalar')

external = nnef.Operation('external',
                          attribs={'shape': [1, 3, 224, 224]},
                          inputs=OrderedDict(),
                          outputs=OrderedDict([('output',
                                                nnef.Identifier('input'))]))
variable = nnef.Operation('variable',
                          attribs={
                              'shape': [32, 3, 5, 5],
                              'label': 'conv/filter'
                          },