AI, DataScience

[PyTorch] PyTorch를 공부하는 이유

이무기뱀술 2022. 2. 16. 10:00
728x90

케라스는 너무 편하다. 아래와 같이 대충 만들어도 대충 잘 돌아간다

그런데 현업에서는 PyTorch를 많이 쓴다고 한다.

 

대학원에 잡혀있는 동기도 keras 왜 쓰냐고하더라.

# Keras_tuner 코드
def model_builder(hp):
  model = Sequential()
  hp_units = hp.Int('units', min_value = 4, max_value = EPOCH, step = 4)
  hp_dropout = hp.Float('dropout', min_value=0.0, max_value=0.5, default=0.05, step=0.05)

  model.add(Dense(units = hp_units, activation='relu')) # input_shape = 63
  
  model.add(Dropout(hp_dropout))
  model.add(Dense(units = hp_units, activation='relu'))
  
  model.add(Dropout(hp_dropout))
  model.add(Dense(units = hp_units, activation='relu'))

  model.add(Dropout(hp_dropout))
  model.add(Dense(1, activation='sigmoid')) # 출력층

  # Tune the learning rate for the optimizer S
  hp_learning_rate = hp.Choice('learning_rate', values = [1e-2, 1e-3]) # 0.01 or 0.001

  model.compile(optimizer = Adam(learning_rate = hp_learning_rate),
                loss="binary_crossentropy", # 손실함수: binary_crossentropy
                metrics = ['accuracy']) # 평가지표
  
  return model

 

이런 다층퍼셉트론 코드를 파이토치로 바꾸는 것이 단기 목표이다.

728x90