示例#1
0
 def __init__(self, param, io):
     self._io = io
     super(RNN_model, self).__init__(
         l1 = L.Linear(io[0],param[0]),
         l2 = L.LSTM(param[0],param[1]), #LSTM
         l3 = L.Linear(param[1],io[1]),
     )
示例#2
0
 def __init__(self, jv, ev, k):
     super(MyMT, self).__init__(
         embedx=L.EmbedID(jv, k),
         embedy=L.EmbedID(ev, k),
         H=L.LSTM(k, k),
         W=L.Linear(k, ev),
     )
示例#3
0
    def __init__(self):
        super(LSTM_VGG, self).__init__(
            conv1_1=L.Convolution2D(3, 64, 3, stride=1, pad=1),
            conv1_2=L.Convolution2D(64, 64, 3, stride=1, pad=1),
            conv2_1=L.Convolution2D(64, 128, 3, stride=1, pad=1),
            conv2_2=L.Convolution2D(128, 128, 3, stride=1, pad=1),

            #conv3_1_b=L.Convolution2D(None, 256, 3, stride=1, pad=1),
            #conv3_2_b=L.Convolution2D(None, 256, 3, stride=1, pad=1),
            #conv3_3_b=L.Convolution2D(None, 512, 3, stride=1, pad=1),
            conv4_1_b=L.Convolution2D(None, 128, 3, stride=1, pad=1),
            #conv4_2=L.Convolution2D(512, 512, 3, stride=1, pad=1),
            #conv4_3=L.Convolution2D(512, 512, 3, stride=1, pad=1),

            #conv5_1=L.Convolution2D(512, 512, 3, stride=1, pad=1),
            #conv5_2=L.Convolution2D(512, 512, 3, stride=1, pad=1),
            #conv5_3=L.Convolution2D(512, 512, 3, stride=1, pad=1),

            #fc6_b=L.Convolution2D(128, 128, 7),
            #fc7=L.Convolution2D(4096, 4096, 1),
            #fc8=L.Convolution2D(4096, 1, 1)
            #fc9=L.Linear(4096, 4)
            #ここからLSTM
            l8=L.LSTM(None, 128),
            fc9=L.Linear(None, 3))
        self.train = True
示例#4
0
 def __init__(self, word_num, feature_num, hidden_num):
     super(ImageCaption, self).__init__(
         word_vec=L.EmbedID(word_num, hidden_num),
         image_vec=L.Linear(feature_num, hidden_num),
         lstm=L.LSTM(hidden_num, hidden_num),
         out_word=L.Linear(hidden_num, word_num),
     )
示例#5
0
    def __init__(self, n_class, in_ch, n_e=24*2, n_h=48*2, g_size=32, n_step=8, scale=3, var=7.5):
        w = math.sqrt(2)  # MSRA scaling
        n_ch_after_core = 256
        n_emb_l =128
        # n_ch_in_core = n_h*2*math.ceil(g_size/8)*math.ceil(g_size/8)
        n_ch_in_core = n_h*math.ceil(g_size/4)*math.ceil(g_size/4)
        super().__init__(
            emb_l = L.Linear(2, n_emb_l),  # embed location
            emb_x = L.MLPConvolution2D( \
                in_ch*scale, (n_e, n_e, n_e), 5, pad=2, wscale=w),  # embed image
            conv_loc_to_glimpse = L.Linear(n_emb_l, n_ch_in_core),  # loc to glimpse. output channel is n_h, if FC.
            conv_image_to_glimpse = L.MLPConvolution2D( \
                n_e, (n_h, n_h, n_h), 5, pad=2, wscale=w),  # image to glimpse
            core_lstm = L.LSTM(n_ch_in_core, n_ch_after_core),  # core LSTM. in the paper, named recurrent network.
            fc_ha = L.Linear(n_ch_after_core, n_class),  # core to action(from core_lstm to action)
            fc_hl = L.Linear(n_ch_after_core, 2),  # core to loc(from core_lstm to loc). in the paper, named emission network.
            fc_hb = L.Linear(n_ch_after_core, 1),  # core to baseline(from core_lstm to baseline)
        )
        self.g_size = g_size
        self.n_step = n_step
        self.scale = scale
        self.var = var

        self.train = True
        self.n_class = n_class
        self.active_learn = False
