Python - 조건 if문이 포함된 한 줄 return 문 사용하기
함수의 리턴문에 한줄로 if문을 사용하는 예제 코드입니다. 참고 https://stackoverflow.com/a/18669843/19664020 2022. 10. 27 최초작성 def f(num): # num값이 1이면 'one'을 리턴하고 나머지 경우에는 'other'를 리턴합니다. return 'one' if num==1 else 'other' # 'one'을 출력합니다. print(f(1)) # 'other'를 출력합니다. print(f(2)) 실행 결과 one other
- Python/Python 예제 코드
- · 2022. 10. 27.
Keras 모델을 TensorFlow Lite로 변환하기 (h5 -> pb -> tflite)
Keras 모델을 저장한 .h5 파일을 Tensorflow Lite용 모델 .tflite로 변환하는 코드입니다. 2022. 10. 23 최초작성 import tensorflow as tf import efficientnet.keras as efn import sys if len(sys.argv) != 2: print(f"Usage : {sys.argv[0]} h5_file") exit(0) file_name = sys.argv[1] model = tf.keras.models.load_model(file_name) converter = tf.lite.TFLiteConverter.from_keras_model(model) tflite_model = converter.convert() open( file_na..
- Deep Learning & Machine Learning/Keras
- · 2022. 10. 23.
lambda와 map을 사용하여 list 원소에 똑같은 문자열을 추가하는 Python 예제
lambda와 map을 사용하여 list 원소에 똑같은 문자열을 추가하는 Python 예제입니다. list에 저장된 경로에 동일한 경로를 추가해야 할 경우 유용합니다. 2022. 10. 23 최초작성 a = ['a', 'b', 'c'] root = './home' print(a) # ['a', 'b', 'c'] path = list(map(lambda x: root + '/' + x, a)) print(path) # ['./home/a', './home/b', './home/c']
- Python/Python 예제 코드
- · 2022. 10. 23.