【问题标题】:How does UpSampling2D layer work in Keras?UpSampling2D 层在 Keras 中是如何工作的?
【发布时间】:2019-10-15 06:20:25
【问题描述】:

UpSampling2D 层在 Keras 中是如何工作的?根据official documentation

分别以size[0]size[1] 重复数据的行和列。

那么,如果size=(2, 2),它如何重复输入矩阵的行和列呢?可以举例说明一下流程吗?

【问题讨论】:

    标签: python keras deep-learning keras-layer


    【解决方案1】:

    如果

    分别以size[0]size[1] 重复数据的行和列。

    没有帮助,那么举个例子可能会有所帮助:

    >>> import numpy as np
    >>> from keras.layers import UpSampling2D
    >>> from keras.models import Sequential
    >>> model = Sequential()
    >>> model.add(UpSampling2D(size=(2,2), input_shape=(3,3,1)))
    
    >>> x = np.arange(9).reshape(1,3,3,1)
    >>> x[0,:,:,0]  # this is what x looks like initially
    array([[0, 1, 2],
           [3, 4, 5],
           [6, 7, 8]])
    >>> y = model.predict(x)
    >>> y[0,:,:,0] # this is what it looks like after upsampling
    array([[0., 0., 1., 1., 2., 2.],
           [0., 0., 1., 1., 2., 2.],
           [3., 3., 4., 4., 5., 5.],
           [3., 3., 4., 4., 5., 5.],
           [6., 6., 7., 7., 8., 8.],
           [6., 6., 7., 7., 8., 8.]], dtype=float32) 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-11-25
      • 2017-10-25
      • 1970-01-01
      • 2018-05-09
      • 1970-01-01
      • 1970-01-01
      • 2017-08-03
      相关资源
      最近更新 更多