Microchip-Vectorblox / VectorBlox-SDK

18 stars 9 forks source link

Support for input of a conv-1d CNN? #11

Open dschonholtz opened 1 year ago

dschonholtz commented 1 year ago

HI there,

I am currently trying to generate a hex file for my polarfire board out of a 1d convolution based CNN.

Does this support 1d-convolutions and if so how? When I try to plug the model in I either get a no negative dimensions allowed error when running generate_vnnx here: https://github.com/Microchip-Vectorblox/VectorBlox-SDK/blob/master/python/vbx/vbx/generate/onnx_convert.py#L1746 The batch size becomes -1 and the input size becomes: [-1, 1024, 1]

Or if I specify the batch size to be 1 then I get an error here: https://github.com/Microchip-Vectorblox/VectorBlox-SDK/blob/master/python/vbx/vbx/generate/onnx_modify.py#L795

With an input that looks like this:

inputs: [name: "0:0"
type {
  tensor_type {
    elem_type: 1
    shape {
      dim {
        dim_param: "N"
      }
      dim {
        dim_value: 1024
      }
      dim {
        dim_value: 1
      }
    }
  }
}
]

So it seems to be expecting things in the format NHWC which is incompatible with my 1d convolution.

Is there some configuration I can do to convert my xml file for my 1d-convolution based network into a hex file or is that not supported?

Thanks a ton, please let me know if you need any additional information from me.

The script I am running is here:

set -e
echo "Checking and Activating VBX Python Environment..."
if [ -z $VBX_SDK ]; then
    echo "\$VBX_SDK not set. Please run 'source setup_vars.sh' from the SDK's root folder" && exit 1
fi
source $VBX_SDK/vbx_env/bin/activate

python "./save_model.py" --model "pat_25302.pruneCNN12.h5"

MODEL_OUTPUT_DIR="MO_COMPLIANT_pat_25302.pruneCNN12"

echo "Running Model Optimizer..."
mo --saved_model_dir="${MODEL_OUTPUT_DIR}" \
# --input_shape [1,1024,1]

MODEL_NAME_FILE="saved_model"

echo "Generating VNNX for V1000 configuration..."
generate_vnnx -x "${MODEL_NAME_FILE}.xml" -c V1000 -f ../../sample_images -o "${MODEL_NAME_FILE}.vnnx"

echo "Running Simulation..."
# python $VBX_SDK/example/python/yoloInfer.py pat_25302.pruneCNN12.vnnx ../../test_images/dog.jpg -j pat_25302.pruneCNN12.json -l coco.names

deactivate
dschonholtz commented 1 year ago

As a follow up for this, I have a repository that is forked off of this that supports this now: Currently, it is fairly hacky and has some hard coded values for the WINES lab at Northeastern. But it may start as a useful starting point for others. It also has ubuntu 22.04 support changes in it.