當前位置: 首頁>>代碼示例>>Python>>正文


Python utils.conv方法代碼示例

本文整理匯總了Python中baselines.a2c.utils.conv方法的典型用法代碼示例。如果您正苦於以下問題:Python utils.conv方法的具體用法?Python utils.conv怎麽用?Python utils.conv使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在baselines.a2c.utils的用法示例。


在下文中一共展示了utils.conv方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: nature_cnn

# 需要導入模塊: from baselines.a2c import utils [as 別名]
# 或者: from baselines.a2c.utils import conv [as 別名]
def nature_cnn(unscaled_images):
    """
    CNN from Nature paper.
    """
    scaled_images = tf.cast(unscaled_images, tf.float32) / 255.
    activ = tf.nn.relu
    h = activ(conv(scaled_images, 'c1', nf=32, rf=8, stride=4, init_scale=np.sqrt(2)))
    h2 = activ(conv(h, 'c2', nf=64, rf=4, stride=2, init_scale=np.sqrt(2)))
    h3 = activ(conv(h2, 'c3', nf=64, rf=3, stride=1, init_scale=np.sqrt(2)))
    h3 = conv_to_fc(h3)
    return activ(fc(h3, 'fc1', nh=512, init_scale=np.sqrt(2))) 
開發者ID:Hwhitetooth,項目名稱:lirpg,代碼行數:13,代碼來源:policies.py

示例2: nature_cnn

# 需要導入模塊: from baselines.a2c import utils [as 別名]
# 或者: from baselines.a2c.utils import conv [as 別名]
def nature_cnn(unscaled_images, **conv_kwargs):
    """
    CNN from Nature paper.
    """
    scaled_images = tf.cast(unscaled_images, tf.float32) / 255.
    activ = tf.nn.relu
    h = activ(conv(scaled_images, 'c1', nf=32, rf=8, stride=4, init_scale=np.sqrt(2),
                   **conv_kwargs))
    h2 = activ(conv(h, 'c2', nf=64, rf=4, stride=2, init_scale=np.sqrt(2), **conv_kwargs))
    h3 = activ(conv(h2, 'c3', nf=64, rf=3, stride=1, init_scale=np.sqrt(2), **conv_kwargs))
    h3 = conv_to_fc(h3)
    return activ(fc(h3, 'fc1', nh=512, init_scale=np.sqrt(2))) 
開發者ID:MaxSobolMark,項目名稱:HardRLWithYoutube,代碼行數:14,代碼來源:models.py

示例3: cnn_small

# 需要導入模塊: from baselines.a2c import utils [as 別名]
# 或者: from baselines.a2c.utils import conv [as 別名]
def cnn_small(**conv_kwargs):
    def network_fn(X):
        h = tf.cast(X, tf.float32) / 255.
        
        activ = tf.nn.relu
        h = activ(conv(h, 'c1', nf=8, rf=8, stride=4, init_scale=np.sqrt(2), **conv_kwargs))
        h = activ(conv(h, 'c2', nf=16, rf=4, stride=2, init_scale=np.sqrt(2), **conv_kwargs))
        h = conv_to_fc(h)
        h = activ(fc(h, 'fc1', nh=128, init_scale=np.sqrt(2)))
        return h, None
    return network_fn 
開發者ID:MaxSobolMark,項目名稱:HardRLWithYoutube,代碼行數:13,代碼來源:models.py

示例4: conv_only

# 需要導入模塊: from baselines.a2c import utils [as 別名]
# 或者: from baselines.a2c.utils import conv [as 別名]
def conv_only(convs=[(32, 8, 4), (64, 4, 2), (64, 3, 1)], **conv_kwargs):
    ''' 
    convolutions-only net

    Parameters:
    ----------

    conv:       list of triples (filter_number, filter_size, stride) specifying parameters for each layer. 

    Returns:

    function that takes tensorflow tensor as input and returns the output of the last convolutional layer
    
    '''

    def network_fn(X):
        out = tf.cast(X, tf.float32) / 255.
        with tf.variable_scope("convnet"):
            for num_outputs, kernel_size, stride in convs:
                out = layers.convolution2d(out,
                                           num_outputs=num_outputs,
                                           kernel_size=kernel_size,
                                           stride=stride,
                                           activation_fn=tf.nn.relu,
                                           **conv_kwargs)

        return out, None
    return network_fn 
開發者ID:MaxSobolMark,項目名稱:HardRLWithYoutube,代碼行數:30,代碼來源:models.py

示例5: cnn_small

