'프로그램 사용'에 해당되는 글 2277건

  1. 2021.04.16 tflite convert
  2. 2021.04.16 LSTM - Long short-term memory
  3. 2021.04.15 quantization: 0.003921568859368563 * q
  4. 2021.04.14 tflite_converter quantization
  5. 2021.04.14 tensorboard graph
  6. 2021.04.13 generate_tfrecord.py
  7. 2021.04.12 Learning without Forgetting (LwF)
  8. 2021.04.12 딥러닝 학습 transfer, quantization
  9. 2021.04.09 tf checkpoint to pb
  10. 2021.04.09 gdb break

'프로그램 사용 > yolo_tensorflow' 카테고리의 다른 글

tflite type  (0) 2021.05.01
tflite example  (0) 2021.04.19
LSTM - Long short-term memory  (0) 2021.04.16
quantization: 0.003921568859368563 * q  (0) 2021.04.15
tflite_converter quantization  (0) 2021.04.14
Posted by 구차니

tensorflow model 뒤져보다 보니 lstm 이라는 용어는 본적이 있는데

귀찮아서 넘기다가 이번에도 또 검색중에 걸려나와서 조사.

 

RNN(Recurrent nerural network) 에서 사용하는 기법(?)으로 문맥을 강화해주는 역활을 하는 듯.

 

