Tiny-DNN共享FC层

时间:2020-10-20 18:10:28

标签: c++ tiny-dnn

我想在tiny-dnn中创建共享的完全连接层。 例如。我有输入形状(3x1x1)。和权重(3x64x1)。我们有输出(64x1x1)。 我想要输入(3x1xk),权重(3x64x1)和输出(64x1xk)。我怎样才能做到这一点??? 我搜索了但没有找到。 例如: 这有效:

#include <vector>
#include <stdexcept>
#include <assert.h>
#include <stdint.h>
#include <math.h>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <complex>
#include "tiny_dnn/tiny_dnn.h"
#include <list>
using namespace std;
using namespace tiny_dnn;
using namespace tiny_dnn::layers;
using namespace tiny_dnn::activation;

void build_simple(int k){
  network<graph> nn;
  layers::input inp(shape3d(3,1,1));
  layers::fc fc_mul(3,64,false);
  inp<<fc_mul;
  construct_graph(nn, { &inp },{&fc_mul});
  std::ofstream ofs("graph_nn_example.txt");
  graph_visualizer viz(nn, "graph");
  viz.generate(ofs);
  for (int     i = 0; i < nn.depth(); i++) {
    cout     << "#layer:" << i << "\n";
    cout     << "layer type:" << nn[i]->layer_type() << "\n";
    cout     << "input:" << nn[i]->in_data_size() << "(" << nn[i]->in_data_shape() << ")\n";
    cout     << "output:" << nn[i]->out_data_size() << "(" <<   nn[i]->out_data_shape() <<")\n";
  }
  system("dot -Tgif graph_nn_example.txt -o graph.gif");
  system("gwenview graph.gif");
}

这有望奏效,但无效:

void build_simple(int k){
network<graph> nn;
layers::input inp(shape3d(3,k,1));
layers::fc fc_mul(3,64,false);
inp<<fc_mul;
construct_graph(nn, { &inp },{&fc_mul});
std::ofstream ofs("graph_nn_example.txt");
graph_visualizer viz(nn, "graph");
viz.generate(ofs);
for (int     i = 0; i < nn.depth(); i++) {
  cout     << "#layer:" << i << "\n";
  cout     << "layer type:" << nn[i]->layer_type() << "\n";
  cout     << "input:" << nn[i]->in_data_size() << "(" << nn[i]->in_data_shape() << ")\n";
  cout     << "output:" << nn[i]->out_data_size() << "(" << nn[i]->out_data_shape() <<")\n";
}
system("dot -Tgif graph_nn_example.txt -o graph.gif");
system("gwenview graph.gif");
}

int main(){
  build_simple(10);
}

0 个答案:

没有答案
相关问题