# 需要導入模塊: from baselines.a2c import utils [as 別名]
# 或者: from baselines.a2c.utils import conv [as 別名]
def cnn_small(**conv_kwargs):
    def network_fn(X):
        h = tf.cast(X, tf.float32) / 255.

        activ = tf.nn.relu
        h = activ(conv(h, 'c1', nf=8, rf=8, stride=4, init_scale=np.sqrt(2), **conv_kwargs))
        h = activ(conv(h, 'c2', nf=16, rf=4, stride=2, init_scale=np.sqrt(2), **conv_kwargs))
        h = conv_to_fc(h)
        h = activ(fc(h, 'fc1', nh=128, init_scale=np.sqrt(2)))
        return h
    return network_fn 
開發者ID:hiwonjoon,項目名稱:ICML2019-TREX,代碼行數:13,代碼來源:models.py

示例6: conv_only

# 需要導入模塊: from baselines.a2c import utils [as 別名]
# 或者: from baselines.a2c.utils import conv [as 別名]
def conv_only(convs=[(32, 8, 4), (64, 4, 2), (64, 3, 1)], **conv_kwargs):
    '''
    convolutions-only net

    Parameters:
    ----------

    conv:       list of triples (filter_number, filter_size, stride) specifying parameters for each layer.

    Returns:

    function that takes tensorflow tensor as input and returns the output of the last convolutional layer

    '''

    def network_fn(X):
        out = tf.cast(X, tf.float32) / 255.
        with tf.variable_scope("convnet"):
            for num_outputs, kernel_size, stride in convs:
                out = layers.convolution2d(out,
                                           num_outputs=num_outputs,
                                           kernel_size=kernel_size,
                                           stride=stride,
                                           activation_fn=tf.nn.relu,
                                           **conv_kwargs)

        return out
    return network_fn 
開發者ID:hiwonjoon,項目名稱:ICML2019-TREX,代碼行數:30,代碼來源:models.py

示例7: nature_cnn_h3

# 需要導入模塊: from baselines.a2c import utils [as 別名]
# 或者: from baselines.a2c.utils import conv [as 別名]
def nature_cnn_h3(unscaled_images, first_layer_mode='', trainable=True, conv1_fn=lambda x: x):
    """
    CNN from Nature paper.
    """
    scaled_images = tf.cast(unscaled_images, tf.float32) / 255.
    activ = tf.nn.relu

    print("scaled_images: {}".format(scaled_images))

    if first_layer_mode == 'Share':
        assert False
        # input_activations = []
        # for start in range(3):
        #     input_images = scaled_images[..., start:start+2]
        #     assert input_images.get_shape()[-1] == 2 # Should be a pair of frames.

        #     h = activ(conv(input_images, 'c1_2_frame_input', nf=32, rf=8, stride=4, init_scale=np.sqrt(2), reuse=start!=0, trainable=trainable))
        #     input_activations.append(h)

        # assert len(input_activations) == 3 # Should have 3 pairs of frames.
        # h = (1. / 3.) * tf.add_n(input_activations, name='c1') # Average the activations of the three pairs of frames.

    elif first_layer_mode == '2Frame':
        input_images = scaled_images[..., -2:]
        assert input_images.get_shape()[-1] == 2 # Should be a pair of frames.
        h = activ(conv(input_images, 'c1_2_frame_input', nf=32, rf=8, stride=4, init_scale=np.sqrt(2), trainable=trainable))

    else:
        assert False
        # scaled_images = scaled_images[..., -2:]
        # print("scaled_images: {}".format(scaled_images))

        # h = activ(conv(scaled_images, 'c1', nf=32, rf=8, stride=4, init_scale=np.sqrt(2), trainable=trainable))

        # print('scaled_images: {}'.format(scaled_images.get_shape()))

    h = conv1_fn(h)
    h2 = activ(conv(h, 'c2', nf=64, rf=4, stride=2, init_scale=np.sqrt(2), trainable=trainable))
    _h3 = conv(h2, 'c3', nf=64, rf=3, stride=1, init_scale=np.sqrt(2), trainable=trainable)
    h3 = activ(_h3)
    return h3, _h3 
開發者ID:vik-goel,項目名稱:MOREL,代碼行數:43,代碼來源:policies.py

示例8: conv_only

# 需要導入模塊: from baselines.a2c import utils [as 別名]
# 或者: from baselines.a2c.utils import conv [as 別名]
def conv_only(convs=[(32, 8, 4), (64, 4, 2), (64, 3, 1)], **conv_kwargs):
    '''
    convolutions-only net

    Parameters:
    ----------

    conv:       list of triples (filter_number, filter_size, stride) specifying parameters for each layer.

    Returns:

    function that takes tensorflow tensor as input and returns the output of the last convolutional layer

    '''

    def network_fn(X):
        out = tf.cast(X, tf.float32) / 255.
        with tf.variable_scope("convnet"):
            for num_outputs, kernel_size, stride in convs:
                out = tf.contrib.layers.convolution2d(out,
                                           num_outputs=num_outputs,
                                           kernel_size=kernel_size,
                                           stride=stride,
                                           activation_fn=tf.nn.relu,
                                           **conv_kwargs)

        return out
    return network_fn 
