2017-08-27 28 views
0

hereのようにActor-Criticメソッドのネットワークを構築しようとしています。具体的には、ポリシーとバリュー機能のために、最後に完全に接続されたレイヤーとReLUアクティベーションを2つの出力レイヤーに接続しようとしています。しかし、私は小さなdnnのグラフモデルでこれを行う方法をドキュメントから理解できません。tiny-dnnでレイヤーを複数の出力レイヤーに接続する方法は?

(これは間違っている)私が試した何

(編集を参照してください):

layers::input in(size_inputs); 
layers::fc h1(size_inputs, size_hidden); 
layers::fc h2(size_hidden, size_hidden); 
layers::fc h3(size_hidden, size_hidden); 
layers::fc h4(size_hidden, size_hidden); 

layers::fc out_policy(size_hidden, size_ouputs); 
layers::fc out_value(size_hidden, 1); 

activation::leaky_relu activation_h; 
activation::softmax activation_out_policy; 
layers::linear activation_out_value(1); 

auto &t1 = in << h1 << activation_h; 
auto &t2 = t1 << h2 << activation_h; 
auto &t3 = t2 << h3 << activation_h; 
auto &t4 = t3 << h4 << activation_h; 
auto &t5 = t4 << (out_policy,out_value); 

construct_graph(m_network, {&in}, {&out_policy, &out_value}); 

は(コネクト機能に "範囲外ベクトル添字を" エラーを与える、自動out_shape =頭部」で> < <オペレータへの最後の呼び出し時にout_shape()[head_index];」

編集:ああ、私は馬鹿ですが、文書が完全な例を提供する可能性があります。まず、ネットワークコンポーネントの寿命は、ネットワーク自体の存続期間と同じである必要があります。明らかではない。第二に、これは実際には、ある点まで動作します。実行時に2つの出力を生成するネットワークを構築しますが、softmax出力はすべて間違っています。負の数を返します。

auto &t1 = in << h1 << activation_h; 
auto &t2 = t1 << h2 << activation_h; 
auto &t3 = t2 << h3 << activation_h; 
auto &t4 = t3 << h4 << activation_h; 
auto &t5 = t4 << out_policy; 
auto &t6 = t4 << out_value; 

construct_graph(m_network, {&in}, {&out_policy, &out_value}); 

答えて

0

OK、答えは質問に実際にある:ネットワークに2つの出力を追加するための正しい方法は次のとおりです。

out_policy << activation_out_policy; 
out_value << activation_out_value; 

auto& t = in 
    << h1 << activation_h1 
    << h2 << activation_h2 
    << h3 << activation_h3 
    << h4 << activation_h4; 
t << out_value; 
t << out_policy; 

construct_graph(m_network, {&in}, {&activation_out_policy, &activation_out_value}); 

そしてもちろん、あなたがいないと、活性化層でconstruct_graphを呼び出す必要があります私がしていたように、合計層。

0

私は同じことを達成しようとしているが、私は活性化関数

auto in = std::make_shared<layers::input>(size_inputs); 
auto h1 = std::make_shared<layers::fc>(size_inputs, size_hidden); 
auto h2 = std::make_shared<layers::fc>(size_hidden, size_hidden); 
auto h3 = std::make_shared<layers::fc>(size_hidden, size_hidden); 
auto h4 = std::make_shared<layers::fc>(size_hidden, size_hidden); 

auto out_policy = std::make_shared<layers::fc>(size_hidden, size_ouputs); 
auto out_value = std::make_shared<layers::fc>(size_hidden, 1); 

activation::leaky_relu activation_h; 
activation::softmax activation_out_policy; 
layers::linear activation_out_value(1); 

network<graph> net; 

in << h1 << activation_h 
    << h2 << activation_h 
    << h3 << activation_h 
    << h4; 
h4 << out_policy << activation_out_policy; 
h4 << out_value << activation_out_value; 

construct_graph(net, {&in}, {&activation_out_policy,&activation_out_value}); 

エラーなどがあれば、私は、コンパイラのエラーを取得する:「演算子< <」の不一致(オペランドの型は「STDですが:: shared_ptrの」と 'tiny_dnn :: < < H1 <で活性化:: leaky_relu {別名tiny_dnn :: leaky_relu_layer}') < activation_h ~~~~~~~~~^~~~~~~~~~~~ ~~~ ファイル内に.../include/tiny_dnn/lossfunctions/loss_function.h:12:0,

01が含まれています
+0

shared_ptrsを<<演算子で接続することはできません。 '<< << h1 << activation_h >>のようにすべてのポインタを逆参照してみてください。 – MaxEd

+0

ありがとう、少し進歩しました。コンパイルされますが、グラフは作成されません。私は新しい質問を提起します。 – user1305541

関連する問題