def test_forward_mobilenet_v1(accel_type): """Test the Mobilenet V1 TF Lite model.""" np.random.seed(23) tflite_model_file = tf_testing.get_workload_official( "https://storage.googleapis.com/download.tensorflow.org/" "models/mobilenet_v1_2018_08_02/mobilenet_v1_1.0_224_quant.tgz", "mobilenet_v1_1.0_224_quant.tflite", ) with open(tflite_model_file, "rb") as f: tflite_model_buf = f.read() input_tensor = "input" input_dtype = "uint8" input_shape = (1, 224, 224, 3) in_min, in_max = util.get_range_for_dtype_str(input_dtype) input_data = np.random.randint(in_min, high=in_max, size=input_shape, dtype=input_dtype) relay_mod, params = convert_to_relay(tflite_model_buf) input_data = {input_tensor: input_data} output_data = generate_ref_data(relay_mod, input_data) mod = partition_for_ethosu(relay_mod, params) compiled_models = infra.build_source( mod, input_data, output_data, accel_type, output_tolerance=10 ) infra.verify_source(compiled_models, accel_type)
def test_networks_with_usmp(accel_type, model_url, workspace_size): np.random.seed(23) tflite_model_buf = infra.get_tflite_model(model_url) input_data, output_data = infra.generate_ref_data_tflite(tflite_model_buf) mod, params = convert_to_relay(tflite_model_buf) mod = partition_for_ethosu(mod, params) compiled_models = infra.build_source(mod, input_data, output_data, accel_type, enable_usmp=True) allocated_pool_info = list( dict(compiled_models[0].executor_factory.executor_codegen_metadata.pool_inputs).values() )[0] assert allocated_pool_info.allocated_size == workspace_size infra.verify_source(compiled_models, accel_type, enable_usmp=True)
def test_networks_without_usmp(accel_type, model_url, workspace_size): np.random.seed(23) tflite_model_buf = infra.get_tflite_model(model_url) input_data, output_data = infra.generate_ref_data_tflite(tflite_model_buf) mod, params = convert_to_relay(tflite_model_buf) mod = partition_for_ethosu(mod, params) compiled_models = infra.build_source( mod, input_data, output_data, accel_type, enable_usmp=False ) mlf_memory_map = mlf._build_function_memory_map( compiled_models[0].executor_factory.function_metadata ) assert mlf_memory_map["main"][0]["workspace_size_bytes"] == workspace_size infra.verify_source(compiled_models, accel_type, enable_usmp=False)