開發者ID:openai,項目名稱:baselines,代碼行數:30,代碼來源:models.py

示例9: __init__

# 需要導入模塊: from baselines.a2c import utils [as 別名]
# 或者: from baselines.a2c.utils import conv [as 別名]
def __init__(self, sess, ob_space, ac_space, nenv, nsteps, nstack, nlstm=256, reuse=False):
        nbatch = nenv*nsteps
        nh, nw, nc = ob_space.shape
        ob_shape = (nbatch, nh, nw, nc*nstack)
        nact = ac_space.n
        X = tf.placeholder(tf.uint8, ob_shape) #obs
        M = tf.placeholder(tf.float32, [nbatch]) #mask (done t-1)
        S = tf.placeholder(tf.float32, [nenv, nlstm*2]) #states
        with tf.variable_scope("model", reuse=reuse):
            h = conv(tf.cast(X, tf.float32)/255., 'c1', nf=32, rf=8, stride=4, init_scale=np.sqrt(2))
            h2 = conv(h, 'c2', nf=64, rf=4, stride=2, init_scale=np.sqrt(2))
            h3 = conv(h2, 'c3', nf=64, rf=3, stride=1, init_scale=np.sqrt(2))
            h3 = conv_to_fc(h3)
            h4 = fc(h3, 'fc1', nh=512, init_scale=np.sqrt(2))
            xs = batch_to_seq(h4, nenv, nsteps)
            ms = batch_to_seq(M, nenv, nsteps)
            h5, snew = lnlstm(xs, ms, S, 'lstm1', nh=nlstm)
            h5 = seq_to_batch(h5)
            pi = fc(h5, 'pi', nact, act=lambda x:x)
            vf = fc(h5, 'v', 1, act=lambda x:x)

        v0 = vf[:, 0]
        a0 = sample(pi)
        self.initial_state = np.zeros((nenv, nlstm*2), dtype=np.float32)

        def step(ob, state, mask):
            a, v, s = sess.run([a0, v0, snew], {X:ob, S:state, M:mask})
            return a, v, s

        def value(ob, state, mask):
            return sess.run(v0, {X:ob, S:state, M:mask})

        self.X = X
        self.M = M
        self.S = S
        self.pi = pi
        self.vf = vf
        self.step = step
        self.value = value 
開發者ID:cxxgtxy,項目名稱:deeprl-baselines,代碼行數:41,代碼來源:policies.py

示例10: __init__

# 需要導入模塊: from baselines.a2c import utils [as 別名]
# 或者: from baselines.a2c.utils import conv [as 別名]
def __init__(self, sess, ob_space, ac_space, nenv, nsteps, nstack, reuse=False):
        nbatch = nenv * nsteps
        nh, nw, nc = ob_space.shape
        ob_shape = (nbatch, nh, nw, nc * nstack)
        nact = ac_space.n
        X = tf.placeholder(tf.uint8, ob_shape)  # obs
        with tf.variable_scope("model", reuse=reuse):
            h = conv(tf.cast(X, tf.float32) / 255., 'c1', nf=32, rf=8, stride=4, init_scale=np.sqrt(2))
            h2 = conv(h, 'c2', nf=64, rf=4, stride=2, init_scale=np.sqrt(2))
            h3 = conv(h2, 'c3', nf=64, rf=3, stride=1, init_scale=np.sqrt(2))
            h3 = conv_to_fc(h3)
            h4 = fc(h3, 'fc1', nh=512, init_scale=np.sqrt(2))
            pi_logits = fc(h4, 'pi', nact, act=lambda x: x, init_scale=0.01)
            pi = tf.nn.softmax(pi_logits)
            q = fc(h4, 'q', nact, act=lambda x: x)

        a = sample(pi_logits)  # could change this to use self.pi instead
        self.initial_state = []  # not stateful
        self.X = X
        self.pi = pi  # actual policy params now
        self.q = q

        def step(ob, *args, **kwargs):
            # returns actions, mus, states
            a0, pi0 = sess.run([a, pi], {X: ob})
            return a0, pi0, []  # dummy state

        def out(ob, *args, **kwargs):
            pi0, q0 = sess.run([pi, q], {X: ob})
            return pi0, q0

        def act(ob, *args, **kwargs):
            return sess.run(a, {X: ob})

        self.step = step
        self.out = out
        self.act = act 
開發者ID:cxxgtxy,項目名稱:deeprl-baselines,代碼行數:39,代碼來源:policies.py


注:本文中的baselines.a2c.utils.conv方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。