Сбои с обучением с учетом квантования или квантованием после обучения - PullRequest
0 голосов
/ 25 апреля 2020

Я новичок. У меня есть проблема, которую я не могу решить, и я очень в беде. Я хочу, чтобы ты сказал мне. Я хочу обнаружить объект на моем Raspberry Pi. Я хочу выполнить модель вывода на Edge TPU.

1.Создать новую модель из изученной модели с тонкой настройкой.

2.Скомпилировать для работы с EdgeTPU и развернуть на RaspberryPi.

Я попробовал две вещи для достижения этой цели, но они не увенчались успехом.

Первая

1. Модель обнаружения тензора. Для тонкой настройки я использовал zs ssd_mobilenet_v3_large_coco.

2.В следующем потоке обработайте его так, чтобы он мог использоваться EgdeTPU.

2-1

python object_detection/export_tflite_ssd_graph.py --pipeline_config_path=object_detection/ssd_mobilenet_v3_large_coco/pipeline.config --trained_checkpoint_prefix=object_detection/test0001/save/model.ckpt-10000 --output_directory=object_detection/test0001/tflite --add_postprocessing_op=true

2-2

tflite_convert --output_file=object_detection/test0001/tflite/test.tflite --graph_def_file=object_detection/test0001/tflite/tflite_graph.pb --inference_type=FLOAT --input_arrays=normalized_input_image_tensor --input_shape=1,320,320,3 --output_arrays=TFLite_Detection_PostProcess,TFLite_Detection_PostProcess:1,TFLite_Detection_PostProcess:2,TFLite_Detection_PostProcess:3 --default_ranges_min=0 --default_ranges_max=255 --mean_values=128 --std_dev_values=127 --inference_type=QUANTIZED_UINT8 --allow_custom_ops

2 -3

edgetpu_compiler test.tflite

log

Edge TPU Compiler version 2.1.302470888
  Input: test.tflite
  Output: test_edgetpu.tflite

  Operator                       Count      Status

  LOGISTIC                       1          More than one subgraph is not supported
  CUSTOM                         1          Operation is working on an unsupported data type
  ADD                            22         More than one subgraph is not supported
  MUL                            28         More than one subgraph is not supported
  CONCATENATION                  2          More than one subgraph is not supported
  CONV_2D                        1          Mapped to Edge TPU
  CONV_2D                        66         More than one subgraph is not supported
  DEPTHWISE_CONV_2D              31         More than one subgraph is not supported
  HARD_SWISH                     8          Operation not supported
  RESHAPE                        13         More than one subgraph is not supported
  MEAN                           8          More than one subgraph is not supported

Это связано с квантованием после тренировки? Я не знаю, какой именно метод квантования c после тренировки.

Секунда

Во время обучения я думал о тренировке с учетом квантования. Я создал следующее для pipe.comfig, но происходит ошибка. 1

python object_detection/model_main.py --pipeline_config_path=”object_detection/ssd_mobilenet_v3_large_coco/pipeline.config" --model_dir="./object_detection/test0001/save" --alsologtostderr

pipe.config

# SSDLite with Mobilenet v3 large feature extractor.
# Trained on COCO14, initialized from scratch.
# 3.22M parameters, 1.02B FLOPs
# TPU-compatible.
# Users should configure the fine_tune_checkpoint field in the train config as
# well as the label_map_path and input_path fields in the train_input_reader and
# eval_input_reader. Search for "PATH_TO_BE_CONFIGURED" to find the fields that
# should be configured.

