Xilinx / DPU-PYNQ

DPU on PYNQ
Apache License 2.0
199 stars 68 forks source link

How to get the output_data using VART API in PYNQ-DPU #76

Closed Afef00 closed 2 years ago

Afef00 commented 2 years ago

Hello, I was trying to run a custom CNN model using PYNQ-DPU on ZCU104 board following this example. And I was trying to retrieve the data from the layer before Softmax. As far as I know, the output data here is the output data of the layer before Softmax , which is the dense layer in the attached example of a model architecture. The shape of the output data will be (1,128). Am I correct ??? job_id = dpu.execute_async(input_data, output_data) dpu.wait(job_id) temp = [j.reshape(1, outputSize) for j in output_data] softmax = calculate_softmax(temp[0][0]) Screenshot_1 When I tried to reshape the output data to be (1,128), there was NaN in the data.

So I tried this: After the training of the full model using tensorflow, I run vai_q_tensorflow to obtain a .pb quantized model. I truncate this model to delete softmax layer. The truncated model (conv+pool+dense1) is compiled using

!vai_c_tensorflow \
    --frozen_pb custom_dense1.pb \
    --arch /opt/vitis_ai/compiler/arch/DPUCZDX8G/ZCU104/arch.json \
    --output_dir . \
    --net_name mnist_dense1_modif

However I got the following error


Any suggestions how to solve this problem please? Thanks.

skalade commented 2 years ago

The model in the example already outputs the final fully connected layer output values before softmax and its shape is (1, 10). Softmax is calculated as a separate python function.

If you are having issues training custom models on the Vitis AI docker then Vitis AI would be a better place to find support. I would also investigate the Vitis AI Tutorials as there are plenty of training examples of more complex architectures.

Thanks Shawn

Afef00 commented 2 years ago

Hello, Thanks for the clarification!
Actually, I was trying to build a hybrid CNN -SVM model, where I use the output values of the final fully connected layer as inputs for SVM classifier. The problem is that in the software validation of this approach the output shape of this layer was (1,128).
I tried the following to get the output values of the final fully connected layer

getFeature = K.function([model.layers[0].input, K.learning_phase()],
                        [model.layers[4].output])
exTrain = getFeature([x_train, 0])[0]

The output shape of extrain was (1,128). That's why am confused Thanks

skalade commented 2 years ago

Closing this out as it has been a few weeks without activity and it seems more of a general ML/tensorflow issue, than to do with DPU-PYNQ.