示例#6
0
    def __init__(self,
                 input_dim,
                 output_dim,
                 hidden_units,
                 w_scale=0.01,
                 activation='relu'):
        """
        Creates a basic recurrent NN.
        :param input_dim: type int, the dimension of input
        :param output_dim: type int, the dimension of output
        :param hidden_units: type int, the dimension of hidden layers
        :param w_scale: type float, the scale used to initialize the weights, look
        at Chainer initialization
        :param activation: type str, the activation used in network
        """
        super(RecNN,
              self).__init__(input_layer=links.Linear(input_dim,
                                                      hidden_units,
                                                      wscale=w_scale,
                                                      bias=initial_bias),
                             mid_rec_layer=links.LSTM(hidden_units,
                                                      hidden_units,
                                                      forget_bias_init=0.,
                                                      lateral_init=w_scale,
                                                      upward_init=w_scale),
                             output_layer=links.Linear(hidden_units,
                                                       output_dim,
                                                       wscale=w_scale))

        self.lstm_c = self['mid_rec_layer'].c
        self.lstm_h = self['mid_rec_layer'].h
        logger.log(msg='Initialized network {}.'.format(
            self.__class__.__name__),
                   level=logging.INFO)
        self.activation = getattr(fun, activation)
示例#7
0
 def __init__(self, image_feature_number, word_length, hidden_num):
     super(ImageCaptionGenerator, self).__init__(
         image_vec=L.Linear(image_feature_number, hidden_num),
         word_vec=L.EmbedID(word_length, hidden_num),
         lstm=L.LSTM(hidden_num, hidden_num),
         output=L.Linear(hidden_num, word_length)
     )
示例#8
0
 def __init__(self, n_hid, rnn_size):  # 44*44, 1096
     super().__init__(
         image_attention = Attention(n_hid, rnn_size),
         rev_lstm = L.LSTM(rnn_size, rnn_size),  # size of h_i is ch
     )
     self.align_source = None
     self.pre_hidden_state = None
示例#9
0
 def __init__(self, in_size, n_units, train=True):
     super(LSTM, self).__init__(
         l1=L.Linear(in_size, n_units),
         l2=L.LSTM(n_units, n_units),
         l3=L.Linear(n_units, in_size),
     )
     self.train = train
示例#10
0
    def __init__(self, imsize, conditional):
        self.imsize = imsize
        self.f = F.relu  # activation func for encoding part
        self.conditional = conditional
        super().__init__()
        with self.init_scope():
            # image encoding part
            in_channel = 2 if self.conditional else 1
            self.e1_c1 = L.Convolution2D(in_channel, 32, ksize=5)

            # action observation encoding part
            self.e1_l1_a1 = L.Linear(1, 16)
            self.e1_l1_a2 = L.Linear(1, 16)

            # convolution after concat
            self.e2_c1 = L.Convolution2D(32, 32, stride=2, ksize=4)
            self.e2_c2 = L.Convolution2D(32, 32, stride=2, ksize=4)
            self.e2_c3 = L.Convolution2D(32, 32, stride=2, ksize=4)
            self.e2_l1 = L.Linear(800, 256)

            # lstm
            self.lstm = L.LSTM(256, 256)

            # decoding part
            self.decoder = AutoregressiveDecoder(256)
示例#11
0
 def __init__(self, n_fv, n_units, n_vocab, ratio=1., train=True):
     super(RNNLM_FV_1layer, self).__init__(
         l1=L.LSTM(n_fv, n_units),
         l2=L.Linear(n_units, n_vocab),
     )
     self.train = train
     self.ratio = 1. - ratio