model {
  ssd {
    inplace_batchnorm_update: true
    freeze_batchnorm: false
    num_classes: 2
    box_coder {
      faster_rcnn_box_coder {
        y_scale: 10.0
        x_scale: 10.0
        height_scale: 5.0
        width_scale: 5.0
      }
    }
    matcher {
      argmax_matcher {
        matched_threshold: 0.5
        unmatched_threshold: 0.5
        ignore_thresholds: false
        negatives_lower_than_unmatched: true
        force_match_for_each_row: true
        use_matmul_gather: true
      }
    }
    similarity_calculator {
      iou_similarity {
      }
    }
    encode_background_as_zeros: true
    anchor_generator {
      ssd_anchor_generator {
        num_layers: 6
        min_scale: 0.2
        max_scale: 0.95
        aspect_ratios: 1.0
        aspect_ratios: 2.0
        aspect_ratios: 0.5
        aspect_ratios: 3.0
        aspect_ratios: 0.3333
      }
    }
    image_resizer {
      fixed_shape_resizer {
        height: 320
        width: 320
      }
    }
    box_predictor {
      convolutional_box_predictor {
        min_depth: 0
        max_depth: 0
        num_layers_before_predictor: 0
        use_dropout: false
        dropout_keep_probability: 0.8
        kernel_size: 3
        use_depthwise: true
        box_code_size: 4
        apply_sigmoid_to_scores: false
        class_prediction_bias_init: -4.6
        conv_hyperparams {
          activation: RELU_6,
          regularizer {
            l2_regularizer {
              weight: 0.00004
            }
          }
          initializer {
            random_normal_initializer {
              stddev: 0.03
              mean: 0.0
            }
          }
          batch_norm {
            train: true,
            scale: true,
            center: true,
            decay: 0.97,
            epsilon: 0.001,
          }
        }
      }
    }
    feature_extractor {
      type: 'ssd_mobilenet_v3_large'
      min_depth: 16
      depth_multiplier: 1.0
      use_depthwise: true
      conv_hyperparams {
        activation: RELU_6,
        regularizer {
          l2_regularizer {
            weight: 0.00004
          }
        }
        initializer {
          truncated_normal_initializer {
            stddev: 0.03
            mean: 0.0
          }
        }
        batch_norm {
          train: true,
          scale: true,
          center: true,
          decay: 0.97,
          epsilon: 0.001,
        }
      }
      override_base_feature_extractor_hyperparams: true
    }
    loss {
      classification_loss {
        weighted_sigmoid_focal {
          alpha: 0.75,
          gamma: 2.0
        }
      }
      localization_loss {
        weighted_smooth_l1 {
          delta: 1.0
        }
      }
      classification_weight: 1.0
      localization_weight: 1.0
    }
    normalize_loss_by_num_matches: true
    normalize_loc_loss_by_codesize: true
    post_processing {
      batch_non_max_suppression {
        score_threshold: 1e-8
        iou_threshold: 0.6
        max_detections_per_class: 100
        max_total_detections: 100
        use_static_shapes: true
      }
      score_converter: SIGMOID
    }
  }
}

train_config: {
  batch_size: 4
  sync_replicas: true
  startup_delay_steps: 0
  replicas_to_aggregate: 32
  num_steps: 10000
  data_augmentation_options {
    random_horizontal_flip {
    }
  }
  data_augmentation_options {
    ssd_random_crop {
    }
  }
  optimizer {
    momentum_optimizer: {
      learning_rate: {
        cosine_decay_learning_rate {
          total_steps: 10000
          warmup_steps: 10000
        }
      }
      momentum_optimizer_value: 0.9
    }
    use_moving_average: false
  }
  fine_tune_checkpoint: "./object_detection/ssd_mobilenet_v3_large_coco/model.ckpt"
  from_detection_checkpoint: true
  max_number_of_boxes: 100
  unpad_groundtruth_tensors: false
}

train_input_reader: {
  tf_record_input_reader {
    input_path: "./object_detection/test0001/train/test????.tfrecord"
  }
  label_map_path: "./object_detection/test0001/tf_label_map.pbtxt"
}

eval_config: {
  num_examples: 8000
  # Note: The below line limits the evaluation process to 10 evaluations.
  # Remove the below line to evaluate indefinitely.
  max_evals: 10
}

eval_input_reader: {
  tf_record_input_reader {
    input_path: "./object_detection/test0001/val/test????.tfrecord"
  }
  label_map_path: "./object_detection/test0001/tf_label_map.pbtxt"
  shuffle: false
  num_readers: 1
}
graph_rewriter {
  quantization {
    delay: 48000
    weight_bits: 8
    activation_bits: 8
  }
}

log

tensorflow.python.framework.errors_impl.NotFoundError: Restoring from checkpoint failed. This is most likely due to a Variable name or other graph key that is missing from the checkpoint. Please ensure that you have not altered the graph expected based on the checkpoint. Original error:

Key FeatureExtractor/MobilenetV3/Conv/conv_quant/max not found in checkpoint

среда

OS:WINDOWS10
tensorflow:1.15.0rc3

...