pip install pydot

sudo apt-get install graphviz (pip install graphviz 하면 안됨)


python 코드

from keras.utils import plot_model

plot_model(model, to_file='model.png') # 연결 구조 출력

plot_model(Focal_Loss, to_file='model_detail.png', show_shapes=True, show_layer_names=True) # input/output shape 까지 출력



아래는 keras.io 내용


plot_model

keras.utils.plot_model(model, to_file='model.png', show_shapes=False, show_layer_names=True, rankdir='TB')

Converts a Keras model to dot format and save to a file.

Arguments

  • model: A Keras model instance
  • to_file: File name of the plot image.
  • show_shapes: whether to display shape information.
  • show_layer_names: whether to display layer names.
  • rankdirrankdir argument passed to PyDot, a string specifying the format of the plot: 'TB' creates a vertical plot; 'LR' creates a horizontal plot.


'실습 > keras' 카테고리의 다른 글

loss weight 추가하기 및 학습 도중 loss weight 바꾸기  (1) 2018.01.13
merge  (0) 2017.01.23
Theano tensor  (0) 2017.01.21
theano.shared(value=W_values, name='W', borrow=True)  (0) 2017.01.21
theano.config.floatX  (0) 2017.01.21

import keras.backend as K


w1 = K.variable(1.2)

w2 = K.variable(1.6)


model.compile( .., loss_weights=[w1, w2], ..) # loss별 weight 부여


class Dynamic_loss_weights(Callback): # 콜백클래스 상속

    def __init__(self, w1, w2):

        self.w1 = w1

        self.w2 = w2

    def on_epoch_end(self, epoch, log={}): # epoch 끝날 때마다 호출됨

        K.set_value(self.w1, K.get_value(self.w1) + 0.1)

        K.set_value(self.w2, K.get_value(self.w2) - 0.1)


new_callback = Dynamic_loss_weights(w1, w2)


model.fit(..., callbacks = new_callback, ...) # 여러 콜백클래스를 사용하면, 콜백리스트에 append 시켜주면 됨

# model.fit_generator 도 같은 방법으로 추가

'실습 > keras' 카테고리의 다른 글

model 시각화 방법  (0) 2018.02.14
merge  (0) 2017.01.23
Theano tensor  (0) 2017.01.21
theano.shared(value=W_values, name='W', borrow=True)  (0) 2017.01.21
theano.config.floatX  (0) 2017.01.21

conv_result = merge([conv_unigram, conv_bigram, conv_trigram], mode='concat', concat_axis=2)

 

mode='concat', concat_axis=2

선택 된 아웃 풋들의 2번 째 요소를 다 이어붙임 (이 요소를 제외한 다른 요소들의 크기는 같아야함)

'실습 > keras' 카테고리의 다른 글

model 시각화 방법  (0) 2018.02.14
loss weight 추가하기 및 학습 도중 loss weight 바꾸기  (1) 2018.01.13
Theano tensor  (0) 2017.01.21
theano.shared(value=W_values, name='W', borrow=True)  (0) 2017.01.21
theano.config.floatX  (0) 2017.01.21

http://deeplearning.net/software/theano/library/tensor/basic.html

'실습 > keras' 카테고리의 다른 글

model 시각화 방법  (0) 2018.02.14
loss weight 추가하기 및 학습 도중 loss weight 바꾸기  (1) 2018.01.13
merge  (0) 2017.01.23
theano.shared(value=W_values, name='W', borrow=True)  (0) 2017.01.21
theano.config.floatX  (0) 2017.01.21

theano.shared(value=W_values, name='W', borrow=True)

 

GPU에 해당 데이터를 올리고, 그것에 대한 이름을 정의한다.

'실습 > keras' 카테고리의 다른 글

model 시각화 방법  (0) 2018.02.14
loss weight 추가하기 및 학습 도중 loss weight 바꾸기  (1) 2018.01.13
merge  (0) 2017.01.23
Theano tensor  (0) 2017.01.21
theano.config.floatX  (0) 2017.01.21

theano.config.floatX

 

float64와 같음

GPU에선 float64가 float32보다 계산이 빨라서

GPU 연산을 수행할 데이터를 형변환할 때 주로 사용

'실습 > keras' 카테고리의 다른 글

model 시각화 방법  (0) 2018.02.14
loss weight 추가하기 및 학습 도중 loss weight 바꾸기  (1) 2018.01.13
merge  (0) 2017.01.23
Theano tensor  (0) 2017.01.21
theano.shared(value=W_values, name='W', borrow=True)  (0) 2017.01.21

+ Recent posts