示例#12
0
 def __init__(self, jv, ev, k, jvocab, evocab):
     super(seq2seq, self).__init__(
         embedx = L.EmbedID(jv, k),
         embedy = L.EmbedID(ev, k),
         H = L.LSTM(k, k),
         W = L.Linear(k, ev),
         )
示例#13
0
    def __init__(self):
        super(MLP, self).__init__()

        with self.init_scope():
            self.fc1 = L.Linear(1, 5)
            self.lstm = L.LSTM(5, 5)
            self.fc2 = L.Linear(5, 1)
 def __init__(self, trial, width, height, action_size, lstm_size=128):
     obs_size = width * height
     self.head = MyHead(trial, width=width, height=height)
     self.lstm = L.LSTM(self.head.n_output_channels, lstm_size)
     self.pi = policies.FCSoftmaxPolicy(lstm_size, action_size)
     self.v = v_function.FCVFunction(lstm_size)
     super().__init__(self.head, self.lstm, self.pi, self.v)
示例#15
0
 def __init__(self, jv, ev, k):  # vocab num Japanese(jv), English(ev)
     super(MyMT, self).__init__(
         embedx=L.EmbedID(jv, k),  # k次元分散表現
         embedy=L.EmbedID(ev, k),  # k次元分散表現
         H=L.LSTM(k, k),
         W=L.Linear(k, ev),
     )
示例#16
0
    def __init__(self, n_units, n_layers):
        super(StackedLSTMLayers, self).__init__(
            *[L.LSTM(n_units, n_units) for i in range(n_layers)])
        self.add_persistent('n_layers', n_layers)

        for param in self.params():
            param.data[...] = np.random.uniform(-0.1, 0.1, param.data.shape)
示例#17
0
    def __init__(self,
                 g_size=8,
                 n_steps=6,
                 n_scales=1,
                 var=0.03,
                 use_lstm=False):
        d_glm = 128
        d_core = 256
        super(RAM, self).__init__(
            emb_l=L.Linear(2, d_glm),
            emb_x=L.Linear(g_size * g_size * n_scales, d_glm),
            fc_lg=L.Linear(d_glm, d_core),
            fc_xg=L.Linear(d_glm, d_core),
            fc_ha=L.Linear(d_core, 10),
            fc_hl=L.Linear(d_core, 2),
            fc_hb=L.Linear(d_core, 1),
        )

        if use_lstm:
            self.add_link(name='core_lstm', link=L.LSTM(d_core, d_core))
        else:
            self.add_link(name='core_hh', link=L.Linear(d_core, d_core))
            self.add_link(name='core_gh', link=L.Linear(d_core, d_core))

        self.use_lstm = use_lstm
        self.d_core = d_core
        self.g_size = g_size
        self.n_steps = n_steps
        self.n_scales = n_scales
        self.var = var
示例#18
0
 def __init__(self, input_num, action_num):
     print("DRQN Model", input_num, action_num)
     super(DRQN, self).__init__(
         fc1=L.Linear(input_num, 256),
         lstm=L.LSTM(256, 256),
         fc2=L.Linear(256, action_num),
     )
示例#19
0
 def __init__(self, n_units, n_out, train=True):
     super(MLP, self).__init__()
     with self.init_scope():
         # the size of the inputs to each layer will be inferred
         self.l1 = L.LSTM(None, n_units, lateral_init=chainer.initializers.Normal(scale=0.01))  # n_in -> n_units
         self.l2 = L.Linear(None, n_out, initialW=chainer.initializers.Normal(scale=0.01))  # n_units -> n_ou
         self.train = train
示例#20
0
 def __init__(self, j_numvocab, e_vocab, dim):
     super(MyMT, self).__init__(
         embedx=L.EmbedID(j_numvocab, dim),  # jp input-x
         embedy=L.EmbedID(e_numvocab, dim),  # eng input-y
         H=L.LSTM(dim, dim),  # LSTM output (recurrent part)
         W=L.Linear(dim, e_numvocab)  # Total output
     )
