mcmc_sampler.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:bnn-analysis 作者: myshkov 项目源码 文件源码
def model_from_position(cls, layer_descriptions, position_tensor, input_tensor, use_softmax=False):
        """ Creates TF model from the specified position and description. """
        offset = 0
        model = input_tensor

        for i in range(1, len(layer_descriptions)):
            previous_layer = layer_descriptions[i - 1]
            current_layer = layer_descriptions[i]

            previous_layer_size = previous_layer[0]
            current_layer_size = current_layer[0]

            weights_size = previous_layer_size * current_layer_size
            biases_size = current_layer_size

            weights = tf.slice(position_tensor, [0, offset], [1, weights_size])
            weights = tf.reshape(weights, shape=[previous_layer_size, current_layer_size])
            offset += weights_size

            biases = tf.slice(position_tensor, [0, offset], [1, biases_size])
            biases = tf.reshape(biases, shape=[1, biases_size])
            offset += biases_size

            model = tf.matmul(model, weights) + biases

            if i != len(layer_descriptions) - 1:
                model = tf.nn.relu(model)
            elif use_softmax and layer_descriptions[-1][0] > 1:
                model = tf.nn.softmax(model)

        return model
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号