Checking On-Device Accuracy

Hi,
Hoping someone is still following this class. I’m running the course labs locally. In Lab3 I run into an issue while Checking device accuracy.

torch_inputs = torch.Tensor(sample_inputs[‘image’][0])
torch_outputs = ffnet_40s(torch_inputs)
torch_outputs

Throws an error:
RuntimeError: Given groups=1, weight of size [32, 3, 3, 3], expected input[1, 1024, 2048, 3] to have 3 channels, but got 1024 channels instead

Could it be related to the warning received after running:

from qai_hub_models.models.ffnet_40s import Model as FFNet_40s

Load from pre-trained weights

ffnet_40s = FFNet_40s.from_pretrained()

Loading pretrained model state dict from /home/chuck/.qaihm/models/ffnet/v1/ffnet40S/ffnet40S_dBBB_cityscapes_state_dict_quarts.pth
Initializing ffnnet40S_dBBB_mobile weights
/home/chuck/.qaihm/models/cityscapes_segmentation/v2/Qualcomm-AI-research_FFNet_git/models/ffnet_blocks.py:599: FutureWarning: You are using torch.load with weights_only=False (the current default value), which uses the default pickle module implicitly. It is possible to construct malicious pickle data which will execute arbitrary code during unpickling (See pytorch/SECURITY.md at main · pytorch/pytorch · GitHub for more details). In a future release, the default value for weights_only will be flipped to True. This limits the functions that could be executed during unpickling. Arbitrary objects will no longer be allowed to be loaded via this mode unless they are explicitly allowlisted by the user via torch.serialization.add_safe_globals. We recommend you start setting weights_only=True for any use case where you don’t have full control of the loaded file. Please open an issue on GitHub for any issues related to this experimental feature.
pretrained_dict = torch.load(

V/r,

Chuck

can you share a screenshot of the error

I found a few similar issues online that were posted on the Pytorch forum Given groups=1, weight of size [40, 3, 3, 3], expected input[16, 32, 33, 5] to have 3 channels, but got 32 channels instead - #3 by ptrblck - PyTorch Forums

Following that advice I added permute to the cell as:

torch_inputs = torch.Tensor(sample_inputs[‘image’][0])
torch_inputs = torch_inputs.permute(0, 3, 1, 2)
torch_outputs = ffnet_40s(torch_inputs)
torch_outputs

Which seemed logical since it was expecting NCHW (pytorch format) but somehow received a TensorFlow format (NHWC)

The output appears to be identical to the DeepLearning.AI platform response.

The following inferrence_job cell runs okay but the
ondevice_outputs = inference_job.download_output_data()
ondevice_outputs[‘output_0’]

cell kicks off, runs for about 45 sec then errors out

error files attached:
ondevice_output_error.pdf (10.9 KB)
torch_inputs_error.pdf (17.9 KB)

The original error w/o permute
ondevice_output error after permute added

please mention the lesson code you are trying to run locally

Thank you for your help. I’m running lesson 3, Preparing for on-device deployment.

Thanks to everyone who took the time to help or view this post. After some digging around on the Pytorch website, other resources, and a closer look at the requirements file I realized I was running the current version of torch for GPU and a latest version of qai-hub-models. After getting that aligned with the lab, all of the code ran as expected.

Thanks again.

Chuck

1 Like