From 8b739bdceec6503e981d30361259ab28da7483e6 Mon Sep 17 00:00:00 2001 From: liuqi Date: Mon, 12 Mar 2018 14:19:42 +0800 Subject: [PATCH] Fix converte vgg caffe model bug. --- generate_data.py | 3 --- generate_model_code.sh | 2 +- mace_tools.py | 25 ++++++++++++++++++++++++- validate_tools.sh | 7 ++++--- 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/generate_data.py b/generate_data.py index 24ac6c23..8feff823 100644 --- a/generate_data.py +++ b/generate_data.py @@ -1,10 +1,7 @@ import argparse import sys -import os -import os.path import numpy as np import re -from scipy import spatial # Validation Flow: # 1. Generate input data diff --git a/generate_model_code.sh b/generate_model_code.sh index d893e29f..424f8df6 100644 --- a/generate_model_code.sh +++ b/generate_model_code.sh @@ -10,7 +10,7 @@ if [ ${DSP_MODE} ]; then DSP_MODE_FLAG="--dsp_mode=${DSP_MODE}" fi -bazel-bin/lib/python/tools/converter --platform=${PLATFORM} \ +PYTHONUNBUFFERED=1 bazel-bin/lib/python/tools/converter --platform=${PLATFORM} \ --model_file=${MODEL_FILE_PATH} \ --weight_file=${WEIGHT_FILE_PATH} \ --model_checksum=${MODEL_SHA256_CHECKSUM} \ diff --git a/mace_tools.py b/mace_tools.py index 0c0823ea..2c833f82 100644 --- a/mace_tools.py +++ b/mace_tools.py @@ -17,6 +17,29 @@ import yaml from ConfigParser import ConfigParser +def run_command_real_time(command): + print("Run command: {}".format(command)) + process = subprocess.Popen( + command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + + while True: + std_err = process.stderr.readline() + if std_err == '' and process.poll() is not None: + break + if std_err: + print std_err.strip() + while True: + std_out = process.stdout.readline() + if std_out == '' and process.poll() is not None: + break + if std_out: + print std_out.strip() + ret_code = process.poll() + + if ret_code != 0: + raise Exception("Exit not 0 from bash with code: {}, command: {}".format( + ret_code, command)) + def run_command(command): print("Run command: {}".format(command)) result = subprocess.Popen( @@ -71,7 +94,7 @@ def generate_random_input(model_output_dir): def generate_model_code(): command = "bash tools/generate_model_code.sh" - run_command(command) + run_command_real_time(command) def build_mace_run(production_mode, model_output_dir, hexagon_mode): diff --git a/validate_tools.sh b/validate_tools.sh index 78dfce75..6a458676 100644 --- a/validate_tools.sh +++ b/validate_tools.sh @@ -24,7 +24,7 @@ if [ "$GENERATE_DATA_OR_NOT" = 1 ]; then FORMATTED_NAME=$(sed s/[^[:alnum:]]/_/g <<< ${NAME}) rm -rf ${MODEL_OUTPUT_DIR}/${INPUT_FILE_NAME}_${FORMATTED_NAME} done - python tools/generate_data.py --input_node=${INPUT_NODES} \ + python -u tools/generate_data.py --input_node=${INPUT_NODES} \ --input_file=${MODEL_OUTPUT_DIR}/${INPUT_FILE_NAME} \ --input_shape="${INPUT_SHAPES}" || exit 1 exit 0 @@ -38,7 +38,7 @@ if [ "$PLATFORM" == "tensorflow" ];then adb pull ${PHONE_DATA_DIR}/${OUTPUT_FILE_NAME}_${FORMATTED_NAME} ${MODEL_OUTPUT_DIR} > /dev/null done fi - python tools/validate.py --platform=tensorflow \ + python -u tools/validate.py --platform=tensorflow \ --model_file ${MODEL_FILE_PATH} \ --input_file ${MODEL_OUTPUT_DIR}/${INPUT_FILE_NAME} \ --mace_out_file ${MODEL_OUTPUT_DIR}/${OUTPUT_FILE_NAME} \ @@ -90,7 +90,8 @@ elif [ "$PLATFORM" == "caffe" ];then docker cp tools/validate.py ${CONTAINER_NAME}:/mace docker cp ${MODEL_FILE_PATH} ${CONTAINER_NAME}:/mace docker cp ${WEIGHT_FILE_PATH} ${CONTAINER_NAME}:/mace - docker exec -it ${CONTAINER_NAME} python /mace/validate.py --platform=caffe \ + docker exec -it ${CONTAINER_NAME} python -u /mace/validate.py \ + --platform=caffe \ --model_file /mace/${MODEL_FILE_NAME} \ --weight_file /mace/${WEIGHT_FILE_NAME} \ --input_file /mace/${INPUT_FILE_NAME} \ -- GitLab