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

[링크 : 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 구차니
Linux/Ubuntu2021. 4. 14. 18:59

서비스로 만들어서 넣거나

자동 로그인 켜거나

 

[링크 : https://askubuntu.com/questions/636270/vino-vnc-server-unable-to-start-on-startup]

'Linux > Ubuntu' 카테고리의 다른 글

ubuntu 무선 미러링  (0) 2021.07.13
gpsd 현재 좌표 얻기  (0) 2021.06.05
ubuntu gnome-control-center over ssh  (0) 2021.04.14
우분투 패키지 버전 확인하기  (0) 2020.12.16
ubuntu 20.04 한글입력기  (2) 2020.12.07
Posted by 구차니
Linux/Ubuntu2021. 4. 14. 15:46

ubuntu 20.04 에서 SSH X11 forwarding 상태로 실행하면

devices / details만 나오고 내용이 없는 상태로 나온다.

 

다만.. Display 설정과 화면 공유(display sharing)설정이 안되네 ㅠㅠ

$ env XDG_CURRENT_DESKTOP=GNOME gnome-control-center

[링크 : https://blog.rixa.kr/58]

'Linux > Ubuntu' 카테고리의 다른 글

gpsd 현재 좌표 얻기  (0) 2021.06.05
vino server without login  (0) 2021.04.14
우분투 패키지 버전 확인하기  (0) 2020.12.16
ubuntu 20.04 한글입력기  (2) 2020.12.07
/dev/ipmi를 보고 싶다!!!  (0) 2020.11.07
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 구차니

서울시장 보궐선거의 결과는 충격적이긴 한데

솔찍히 말해서 서울시민이 아니라 누가 뽑히던 상관없...나? 싶기도 했고

개인적으로는 1,2 둘다 아닌 다른 사람이 뽑혔으면 했지만

 

어떤 의미로는 죄수의 딜레마가 적용되면서

2번을 막할 가장 유력한 한사람을 찍게 된게 아닐까 싶긴 한데 (여기까지는 합리적)

누구를 뽑겠다고 말하며 집단지성을 통해 뽑을 사람을 결정하는 것은 불법일테니

설문에 의한 결과를 보고 유력한 후보를 뽑게 된게 아닐까 생각이 된다.

 

다만.. 가장 뽑혀서는 안될 사람이 그 대항마가 된 게 이해가 안되는 포인트.

20대 남자들의 분노를 이해 못하는건 아니지만

이젠 둘다 바닥으로 끌어내려서 너가 날 죽이려 했으니 너도 죽어야 한다는

진흙탕 싸움으로 밖에 결론이 나지 않을 시대가 된 것 같아서 씁쓸할 뿐이다.

 

애 둘 키우는 나로서도 언론을 보고 있노라면

남자라는 건 존재 자체로 죄라는 느낌인데

언론에 의해서 두드려 맞고 동년배 여자들에 의해서 욕 쳐먹고

존재자체가 문제인 것으로 취급당하는 세대가 되고 있으니

어느정도 자아가 형성되고 나서 멘탈은 털리더라도 버텨낼수 있고

싸워서 대응이 가능한 내 또래의 세대와는 다를수 밖에 없지 않나 싶기도 싶다.

그러니 젊은 혈기에 C8 엎어 버리자가 된 것 같아서 더 슬플뿐..

(직설적으로는 히히히 똥오줌 발싸! 느낌)

 

다만 그 대상이 그 아이들에게 있어서는 일어나지 않은 가능성의 영역이었던

"무상급식 반대 논란"의 대상자 였기 때문에

"실패도 성공도 오롯이 나의 것이다"라는 나의 경험을 비추어 보건대

경험해 보지 않았기에 경험해 보고 싶었나.. 라는 아쉬움과 미움마저 든다.

 

그나저나 연나이/만나이 40/30의 경계에 있으니

30 욕먹어도 빡치고

40 욕먹어도 빡치네 ㅋㅋㅋㅋ

 

 

황교익 "여성과 경쟁하게 된 20대男, 불만 일리 있다"
[링크 : http://news.v.daum.net/v/20210411171553699]

 

온라인 불지핀 류근의 돌직구.."남자들 군대갈 때, 여자들은 봉사하라"

[링크 : http://news.v.daum.net/v/20210411105309732]

 

이준석 "'페미 선언'했다고 도덕적으로 더 우월안해"

[링크 : http://news.v.daum.net/v/20210411144851809]

 

"여성정책 치우쳐 '이남자' 떠났다? 기득권 민주당 심판한 것"

[링크 : http://news.v.daum.net/v/20210412050621431]

'개소리 왈왈 > 정치관련 신세한탄' 카테고리의 다른 글

최고의 대응책  (0) 2021.07.07
지옥에 온 것을 환영하오 낮선이여!!  (0) 2021.04.29
KF-X 8조 8천  (2) 2021.04.11
서울 시민은 아니지만..  (2) 2021.04.07
15년 전 탓을 하네  (0) 2021.03.09
Posted by 구차니

22조에 비하면 껌값.. 

 

읍읍읍!

 

[링크 : https://www.hankyung.com/politics/article/2015122413511]

Posted by 구차니
개소리 왈왈/컴퓨터2021. 4. 10. 19:46

별게 다생겼네..

 

SD는 Studio Driver

GRD는 Game Ready Driver로

GRD는 기존의 일반 드라이버 SD는 스튜디오를 위한 안정적인 버전으로

 

안정화 버전과 성능버전 두개로 나눠가지는 느낌인데

이게 적용된게 요 근래라.. 구버전들에 대해서는 GRD로 검색을 해야 드라이버가 나온다는 건 좀 귀찮네..

 

[링크 : http://itrum.tistory.com/151]

Posted by 구차니