# Licensed to the Apache Software Foundation (ASF) under one # or more contributor license agreements. See the NOTICE file # distributed with this work for additional information # regarding copyright ownership. The ASF licenses this file # to you under the Apache License, Version 2.0 (the # "License"); 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 os import shutil import struct import sys import numpy as np import tensorflow as tf import tvm import tvm.relay as relay from tvm.micro.contrib import stm32 from tvm.contrib.download import download from tvm import testing import conftest NUM_ITERATIONS = 10 # ========================================================= # get_data # ========================================================= def get_data(in_data_shapes, in_data_dtypes): """Generate a uint8 image.""" assert len(in_data_shapes) == 1, "Only single input models are supported." in_data = OrderedDict() for shape_name, shape in in_data_shapes.items(): for dtype_name, dtype in in_data_dtypes.items(): if dtype_name == shape_name: in_data[shape_name] = np.random.uniform(size=shape).astype(dtype) in_data = np.random.uniform(size=shape).astype("uint8") break if shape_name not in in_data.keys(): raise ValueError("Shape and dtype dictionaries do not fit.") return in_data # ================================================================== # dump_image # ================================================================== def dump_image(filename, image): # Flatten image image_data = image.flatten() outputRaw = [] # Raw binary format for i in range(0, len(image_data)): outputRaw.append(struct.pack("