Skip to content

AttributeError: 'Tensor' object has no attribute 'astype'. Did you mean: 'dtype'? when prediction in image classification #45

@PeerlessMonster

Description

@PeerlessMonster
python stm32ai_main.py --config-path ./config_file_examples_pt --config-name prediction_n6_config.yaml

throw an exception

Traceback (most recent call last):
  File "D:\Softwares\miniconda3\envs\st_zoo\Lib\site-packages\clearml\binding\hydra_bind.py", line 230, in _patched_tas
k_function
    return task_function(a_config, *a_args, **a_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\workspace\stm32ai-modelzoo-services\image_classification\stm32ai_main.py", line 337, in main
    _process_mode(cfg=cfg)
  File "D:\workspace\stm32ai-modelzoo-services\image_classification\stm32ai_main.py", line 118, in _process_mode
    predictor.predict()
  File "D:\workspace\stm32ai-modelzoo-services\image_classification\tf\src\prediction\onnx_predictor.py", line 196, in 
predict
    scores = self._get_scores(image_processed)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\workspace\stm32ai-modelzoo-services\image_classification\tf\src\prediction\onnx_predictor.py", line 119, in 
_get_scores
    imagee = ai_interp_input_quant(self.ai_runner_interpreter, image_processed, '.onnx')
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\workspace\stm32ai-modelzoo-services\common\utils\models_utils.py", line 35, in ai_interp_input_quant
    out_data = resc_data.astype(np.uint8)
               ^^^^^^^^^^^^^^^^
AttributeError: 'Tensor' object has no attribute 'astype'. Did you mean: 'dtype'?

complete output from terminal: 2026_03_16_23_28_39.log

content of config file:

operation_mode: prediction
general:
  display_figures: false
model:
  framework: torch
  model_name: mobilenetv2_a100_pt
  pretrained: true
  pretrained_dataset: imagenet
  input_shape:
  - 3
  - 224
  - 224
  model_path: ../../stm32ai-modelzoo/image_classification/mobilenetv2_pt/Public_pretrainedmodel_public_dataset/Imagenet/mobilenetv2_a100_pt_224/mobilenetv2_a100_pt_224_qdq_int8.onnx
dataset:
  dataset_name: imagenet
  class_names: ''
  classes_file_path: ./datasets/deployment_labels_imagenet.txt
  num_classes: 1000
  prediction_path: ./datasets/mini-imagenet/test/n01532829/
  workers: 4
  no_prefetcher: true
preprocessing:
  rescaling:
    scale: None
    offset: None
  resizing:
    interpolation: random
    aspect_ratio: fit
  color_mode: rgb
  normalization:
    mean:
    - 0.485
    - 0.456
    - 0.406
    std:
    - 0.229
    - 0.224
    - 0.225
prediction:
  profile: profile_O3
  input_type: uint8
  output_type: int8
  input_chpos: chlast
  output_chpos: chlast
  target: stedgeai_n6
tools:
  stedgeai:
    path_to_stedgeai: D:/Softwares/ST/STEdgeAI/4.0/Utilities/windows/stedgeai.exe
mlflow:
  uri: ./pt/src/experiments_outputs/mlruns

version:
STEdgeAI Core = 4.0
STM32CubeIDE = 1.17.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions