2017-09-11 1 views
0

공유 레이어가 CNTK에서 효율적으로 처리됩니까? dual_model을 평가할 때공유 레이어가 효율적으로 처리됩니까?

def create_func(shared_layers, out1_layers, out2_layers): 

    # ... there would be a with block specifying activations...omitted for brevity 
    shared_hl_func = For(shared_layers, lambda n: Dense(n), name="Shared Hidden Layers") 
    out1_hl_func = For(out1_layers, lambda n: Dense(n), name="Out1 Only Hidden Layers") 
    out2_hl_func = For(out2_layers, lambda n: Dense(n), name="Sigma Only Hidden Layers") 

    output1_func = Sequential([shared_hl_func, out1_hl_func, 
            Dense(1, activation=None, init=init, name="Out1_Regression_Layer")], name="Out1") 
    output2_func = Sequential([shared_hl_func, out2_hl_func, 
           Dense(1, activation=None, init=init, name="Out2_Regression_Layer")], name="Out2") 
    return output1_func, output2_func 

output1, output2 = create_func([50,25], [25, 10], [25, 10]) 
my_input = cntk.input_variable((70,)) 
dual_model = cntk.combine(output1(my_input), output2(my_input)) 

계산을 효율적으로 수행 할 것이다 :

서있 예 I는 다음과 같은 식을 가정 (즉, 활성 계산은 중복되지 않고)? (즉, 처음 두 개의 더 넓은 밀도의 레이어는 한 번만 계산 된 후 공유됩니까? 그렇지 않은 경우 명시적인 함수 작성을 통해 효율성을 구성 할 것입니까?

답변

1

위의 코드에서 shared_hl_func는 독립적으로 평가됩니다 ..

import cntk 
from cntk.layers import * 
def create_func(shared_layers, out1_layers, out2_layers): 
    shared_hl_func = For(shared_layers, lambda n: Dense(n), name="Shared Hidden Layers") 
    out1_hl_func = For(out1_layers, lambda n: Dense(n), name="Out1 Only Hidden Layers") 
    out2_hl_func = For(out2_layers, lambda n: Dense(n), name="Sigma Only Hidden Layers") 
    out1_regr_func = Dense(1, activation=None, name="Out1_Regression_Layer") 
    out2_regr_func = Dense(1, activation=None, name="Out2_Regression_Layer") 
    @cntk.Function 
    def _func(x): 
     # ... there would be a with block specifying activations...omitted for brevity 
     shared_hl = shared_hl_func(x) 
     output1 = Sequential([out1_hl_func, out1_regr_func], name="Out1")(shared_hl) 
     output2 = Sequential([out2_hl_func, out2_regr_func], name="Out2")(shared_hl) 
     return cntk.combine(output1, output2) 
    return _func 

output = create_func([50,25], [25, 10], [25, 10]) 
my_input = cntk.input_variable((70,)) 
dual_model = output(my_input) 
# use plot to visualize the model 
cntk.logging.graph.plot(dual_model, 'dual.pdf') 
: output1_func 및 output2_func에서, 매개 변수를 공유하지만 계산 그래프를 확인하려면, 그것을 시각화 plot을 사용하시기 바랍니다

는 계산 공유를 달성하기 위해, 당신은 output1_func 및 출력 2로 shared_hl_func 출력 변수를 전달해야

+0

감사합니다. 내 comp 내가 더 많은 레이어를 공유 했음에도 유추 동안 유창 시간은 줄어들지 않았습니다. 내 시스템에서 GraphViz를 사용할 수 없습니다. 이 목적을 위해 TensorBoardProgressWriter로 만든 시각화도 정확합니까? – tarlinian

+0

예, 텐서 보드에서도 모델을 시각화 할 수 있습니다. – KeD

관련 문제