class_docstr: Trains an instance of the Model class.
docstr: 定义分类任务的数据、模型
  
  Args:
      hparams:
docstr_tok: ["\u5b9a\u4e49\u5206\u7c7b\u4efb\u52a1\u7684\u6570\u636e\u3001\u6a21\u578b","Args",":","hparams",":"]
code: def __init__(self, hparams: dict) -> None:
      """
      定义分类任务的数据、模型
  
      Args:
          hparams:
      """
  
      def set_paddle_flags(**kwargs):
          for key, value in kwargs.items():
              if os.environ.get(key, None) is None:
                  os.environ[key] = str(value)
  
      # NOTE(paddle-dev): All of these flags should be set before
      # `import paddle`. Otherwise, it would not take any effect.
      set_paddle_flags(
          # enable GC to save memory
          FLAGS_fraction_of_gpu_memory_to_use=hparams.resource_config.gpu,
      )
      import paddle
      import paddlehub as hub
      from paddlehub_utils.trainer import CustomTrainer
      from paddlehub_utils.reader import _init_loader
  
      # todo now does not support fleet distribute training
      # from paddle.fluid.incubate.fleet.base import role_maker
      # from paddle.fluid.incubate.fleet.collective import fleet
      # role = role_maker.PaddleCloudRoleMaker(is_collective=True)
      # fleet.init(role)
  
      logger.info("classficiation data augment search begin")
      self.hparams = hparams
      # param compatible
      self._fit_param(show=True)
      paddle.disable_static(
          paddle.CUDAPlace(paddle.distributed.get_rank())
      )
  
      train_dataset, eval_dataset = _init_loader(self.hparams)
      model = hub.Module(
          name=hparams["task_config"]["classifier"]["model_name"],
          label_list=self.class_to_id_dict.keys(),
          load_checkpoint=None,
      )
  
      optimizer = paddle.optimizer.Adam(
          learning_rate=0.001, parameters=model.parameters()
      )
      trainer = CustomTrainer(
          model=model,
          optimizer=optimizer,
          checkpoint_dir="img_classification_ckpt",
      )
      self.model = model
      self.optimizer = optimizer
  
      trainer.init_train_and_eval(
          train_dataset,
          epochs=100,
          batch_size=32,
          eval_dataset=eval_dataset,
          save_interval=1,
      )
      self.trainer = trainer
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import time
  import six
  import os
  from typing import Dict, List, Optional, Union, Tuple
  from auto_augment.autoaug.utils import log
  import logging
  import auto_augment
label_desc: Use image node_id 1 to create a new HubFitterClassifer object from inherited base classes: object with example: obj = HubFitterClassifer(hparams)