示例#21
0
 def __init__(self, n_units, gpu):
     super(NSE, self).__init__(read_lstm=L.LSTM(n_units, n_units),
                               write_lstm=L.LSTM(2 * n_units, n_units),
                               compose_l1=F.Linear(2 * n_units,
                                                   2 * n_units),
                               h_l1=F.Linear(4 * n_units, 1024),
                               l_y=F.Linear(1024, 3))
     self.__n_units = n_units
     self.__gpu = gpu
     self.__mod = cuda.cupy if gpu >= 0 else np
     for param in self.params():
         data = param.data
         data[:] = np.random.uniform(-0.1, 0.1, data.shape)
     if gpu >= 0:
         cuda.get_device(gpu).use()
         self.to_gpu()
示例#22
0
 def __init__(self, in_size, hidden_size, hidden2_size, out_size):
     super(LSTM, self).__init__(
         xh=L.EmbedID(in_size, hidden_size),
         hh=L.LSTM(hidden_size, hidden2_size),
         hh2=L.Linear(hidden2_size, hidden2_size),
         hy=L.Linear(hidden2_size, out_size),
     )
 def __init__(self, vocab_size, embed_size, hidden_size, out_size):
     super(LSTM_SentenceClassifier,
           self).__init__(xe=L.EmbedID(vocab_size,
                                       embed_size,
                                       ignore_label=-1),
                          eh=L.LSTM(embed_size, hidden_size),
                          hy=L.Linear(hidden_size * 2, out_size))
示例#24
0
    def __init__(self, dropout_ratio, num_timesteps, zoom=0.9):
        super(SVHNLocalizationNet, self).__init__()
        with self.init_scope():
            self.conv0 = L.Convolution2D(None, 32, 3, pad=1)
            self.bn0 = L.BatchNormalization(32)
            self.rs1 = ResnetBlock(32)
            self.rs2 = ResnetBlock(48, filter_increase=True)
            self.rs3 = ResnetBlock(48)
            self.lstm = L.LSTM(None, 256)
            self.transform_2 = L.Linear(256, 6)

        # initialize transform
        self.transform_2.W.data[...] = 0

        transform_bias = self.transform_2.b.data
        transform_bias[[0, 4]] = zoom
        transform_bias[[2, 5]] = 0

        self.dropout_ratio = dropout_ratio
        self._train = True
        self.num_timesteps = num_timesteps
        self.vis_anchor = None

        self.width_encoding = None
        self.height_encoding = None
示例#25
0
 def __init__(self, in_units=1, hidden_units=2, out_units=1, train=True):
     super(LSTM, self).__init__(
         l1=L.Linear(in_units, hidden_units),
         l2=L.LSTM(hidden_units, hidden_units),
         l3=L.Linear(hidden_units, out_units),
     )
     self.train = True
示例#26
0
 def __init__(self, i_size, h_size, o_size, train):
     self.train = train
     super(Model_Atr, self).__init__(
         i_h=L.Linear(i_size, h_size),
         h_h=L.LSTM(h_size, h_size),
         h_o=L.Linear(h_size, o_size),
     )
 def __init__(self, jv, ev, k):
     super(MyMT, self).__init__(
         embedx=L.EmbedID(jv, k),
         embedy=L.EmbedID(ev, k),
         H=L.LSTM(k, k),  # LSTM output -> history
         W=L.Linear(k, ev)  # total output
     )