[링크 : http://euzl.github.io/hackday_1/]

[링크 : https://en.wikipedia.org/wiki/Long_short-term_memory]

 

'프로그램 사용 > yolo_tensorflow' 카테고리의 다른 글

tflite example  (0) 2021.04.19
tflite convert  (0) 2021.04.16
quantization: 0.003921568859368563 * q  (0) 2021.04.15
tflite_converter quantization  (0) 2021.04.14
tensorboard graph  (0) 2021.04.14
Posted by 구차니

tflite로 변환시 unit8로 양자화 하면

분명 범위는 random으로 들어가야 해서 quantization 범위가 조금은 달라질 것으로 예상을 했는데

항상 동일한 0.003921568859368563 * q로 나와 해당 숫자로 검색을 하니

0~255 범위를 float로 정규화 하면 해당 숫자가 나온다고..

 

0.00392 * 255 = 0.9996 이 나오긴 하네?

quantization of input tensor will be close to (0.003921568859368563, 0). mean is the integer value from 0 to 255 that maps to floating point 0.0f. std_dev is 255 / (float_max - float_min). This will fix one possible problem

[링크 : https://stackoverflow.com/questions/54830869/]

[링크 : https://github.com/majidghafouri/Object-Recognition-tf-lite/issues/1]

 

+

output_format: Output file format. Currently must be {TFLITE, GRAPHVIZ_DOT}. (default TFLITE)
quantized_input_stats: Dict of strings representing input tensor names mapped to tuple of floats representing the mean and standard deviation of the training data (e.g., {"foo" : (0., 1.)}). Only need if inference_input_type is QUANTIZED_UINT8. real_input_value = (quantized_input_value - mean_value) / std_dev_value. (default {})
default_ranges_stats: Tuple of integers representing (min, max) range values for all arrays without a specified range. Intended for experimenting with quantization via "dummy quantization". (default None)
post_training_quantize: Boolean indicating whether to quantize the weights of the converted float model. Model size will be reduced and there will be latency improvements (at the cost of accuracy). (default False)

[링크 : http://man.hubwiz.com/.../python/tf/lite/TFLiteConverter.html]

 

TOCO(Tensorflow Lite Optimized Converter)

[링크 : https://junimnjw.github.io/%EA%B0%9C%EB%B0%9C/2019/08/09/tensorflow-lite-2.html]

'프로그램 사용 > yolo_tensorflow' 카테고리의 다른 글

tflite convert  (0) 2021.04.16
LSTM - Long short-term memory  (0) 2021.04.16
tflite_converter quantization  (0) 2021.04.14
tensorboard graph  (0) 2021.04.14
generate_tfrecord.py  (0) 2021.04.13
Posted by 구차니

이것저것.. 원본 소스까지 뒤지고 있는데 이렇다 할 원하는 답이 안보인다.

[링크 : https://www.tensorflow.org/model_optimization/guide/quantization/training]

[링크 : https://www.tensorflow.org/model_optimization/guide/quantization/training_example]

[링크 : https://github.com/tensorflow/.../lite/g3doc/performance/post_training_quantization.md]

[링크 : https://github.com/tensorflow/.../lite/g3doc/performance/quantization_spec.md]

 

util_test.py

def _generate_integer_tflite_model(quantization_type=dtypes.int8):
  """Define an integer post-training quantized tflite model."""
  # Load MNIST dataset
  n = 10  # Number of samples
  (train_images, train_labels), (test_images, test_labels) = \
      tf.keras.datasets.mnist.load_data()
  train_images, train_labels, test_images, test_labels = \
      train_images[:n], train_labels[:n], test_images[:n], test_labels[:n]

  # Normalize the input image so that each pixel value is between 0 to 1.
  train_images = train_images / 255.0
  test_images = test_images / 255.0

  # Define TF model
  model = tf.keras.Sequential([
      tf.keras.layers.InputLayer(input_shape=(28, 28)),
      tf.keras.layers.Reshape(target_shape=(28, 28, 1)),
      tf.keras.layers.Conv2D(filters=12, kernel_size=(3, 3), activation="relu"),
      tf.keras.layers.MaxPooling2D(pool_size=(2, 2)),
      tf.keras.layers.Flatten(),
      tf.keras.layers.Dense(10)
  ])

  # Train
  model.compile(
      optimizer="adam",
      loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),
      metrics=["accuracy"])

  model.fit(
      train_images,
      train_labels,
      epochs=1,
      validation_split=0.1,
  )

  # Convert TF Model to an Integer Quantized TFLite Model
  converter = tf.lite.TFLiteConverter.from_keras_model(model)
  converter.optimizations = {tf.lite.Optimize.DEFAULT}
  def representative_dataset_gen():
    for _ in range(2):
      yield [
          np.random.uniform(low=0, high=1, size=(1, 28, 28)).astype(
              np.float32)
      ]
  converter.representative_dataset = representative_dataset_gen
  if quantization_type == dtypes.int8:
    converter.target_spec.supported_ops = {tf.lite.OpsSet.TFLITE_BUILTINS_INT8}
  else:
    converter.target_spec.supported_ops = {
        tf.lite.OpsSet
        .EXPERIMENTAL_TFLITE_BUILTINS_ACTIVATIONS_INT16_WEIGHTS_INT8
    }
  tflite_model = converter.convert()

  return tflite_model

 

lite_v2_test.py

  def _getIntegerQuantizeModel(self):
    np.random.seed(0)

    root = tracking.AutoTrackable()

    @tf.function(
        input_signature=[tf.TensorSpec(shape=[1, 5, 5, 3], dtype=tf.float32)])
    def func(inp):
      conv = tf.nn.conv2d(
          inp, tf.ones([3, 3, 3, 16]), strides=[1, 1, 1, 1], padding='SAME')
      output = tf.nn.relu(conv, name='output')
      return output

    def calibration_gen():
      for _ in range(5):
        yield [np.random.uniform(-1, 1, size=(1, 5, 5, 3)).astype(np.float32)]

    root.f = func
    to_save = root.f.get_concrete_function()
    return (to_save, calibration_gen)


 def testInvalidIntegerQuantization(self, is_int16_quantize,
                                     inference_input_output_type):
    func, calibration_gen = self._getIntegerQuantizeModel()

    # Convert quantized model.
    quantized_converter = lite.TFLiteConverterV2.from_concrete_functions([func])
    quantized_converter.optimizations = [lite.Optimize.DEFAULT]
    quantized_converter.representative_dataset = calibration_gen
    if is_int16_quantize:
      quantized_converter.target_spec.supported_ops = [
          lite.OpsSet.\
          EXPERIMENTAL_TFLITE_BUILTINS_ACTIVATIONS_INT16_WEIGHTS_INT8,
          lite.OpsSet.TFLITE_BUILTINS
      ]
    with self.assertRaises(ValueError) as error:
      quantized_converter.inference_input_type = dtypes.int8
      quantized_converter.inference_output_type = dtypes.int8
      quantized_converter.convert()
    self.assertEqual(
        'The inference_input_type and inference_output_type '
        "must be in ['tf.float32', 'tf.int16'].", str(error.exception))


  def testCalibrateAndQuantizeBuiltinInt16(self):
    func, calibration_gen = self._getIntegerQuantizeModel()

    # Convert float model.
    float_converter = lite.TFLiteConverterV2.from_concrete_functions([func])
    float_tflite_model = float_converter.convert()
    self.assertIsNotNone(float_tflite_model)

    converter = lite.TFLiteConverterV2.from_concrete_functions([func])
    # TODO(b/156309549): We should add INT16 to the builtin types.
    converter.optimizations = [lite.Optimize.DEFAULT]
    converter.target_spec.supported_ops = [lite.OpsSet.TFLITE_BUILTINS_INT8]
    converter.representative_dataset = calibration_gen
    converter._experimental_calibrate_only = True
    calibrated_tflite = converter.convert()
    quantized_tflite_model = mlir_quantize(
        calibrated_tflite, inference_type=_types_pb2.QUANTIZED_INT16)

    self.assertIsNotNone(quantized_tflite_model)

    # The default input and output types should be float.
    interpreter = Interpreter(model_content=quantized_tflite_model)
    interpreter.allocate_tensors()
    input_details = interpreter.get_input_details()
    self.assertLen(input_details, 1)
    self.assertEqual(np.float32, input_details[0]['dtype'])
    output_details = interpreter.get_output_details()
    self.assertLen(output_details, 1)
    self.assertEqual(np.float32, output_details[0]['dtype'])

    # Ensure that the quantized weights tflite model is smaller.
    self.assertLess(len(quantized_tflite_model), len(float_tflite_model))

'프로그램 사용 > yolo_tensorflow' 카테고리의 다른 글

LSTM - Long short-term memory  (0) 2021.04.16
quantization: 0.003921568859368563 * q  (0) 2021.04.15
tensorboard graph  (0) 2021.04.14
generate_tfrecord.py  (0) 2021.04.13
Learning without Forgetting (LwF)  (0) 2021.04.12
Posted by 구차니

pb 파일을 tensorboard에 끌어가면

간혹(?) graph 항목에 내용이 없는 경우가 있어서

어떻게 해야 해당 항목을 활성화 할 수 있나 검색중

 

[링크 : http://stackoverflow.com/questions/48391075]

 

writer = tf.summary.FileWriter("output", sess.graph)

[링크 : http://www.h2kinfosys.com/blog/tensorboard-how-to-use-tensorboard-for-graph-visualization/]

[링크 : http://www.tensorflow.org/tensorboard/graphs]

 

 

'프로그램 사용 > yolo_tensorflow' 카테고리의 다른 글

quantization: 0.003921568859368563 * q  (0) 2021.04.15
tflite_converter quantization  (0) 2021.04.14
generate_tfrecord.py  (0) 2021.04.13
Learning without Forgetting (LwF)  (0) 2021.04.12
딥러닝 학습 transfer, quantization  (0) 2021.04.12
Posted by 구차니

먼가 이상해서 하나하나 뜯어 보는중

[링크 : https://www.tensorflow.org/tutorials/load_data/tfrecord]

[링크 : https://www.kaggle.com/gauravchopracg/understanding-tfrecord-format]

 

학습을 하는건 돌아가는데 

탐지가 안되거나 입력 범위가 이상하거나 이런 문제가 있어서 확인하는데

 

tfrecord 에서는 학습에 필요한 이미지를 읽어서 넣어 두는 듯?

그 과정에서 원본이 들어가냐 bitmpa으로 들어가냐를 확인하는데

 

혹시나 해서 1년 이내 글로 찾아보니 업그레이드 된 generate_tfrecord.py 를 발견!

 

[링크 : https://github.com/EdjeElectronics/.../issues/427]

'프로그램 사용 > yolo_tensorflow' 카테고리의 다른 글

tflite_converter quantization  (0) 2021.04.14
tensorboard graph  (0) 2021.04.14
Learning without Forgetting (LwF)  (0) 2021.04.12
딥러닝 학습 transfer, quantization  (0) 2021.04.12
tf checkpoint to pb  (0) 2021.04.09
Posted by 구차니

Trnasfer는 기존의 학습을 다 지우고

새로운 내용에 대한 학습을 하는 것이라면

 

LwF는 기존의 데이터에 추가로 학습을 하는 것.

 

[링크 : http://ai.stackexchange.com/questions/13644/]

'프로그램 사용 > yolo_tensorflow' 카테고리의 다른 글

tensorboard graph  (0) 2021.04.14
generate_tfrecord.py  (0) 2021.04.13
딥러닝 학습 transfer, quantization  (0) 2021.04.12
tf checkpoint to pb  (0) 2021.04.09
labelImg  (0) 2021.04.09
Posted by 구차니

transfer 는 학습된 모델에서 구조는 유지한채 학습 데이터를 날리고 

새로운 데이터로 학습하는걸 의미하는데

학습시에 양자화 범위를 지정해주는 학습도 존재하는 듯.

 

quant learning

def format_example(image, label):
  image = tf.cast(image, tf.float32)
  image = (image/127.5) - 1
  image = tf.image.resize(image, (IMG_SIZE, IMG_SIZE))
  return image, label

[링크 : https://www.tensorflow.org/tutorials/images/transfer_learning?hl=ko]

[링크 : https://github.com/EdjeElectronics/TensorFlow-Lite-Object-Detection-on-Android-and-Raspberry-Pi]

 

'프로그램 사용 > yolo_tensorflow' 카테고리의 다른 글

generate_tfrecord.py  (0) 2021.04.13
Learning without Forgetting (LwF)  (0) 2021.04.12
tf checkpoint to pb  (0) 2021.04.09
labelImg  (0) 2021.04.09
tf docker  (0) 2021.04.09
Posted by 구차니

기본으로 제공되는 건 없으려나?

 

[링크 : https://stackoverflow.com/questions/56766639/how-to-convert-ckpt-to-pb]

 

$ saved_model_cli convert tensorrt
usage: saved_model_cli convert [-h] --dir DIR --output_dir OUTPUT_DIR --tag_set TAG_SET {tensorrt} ...
saved_model_cli convert: error: the following arguments are required: --dir, --output_dir, --tag_set

'프로그램 사용 > yolo_tensorflow' 카테고리의 다른 글

Learning without Forgetting (LwF)  (0) 2021.04.12
딥러닝 학습 transfer, quantization  (0) 2021.04.12
labelImg  (0) 2021.04.09
tf docker  (0) 2021.04.09
tensorboard 사용법  (0) 2021.04.08
Posted by 구차니

귀찮아서 b main 으로만 쓰는건 함정 ㅋㅋ

for 반복문으로 인해서 귀찮아서 결국에는 라인으로 브레이크 잡는법 찾은것도 함정

 

gdb> break filename:line
gdb> b filename:line
gdb> b function

[링크 : https://stackoverflow.com/questions/5276988/]

 

브레이크 목록보기

gdb> info break
gdb> i b

[링크 : https://ccrma.stanford.edu/~jos/stkintro/Useful_commands_gdb.html]

Posted by 구차니