示例#28
0
    def __init__(self,
                 deep,
                 gpu,
                 word2index,
                 in_units,
                 hidden_units,
                 out_units,
                 loss_func,
                 train,
                 drop_ratio=0.0):
        n_vocab = len(word2index)
        # harman - modified F.EmbedID to L.EmbedID
        l2r_embedding = L.EmbedID(n_vocab, in_units)
        r2l_embedding = L.EmbedID(n_vocab, in_units)

        if deep:
            super(BiLstmContext, self).__init__(
                l2r_embed=l2r_embedding,
                r2l_embed=r2l_embedding,
                loss_func=loss_func,
                l2r_1=L.LSTM(in_units, hidden_units),
                r2l_1=L.LSTM(in_units, hidden_units),
                l3=L.Linear(2 * hidden_units, 2 * hidden_units),
                l4=L.Linear(2 * hidden_units, out_units),
            )
        else:
            super(BiLstmContext,
                  self).__init__(l2r_embed=l2r_embedding,
                                 r2l_embed=r2l_embedding,
                                 loss_func=loss_func,
                                 l2r_1=L.LSTM(in_units, hidden_units),
                                 r2l_1=L.LSTM(in_units, hidden_units),
                                 lp_l2r=L.Linear(hidden_units, out_units / 2),
                                 lp_r2l=L.Linear(hidden_units, out_units / 2))
        if gpu >= 0:
            self.to_gpu()
        l2r_embedding.W.data = self.xp.random.normal(
            0, math.sqrt(1. / l2r_embedding.W.data.shape[0]),
            l2r_embedding.W.data.shape).astype(np.float32)
        r2l_embedding.W.data = self.xp.random.normal(
            0, math.sqrt(1. / r2l_embedding.W.data.shape[0]),
            r2l_embedding.W.data.shape).astype(np.float32)

        self.word2index = word2index
        self.train = chainer.using_config('train', train)
        self.deep = deep
        self.drop_ratio = drop_ratio
示例#29
0
    def __init__(self, n_units=256, n_out=0, img_size=112, var=0.18, n_step=2, gpu_id=-1):
        super(BASE, self).__init__(
            # the size of the inputs to each layer will be inferred
            # glimpse network
            # 切り取られた画像を処理する部分 位置情報 (glimpse loc)と画像特徴量の積を出力
            glimpse_cnn_1=L.Convolution2D(1, 8, 5),  # in 28 out 24
            glimpse_cnn_2=L.Convolution2D(8, 32, 5),  # in 24 out 20
            glimpse_cnn_3=L.Convolution2D(32, 64, 5),  # in 20 pool 10 out 6
            glimpse_full=L.Linear(8 * 8 * 64, n_units),
            glimpse_loc=L.Linear(2, n_units),

            # baseline network 強化学習の期待値を学習し、バイアスbとする
            baseline=L.Linear(n_units, 1),

            # 記憶を用いるLSTM部分
            rnn_1=L.LSTM(n_units, n_units),
            rnn_2=L.LSTM(n_units, n_units),

            # 注意領域を選択するネットワーク
            attention_loc=L.Linear(n_units, 2),

            # 入力画像を処理するネットワーク
            context_cnn_1=L.Convolution2D(1, 4, 5),  # 56 to 52 pooling: 26
            context_cnn_2=L.Convolution2D(4, 4, 5),  # 26 to 22 pooling
            context_cnn_3=L.Convolution2D(4, 4, 4),  # 22 to 16

            class_full=L.Linear(n_units, n_out)
        )

        #
        # img parameter
        #
        if gpu_id == 0:
            self.use_gpu = True
        else:
            self.use_gpu = False
        self.img_size = img_size
        self.gsize = 32
        self.train = True
        self.var = var
        self.vars = var
        self.n_unit = n_units
        self.num_class = n_out
        # r determine the rate of position
        self.r = 0.5
        self.r_recognize = 1.0
        self.n_step = n_step
 def __init__(self, n_actions):
     self.head = links.NIPSDQNHead()
     self.pi = policy.FCSoftmaxPolicy(self.head.n_output_channels,
                                      n_actions)
     self.v = v_function.FCVFunction(self.head.n_output_channels)
     self.lstm = L.LSTM(self.head.n_output_channels,
                        self.head.n_output_channels)
     super().__init__(self.head, self.lstm, self.pi, self.v)