python类reshape()的实例源码

train_catastrophe_model_human.py 文件源码 项目:human-rl 作者: gsastry 项目源码 文件源码 阅读 47 收藏 0 点赞 0 评论 0
def model(self, features, labels):
        x = features["observation"]
        x = tf.contrib.layers.convolution2d(x, 2, kernel_size=[3, 3], stride=[2, 2], activation_fn=tf.nn.elu)
        x = tf.contrib.layers.convolution2d(x, 2, kernel_size=[3, 3], stride=[2, 2], activation_fn=tf.nn.elu)
        actions = tf.one_hot(tf.reshape(features["action"],[-1]), depth=6, on_value=1.0, off_value=0.0, axis=1)
        x = tf.concat(1, [tf.contrib.layers.flatten(x),  actions])
        x = tf.contrib.layers.fully_connected(x, 100, activation_fn=tf.nn.elu)
        x = tf.contrib.layers.fully_connected(x, 100, activation_fn=tf.nn.elu)
        logits = tf.contrib.layers.fully_connected(x, 1, activation_fn=None)
        prediction = tf.sigmoid(logits, name="prediction")
        loss = tf.reduce_mean(tf.nn.sigmoid_cross_entropy_with_logits(logits, tf.expand_dims(labels, axis=1)),name="loss")
        train_op = tf.contrib.layers.optimize_loss(
          loss, tf.contrib.framework.get_global_step(), optimizer='Adam',
          learning_rate=self.learning_rate)
        tf.add_to_collection('prediction', prediction)
        tf.add_to_collection('loss', loss)
        return prediction, loss, train_op
__init__.py 文件源码 项目:a-nice-mc 作者: ermongroup 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def visualize(self, zv, path):
        self.ax1.clear()
        self.ax2.clear()
        z, v = zv
        if path:
            np.save(path + '/trajectory.npy', z)

        z = np.reshape(z, [-1, 2])
        self.ax1.hist2d(z[:, 0], z[:, 1], bins=400)
        self.ax1.set(xlim=self.xlim(), ylim=self.ylim())

        v = np.reshape(v, [-1, 2])
        self.ax2.hist2d(v[:, 0], v[:, 1], bins=400)
        self.ax2.set(xlim=self.xlim(), ylim=self.ylim())

        if self.display:
            import matplotlib.pyplot as plt
            plt.show()
            plt.pause(0.1)
        elif path:
            self.fig.savefig(path + '/visualize.png')
dense_lstm_test.py 文件源码 项目:DeepAnomaly 作者: adiyoss 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def test(path_test, input_size, hidden_size, batch_size, save_dir, model_name, maxlen):
    db = read_data(path_test)

    X = create_sequences(db[:-maxlen], win_size=maxlen, step=maxlen)
    X = np.reshape(X, (X.shape[0], X.shape[1], input_size))

    # build the model: 1 layer LSTM
    print('Build model...')
    model = Sequential()
    model.add(LSTM(hidden_size, return_sequences=False, input_shape=(maxlen, input_size)))
    model.add(Dense(maxlen))

    model.load_weights(save_dir + model_name)
    model.compile(loss='mse', optimizer='adam')

    prediction = model.predict(X, batch_size, verbose=1)
    prediction = prediction.flatten()
    # prediction_container = np.array(prediction).flatten()
    Y = db[maxlen:]
    plt.plot(prediction, label='prediction')
    plt.plot(Y, label='true')
    plt.legend()
    plt.show()
fit_unet_d8g_222_swrap_10.py 文件源码 项目:kaggle_dsb2017 作者: astoc 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def data_from_grid (cells, gridwidth, gridheight, grid=32):

    width = cells.shape[4]
    crop = (width - grid ) // 2 ## for simplicity we are assuming the same crop (and grid) in x & y directions 

    if crop > 0:  # do NOT crop with 0 as we get empty cells ...
        cells = cells[:,:,:,crop:-crop,crop:-crop]     

    shape = cells.shape
    new_shape_1_dim = shape[0]// (gridwidth * gridheight)  # ws // 36 -- Improved on 20170306
    new_shape = (gridwidth * gridheight, new_shape_1_dim, ) +  tuple([x for x in shape][1:])   # was 36,  Improved on 20170306
    cells = np.reshape(cells, new_shape)  
    cells = np.moveaxis(cells, 0, -3)

    shape = cells.shape
    new_shape2 = tuple([x for x in shape[0:3]]) + (gridheight, gridwidth,) + tuple([x for x in shape[4:]])
    cells = np.reshape(cells, new_shape2)
    cells = cells.swapaxes(-2, -3)
    shape = cells.shape
    combine_shape =tuple([x for x in shape[0:3]]) + (shape[-4]*shape[-3], shape[-2]*shape[-1],)
    cells = np.reshape(cells, combine_shape)

    return cells
fit_unet_d8g_222_swrap_10.py 文件源码 项目:kaggle_dsb2017 作者: astoc 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def data_from_grid_by_proximity (cells, gridwidth, gridheight, grid=32):

    # disperse the sequential dats into layers and then use data_from_grid
    shape = cells.shape
    new_shape_1_dim = shape[0]// (gridwidth * gridheight)  # ws // 36 -- Improved on 20170306


    ### NOTE tha we invert the order of shapes below to get the required proximity type ordering
    new_shape = (new_shape_1_dim, gridwidth * gridheight,  ) +  tuple([x for x in shape][1:])   # was 36,  Improved on 20170306
    #new_shape = (gridwidth * gridheight, new_shape_1_dim, ) +  tuple([x for x in shape][1:])   # was 36,  Improved on 20170306

    # swap ordering of axes 
    cells = np.reshape(cells, new_shape) 
    cells = cells.swapaxes(0, 1)
    cells = np.reshape(cells, shape) 

    cells = data_from_grid (cells, gridwidth, gridheight, grid)

    return cells
fit_unet_d8g_222_swrap_02.py 文件源码 项目:kaggle_dsb2017 作者: astoc 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def data_from_grid (cells, gridwidth, gridheight, grid=32):

    width = cells.shape[4]
    crop = (width - grid ) // 2 ## for simplicity we are assuming the same crop (and grid) in x & y directions 

    if crop > 0:  # do NOT crop with 0 as we get empty cells ...
        cells = cells[:,:,:,crop:-crop,crop:-crop]     

    shape = cells.shape
    new_shape_1_dim = shape[0]// (gridwidth * gridheight)  # ws // 36 -- Improved on 20170306
    new_shape = (gridwidth * gridheight, new_shape_1_dim, ) +  tuple([x for x in shape][1:])   # was 36,  Improved on 20170306
    cells = np.reshape(cells, new_shape)  
    cells = np.moveaxis(cells, 0, -3)

    shape = cells.shape
    new_shape2 = tuple([x for x in shape[0:3]]) + (gridheight, gridwidth,) + tuple([x for x in shape[4:]])
    cells = np.reshape(cells, new_shape2)
    cells = cells.swapaxes(-2, -3)
    shape = cells.shape
    combine_shape =tuple([x for x in shape[0:3]]) + (shape[-4]*shape[-3], shape[-2]*shape[-1],)
    cells = np.reshape(cells, combine_shape)

    return cells
fit_unet_d8g_222_swrap_02.py 文件源码 项目:kaggle_dsb2017 作者: astoc 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def data_from_grid_by_proximity (cells, gridwidth, gridheight, grid=32):

    # disperse the sequential dats into layers and then use data_from_grid
    shape = cells.shape
    new_shape_1_dim = shape[0]// (gridwidth * gridheight)  # ws // 36 -- Improved on 20170306


    ### NOTE tha we invert the order of shapes below to get the required proximity type ordering
    new_shape = (new_shape_1_dim, gridwidth * gridheight,  ) +  tuple([x for x in shape][1:])   # was 36,  Improved on 20170306
    #new_shape = (gridwidth * gridheight, new_shape_1_dim, ) +  tuple([x for x in shape][1:])   # was 36,  Improved on 20170306

    # swap ordering of axes 
    cells = np.reshape(cells, new_shape) 
    cells = cells.swapaxes(0, 1)
    cells = np.reshape(cells, shape) 

    cells = data_from_grid (cells, gridwidth, gridheight, grid)

    return cells
refit_unet_d8g_222_swrap_07.py 文件源码 项目:kaggle_dsb2017 作者: astoc 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def data_from_grid (cells, gridwidth, gridheight, grid=32):

    width = cells.shape[4]
    crop = (width - grid ) // 2 ## for simplicity we are assuming the same crop (and grid) in x & y directions 

    if crop > 0:  # do NOT crop with 0 as we get empty cells ...
        cells = cells[:,:,:,crop:-crop,crop:-crop]     

    shape = cells.shape
    new_shape_1_dim = shape[0]// (gridwidth * gridheight)  # ws // 36 -- Improved on 20170306
    new_shape = (gridwidth * gridheight, new_shape_1_dim, ) +  tuple([x for x in shape][1:])   # was 36,  Improved on 20170306
    cells = np.reshape(cells, new_shape)  
    cells = np.moveaxis(cells, 0, -3)

    shape = cells.shape
    new_shape2 = tuple([x for x in shape[0:3]]) + (gridheight, gridwidth,) + tuple([x for x in shape[4:]])
    cells = np.reshape(cells, new_shape2)
    cells = cells.swapaxes(-2, -3)
    shape = cells.shape
    combine_shape =tuple([x for x in shape[0:3]]) + (shape[-4]*shape[-3], shape[-2]*shape[-1],)
    cells = np.reshape(cells, combine_shape)

    return cells
refit_unet_d8g_222_swrap_11.py 文件源码 项目:kaggle_dsb2017 作者: astoc 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def data_from_grid (cells, gridwidth, gridheight, grid=32):

    width = cells.shape[4]
    crop = (width - grid ) // 2 ## for simplicity we are assuming the same crop (and grid) in x & y directions 

    if crop > 0:  # do NOT crop with 0 as we get empty cells ...
        cells = cells[:,:,:,crop:-crop,crop:-crop]     

    shape = cells.shape
    new_shape_1_dim = shape[0]// (gridwidth * gridheight)  # ws // 36 -- Improved on 20170306
    new_shape = (gridwidth * gridheight, new_shape_1_dim, ) +  tuple([x for x in shape][1:])   # was 36,  Improved on 20170306
    cells = np.reshape(cells, new_shape)  
    cells = np.moveaxis(cells, 0, -3)

    shape = cells.shape
    new_shape2 = tuple([x for x in shape[0:3]]) + (gridheight, gridwidth,) + tuple([x for x in shape[4:]])
    cells = np.reshape(cells, new_shape2)
    cells = cells.swapaxes(-2, -3)
    shape = cells.shape
    combine_shape =tuple([x for x in shape[0:3]]) + (shape[-4]*shape[-3], shape[-2]*shape[-1],)
    cells = np.reshape(cells, combine_shape)

    return cells
refit_unet_d8g_222_swrap_11.py 文件源码 项目:kaggle_dsb2017 作者: astoc 项目源码 文件源码 阅读 36 收藏 0 点赞 0 评论 0
def data_from_grid_by_proximity (cells, gridwidth, gridheight, grid=32):

    # disperse the sequential dats into layers and then use data_from_grid
    shape = cells.shape
    new_shape_1_dim = shape[0]// (gridwidth * gridheight)  # ws // 36 -- Improved on 20170306


    ### NOTE tha we invert the order of shapes below to get the required proximity type ordering
    new_shape = (new_shape_1_dim, gridwidth * gridheight,  ) +  tuple([x for x in shape][1:])   # was 36,  Improved on 20170306
    #new_shape = (gridwidth * gridheight, new_shape_1_dim, ) +  tuple([x for x in shape][1:])   # was 36,  Improved on 20170306

    # swap ordering of axes 
    cells = np.reshape(cells, new_shape) 
    cells = cells.swapaxes(0, 1)
    cells = np.reshape(cells, shape) 

    cells = data_from_grid (cells, gridwidth, gridheight, grid)

    return cells
fit_unet_d8g_222_swrap_09.py 文件源码 项目:kaggle_dsb2017 作者: astoc 项目源码 文件源码 阅读 36 收藏 0 点赞 0 评论 0
def data_from_grid (cells, gridwidth, gridheight, grid=32):

    width = cells.shape[4]
    crop = (width - grid ) // 2 ## for simplicity we are assuming the same crop (and grid) in x & y directions 

    if crop > 0:  # do NOT crop with 0 as we get empty cells ...
        cells = cells[:,:,:,crop:-crop,crop:-crop]     

    shape = cells.shape
    new_shape_1_dim = shape[0]// (gridwidth * gridheight)  # ws // 36 -- Improved on 20170306
    new_shape = (gridwidth * gridheight, new_shape_1_dim, ) +  tuple([x for x in shape][1:])   # was 36,  Improved on 20170306
    cells = np.reshape(cells, new_shape)  
    cells = np.moveaxis(cells, 0, -3)

    shape = cells.shape
    new_shape2 = tuple([x for x in shape[0:3]]) + (gridheight, gridwidth,) + tuple([x for x in shape[4:]])
    cells = np.reshape(cells, new_shape2)
    cells = cells.swapaxes(-2, -3)
    shape = cells.shape
    combine_shape =tuple([x for x in shape[0:3]]) + (shape[-4]*shape[-3], shape[-2]*shape[-1],)
    cells = np.reshape(cells, combine_shape)

    return cells
fit_unet_d8g_222_swrap_09.py 文件源码 项目:kaggle_dsb2017 作者: astoc 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def data_from_grid_by_proximity (cells, gridwidth, gridheight, grid=32):

    # disperse the sequential dats into layers and then use data_from_grid
    shape = cells.shape
    new_shape_1_dim = shape[0]// (gridwidth * gridheight)  # ws // 36 -- Improved on 20170306


    ### NOTE tha we invert the order of shapes below to get the required proximity type ordering
    new_shape = (new_shape_1_dim, gridwidth * gridheight,  ) +  tuple([x for x in shape][1:])   # was 36,  Improved on 20170306
    #new_shape = (gridwidth * gridheight, new_shape_1_dim, ) +  tuple([x for x in shape][1:])   # was 36,  Improved on 20170306

    # swap ordering of axes 
    cells = np.reshape(cells, new_shape) 
    cells = cells.swapaxes(0, 1)
    cells = np.reshape(cells, shape) 

    cells = data_from_grid (cells, gridwidth, gridheight, grid)

    return cells
refit_unet_d8g_222_swrap_02.py 文件源码 项目:kaggle_dsb2017 作者: astoc 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def data_from_grid (cells, gridwidth, gridheight, grid=32):

    width = cells.shape[4]
    crop = (width - grid ) // 2 ## for simplicity we are assuming the same crop (and grid) in x & y directions 

    if crop > 0:  # do NOT crop with 0 as we get empty cells ...
        cells = cells[:,:,:,crop:-crop,crop:-crop]     

    shape = cells.shape
    new_shape_1_dim = shape[0]// (gridwidth * gridheight)  # ws // 36 -- Improved on 20170306
    new_shape = (gridwidth * gridheight, new_shape_1_dim, ) +  tuple([x for x in shape][1:])   # was 36,  Improved on 20170306
    cells = np.reshape(cells, new_shape)  
    cells = np.moveaxis(cells, 0, -3)

    shape = cells.shape
    new_shape2 = tuple([x for x in shape[0:3]]) + (gridheight, gridwidth,) + tuple([x for x in shape[4:]])
    cells = np.reshape(cells, new_shape2)
    cells = cells.swapaxes(-2, -3)
    shape = cells.shape
    combine_shape =tuple([x for x in shape[0:3]]) + (shape[-4]*shape[-3], shape[-2]*shape[-1],)
    cells = np.reshape(cells, combine_shape)

    return cells
refit_unet_d8g_222_swrap_05.py 文件源码 项目:kaggle_dsb2017 作者: astoc 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def data_from_grid (cells, gridwidth, gridheight, grid=32):

    width = cells.shape[4]
    crop = (width - grid ) // 2 ## for simplicity we are assuming the same crop (and grid) in x & y directions 

    if crop > 0:  # do NOT crop with 0 as we get empty cells ...
        cells = cells[:,:,:,crop:-crop,crop:-crop]     

    shape = cells.shape
    new_shape_1_dim = shape[0]// (gridwidth * gridheight)  # ws // 36 -- Improved on 20170306
    new_shape = (gridwidth * gridheight, new_shape_1_dim, ) +  tuple([x for x in shape][1:])   # was 36,  Improved on 20170306
    cells = np.reshape(cells, new_shape)  
    cells = np.moveaxis(cells, 0, -3)

    shape = cells.shape
    new_shape2 = tuple([x for x in shape[0:3]]) + (gridheight, gridwidth,) + tuple([x for x in shape[4:]])
    cells = np.reshape(cells, new_shape2)
    cells = cells.swapaxes(-2, -3)
    shape = cells.shape
    combine_shape =tuple([x for x in shape[0:3]]) + (shape[-4]*shape[-3], shape[-2]*shape[-1],)
    cells = np.reshape(cells, combine_shape)

    return cells
refit_unet_d8g_222_swrap_05.py 文件源码 项目:kaggle_dsb2017 作者: astoc 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def data_from_grid_by_proximity (cells, gridwidth, gridheight, grid=32):

    # disperse the sequential dats into layers and then use data_from_grid
    shape = cells.shape
    new_shape_1_dim = shape[0]// (gridwidth * gridheight)  # ws // 36 -- Improved on 20170306


    ### NOTE tha we invert the order of shapes below to get the required proximity type ordering
    new_shape = (new_shape_1_dim, gridwidth * gridheight,  ) +  tuple([x for x in shape][1:])   # was 36,  Improved on 20170306
    #new_shape = (gridwidth * gridheight, new_shape_1_dim, ) +  tuple([x for x in shape][1:])   # was 36,  Improved on 20170306

    # swap ordering of axes 
    cells = np.reshape(cells, new_shape) 
    cells = cells.swapaxes(0, 1)
    cells = np.reshape(cells, shape) 

    cells = data_from_grid (cells, gridwidth, gridheight, grid)

    return cells
refit_unet_d8g_222_swrap_08.py 文件源码 项目:kaggle_dsb2017 作者: astoc 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def data_from_grid (cells, gridwidth, gridheight, grid=32):

    width = cells.shape[4]
    crop = (width - grid ) // 2 ## for simplicity we are assuming the same crop (and grid) in x & y directions 

    if crop > 0:  # do NOT crop with 0 as we get empty cells ...
        cells = cells[:,:,:,crop:-crop,crop:-crop]     

    shape = cells.shape
    new_shape_1_dim = shape[0]// (gridwidth * gridheight)  # ws // 36 -- Improved on 20170306
    new_shape = (gridwidth * gridheight, new_shape_1_dim, ) +  tuple([x for x in shape][1:])   # was 36,  Improved on 20170306
    cells = np.reshape(cells, new_shape)  
    cells = np.moveaxis(cells, 0, -3)

    shape = cells.shape
    new_shape2 = tuple([x for x in shape[0:3]]) + (gridheight, gridwidth,) + tuple([x for x in shape[4:]])
    cells = np.reshape(cells, new_shape2)
    cells = cells.swapaxes(-2, -3)
    shape = cells.shape
    combine_shape =tuple([x for x in shape[0:3]]) + (shape[-4]*shape[-3], shape[-2]*shape[-1],)
    cells = np.reshape(cells, combine_shape)

    return cells
refit_unet_d8g_222_swrap_08.py 文件源码 项目:kaggle_dsb2017 作者: astoc 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def data_from_grid_by_proximity (cells, gridwidth, gridheight, grid=32):

    # disperse the sequential dats into layers and then use data_from_grid
    shape = cells.shape
    new_shape_1_dim = shape[0]// (gridwidth * gridheight)  # ws // 36 -- Improved on 20170306


    ### NOTE tha we invert the order of shapes below to get the required proximity type ordering
    new_shape = (new_shape_1_dim, gridwidth * gridheight,  ) +  tuple([x for x in shape][1:])   # was 36,  Improved on 20170306
    #new_shape = (gridwidth * gridheight, new_shape_1_dim, ) +  tuple([x for x in shape][1:])   # was 36,  Improved on 20170306

    # swap ordering of axes 
    cells = np.reshape(cells, new_shape) 
    cells = cells.swapaxes(0, 1)
    cells = np.reshape(cells, shape) 

    cells = data_from_grid (cells, gridwidth, gridheight, grid)

    return cells
refit_unet_d8g_222_swrap_01.py 文件源码 项目:kaggle_dsb2017 作者: astoc 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def data_from_grid (cells, gridwidth, gridheight, grid=32):

    width = cells.shape[4]
    crop = (width - grid ) // 2 ## for simplicity we are assuming the same crop (and grid) in x & y directions 

    if crop > 0:  # do NOT crop with 0 as we get empty cells ...
        cells = cells[:,:,:,crop:-crop,crop:-crop]     

    shape = cells.shape
    new_shape_1_dim = shape[0]// (gridwidth * gridheight)  # ws // 36 -- Improved on 20170306
    new_shape = (gridwidth * gridheight, new_shape_1_dim, ) +  tuple([x for x in shape][1:])   # was 36,  Improved on 20170306
    cells = np.reshape(cells, new_shape)  
    cells = np.moveaxis(cells, 0, -3)

    shape = cells.shape
    new_shape2 = tuple([x for x in shape[0:3]]) + (gridheight, gridwidth,) + tuple([x for x in shape[4:]])
    cells = np.reshape(cells, new_shape2)
    cells = cells.swapaxes(-2, -3)
    shape = cells.shape
    combine_shape =tuple([x for x in shape[0:3]]) + (shape[-4]*shape[-3], shape[-2]*shape[-1],)
    cells = np.reshape(cells, combine_shape)

    return cells
fit_unet_d8g_222_swrap_04.py 文件源码 项目:kaggle_dsb2017 作者: astoc 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def data_from_grid (cells, gridwidth, gridheight, grid=32):

    width = cells.shape[4]
    crop = (width - grid ) // 2 ## for simplicity we are assuming the same crop (and grid) in x & y directions 

    if crop > 0:  # do NOT crop with 0 as we get empty cells ...
        cells = cells[:,:,:,crop:-crop,crop:-crop]     

    shape = cells.shape
    new_shape_1_dim = shape[0]// (gridwidth * gridheight)  # ws // 36 -- Improved on 20170306
    new_shape = (gridwidth * gridheight, new_shape_1_dim, ) +  tuple([x for x in shape][1:])   # was 36,  Improved on 20170306
    cells = np.reshape(cells, new_shape)  
    cells = np.moveaxis(cells, 0, -3)

    shape = cells.shape
    new_shape2 = tuple([x for x in shape[0:3]]) + (gridheight, gridwidth,) + tuple([x for x in shape[4:]])
    cells = np.reshape(cells, new_shape2)
    cells = cells.swapaxes(-2, -3)
    shape = cells.shape
    combine_shape =tuple([x for x in shape[0:3]]) + (shape[-4]*shape[-3], shape[-2]*shape[-1],)
    cells = np.reshape(cells, combine_shape)

    return cells
fit_unet_d8g_222_swrap_04.py 文件源码 项目:kaggle_dsb2017 作者: astoc 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def data_from_grid_by_proximity (cells, gridwidth, gridheight, grid=32):

    # disperse the sequential dats into layers and then use data_from_grid
    shape = cells.shape
    new_shape_1_dim = shape[0]// (gridwidth * gridheight)  # ws // 36 -- Improved on 20170306


    ### NOTE tha we invert the order of shapes below to get the required proximity type ordering
    new_shape = (new_shape_1_dim, gridwidth * gridheight,  ) +  tuple([x for x in shape][1:])   # was 36,  Improved on 20170306
    #new_shape = (gridwidth * gridheight, new_shape_1_dim, ) +  tuple([x for x in shape][1:])   # was 36,  Improved on 20170306

    # swap ordering of axes 
    cells = np.reshape(cells, new_shape) 
    cells = cells.swapaxes(0, 1)
    cells = np.reshape(cells, shape) 

    cells = data_from_grid (cells, gridwidth, gridheight, grid)

    return cells
unet_d8g_222f.py 文件源码 项目:kaggle_dsb2017 作者: astoc 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def data_from_grid_by_proximity (cells, gridwidth, gridheight, grid=32):

    # disperse the sequential dats into layers and then use data_from_grid
    dspacing = gridwidth * gridheight
    layers = cells.shape[0] // dspacing

    shape = cells.shape
    new_shape_1_dim = shape[0]// (gridwidth * gridheight)  # ws // 36 -- Improved on 20170306

    ### NOTE tha we invert the order of shapes below to get the required proximity type ordering
    new_shape = (new_shape_1_dim, gridwidth * gridheight,  ) +  tuple([x for x in shape][1:])   # was 36,  Improved on 20170306

    # swap ordering of axes 
    cells = np.reshape(cells, new_shape) 
    cells = cells.swapaxes(0, 1)
    cells = np.reshape(cells, shape) 

    cells = data_from_grid (cells, gridwidth, gridheight, grid)

    return cells
fit_unet_d8g_222_swrap_11.py 文件源码 项目:kaggle_dsb2017 作者: astoc 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def data_from_grid (cells, gridwidth, gridheight, grid=32):

    width = cells.shape[4]
    crop = (width - grid ) // 2 ## for simplicity we are assuming the same crop (and grid) in x & y directions 

    if crop > 0:  # do NOT crop with 0 as we get empty cells ...
        cells = cells[:,:,:,crop:-crop,crop:-crop]     

    shape = cells.shape
    new_shape_1_dim = shape[0]// (gridwidth * gridheight)  # ws // 36 -- Improved on 20170306
    new_shape = (gridwidth * gridheight, new_shape_1_dim, ) +  tuple([x for x in shape][1:])   # was 36,  Improved on 20170306
    cells = np.reshape(cells, new_shape)  
    cells = np.moveaxis(cells, 0, -3)

    shape = cells.shape
    new_shape2 = tuple([x for x in shape[0:3]]) + (gridheight, gridwidth,) + tuple([x for x in shape[4:]])
    cells = np.reshape(cells, new_shape2)
    cells = cells.swapaxes(-2, -3)
    shape = cells.shape
    combine_shape =tuple([x for x in shape[0:3]]) + (shape[-4]*shape[-3], shape[-2]*shape[-1],)
    cells = np.reshape(cells, combine_shape)

    return cells
fit_unet_d8g_222_swrap_11.py 文件源码 项目:kaggle_dsb2017 作者: astoc 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def data_from_grid_by_proximity (cells, gridwidth, gridheight, grid=32):

    # disperse the sequential dats into layers and then use data_from_grid
    shape = cells.shape
    new_shape_1_dim = shape[0]// (gridwidth * gridheight)  # ws // 36 -- Improved on 20170306


    ### NOTE tha we invert the order of shapes below to get the required proximity type ordering
    new_shape = (new_shape_1_dim, gridwidth * gridheight,  ) +  tuple([x for x in shape][1:])   # was 36,  Improved on 20170306
    #new_shape = (gridwidth * gridheight, new_shape_1_dim, ) +  tuple([x for x in shape][1:])   # was 36,  Improved on 20170306

    # swap ordering of axes 
    cells = np.reshape(cells, new_shape) 
    cells = cells.swapaxes(0, 1)
    cells = np.reshape(cells, shape) 

    cells = data_from_grid (cells, gridwidth, gridheight, grid)

    return cells
refit_unet_d8g_222_swrap_04.py 文件源码 项目:kaggle_dsb2017 作者: astoc 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def data_from_grid (cells, gridwidth, gridheight, grid=32):

    width = cells.shape[4]
    crop = (width - grid ) // 2 ## for simplicity we are assuming the same crop (and grid) in x & y directions 

    if crop > 0:  # do NOT crop with 0 as we get empty cells ...
        cells = cells[:,:,:,crop:-crop,crop:-crop]     

    shape = cells.shape
    new_shape_1_dim = shape[0]// (gridwidth * gridheight)  # ws // 36 -- Improved on 20170306
    new_shape = (gridwidth * gridheight, new_shape_1_dim, ) +  tuple([x for x in shape][1:])   # was 36,  Improved on 20170306
    cells = np.reshape(cells, new_shape)  
    cells = np.moveaxis(cells, 0, -3)

    shape = cells.shape
    new_shape2 = tuple([x for x in shape[0:3]]) + (gridheight, gridwidth,) + tuple([x for x in shape[4:]])
    cells = np.reshape(cells, new_shape2)
    cells = cells.swapaxes(-2, -3)
    shape = cells.shape
    combine_shape =tuple([x for x in shape[0:3]]) + (shape[-4]*shape[-3], shape[-2]*shape[-1],)
    cells = np.reshape(cells, combine_shape)

    return cells
refit_unet_d8g_222_swrap_04.py 文件源码 项目:kaggle_dsb2017 作者: astoc 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def data_from_grid_by_proximity (cells, gridwidth, gridheight, grid=32):

    # disperse the sequential dats into layers and then use data_from_grid
    shape = cells.shape
    new_shape_1_dim = shape[0]// (gridwidth * gridheight)  # ws // 36 -- Improved on 20170306


    ### NOTE tha we invert the order of shapes below to get the required proximity type ordering
    new_shape = (new_shape_1_dim, gridwidth * gridheight,  ) +  tuple([x for x in shape][1:])   # was 36,  Improved on 20170306
    #new_shape = (gridwidth * gridheight, new_shape_1_dim, ) +  tuple([x for x in shape][1:])   # was 36,  Improved on 20170306

    # swap ordering of axes 
    cells = np.reshape(cells, new_shape) 
    cells = cells.swapaxes(0, 1)
    cells = np.reshape(cells, shape) 

    cells = data_from_grid (cells, gridwidth, gridheight, grid)

    return cells
fit_unet_d8g_222_swrap_07.py 文件源码 项目:kaggle_dsb2017 作者: astoc 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def data_from_grid (cells, gridwidth, gridheight, grid=32):

    width = cells.shape[4]
    crop = (width - grid ) // 2 ## for simplicity we are assuming the same crop (and grid) in x & y directions 

    if crop > 0:  # do NOT crop with 0 as we get empty cells ...
        cells = cells[:,:,:,crop:-crop,crop:-crop]     

    shape = cells.shape
    new_shape_1_dim = shape[0]// (gridwidth * gridheight)  # ws // 36 -- Improved on 20170306
    new_shape = (gridwidth * gridheight, new_shape_1_dim, ) +  tuple([x for x in shape][1:])   # was 36,  Improved on 20170306
    cells = np.reshape(cells, new_shape)  
    cells = np.moveaxis(cells, 0, -3)

    shape = cells.shape
    new_shape2 = tuple([x for x in shape[0:3]]) + (gridheight, gridwidth,) + tuple([x for x in shape[4:]])
    cells = np.reshape(cells, new_shape2)
    cells = cells.swapaxes(-2, -3)
    shape = cells.shape
    combine_shape =tuple([x for x in shape[0:3]]) + (shape[-4]*shape[-3], shape[-2]*shape[-1],)
    cells = np.reshape(cells, combine_shape)

    return cells
refit_unet_d8g_222_swrap_10.py 文件源码 项目:kaggle_dsb2017 作者: astoc 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def data_from_grid (cells, gridwidth, gridheight, grid=32):

    width = cells.shape[4]
    crop = (width - grid ) // 2 ## for simplicity we are assuming the same crop (and grid) in x & y directions 

    if crop > 0:  # do NOT crop with 0 as we get empty cells ...
        cells = cells[:,:,:,crop:-crop,crop:-crop]     

    shape = cells.shape
    new_shape_1_dim = shape[0]// (gridwidth * gridheight)  # ws // 36 -- Improved on 20170306
    new_shape = (gridwidth * gridheight, new_shape_1_dim, ) +  tuple([x for x in shape][1:])   # was 36,  Improved on 20170306
    cells = np.reshape(cells, new_shape)  
    cells = np.moveaxis(cells, 0, -3)

    shape = cells.shape
    new_shape2 = tuple([x for x in shape[0:3]]) + (gridheight, gridwidth,) + tuple([x for x in shape[4:]])
    cells = np.reshape(cells, new_shape2)
    cells = cells.swapaxes(-2, -3)
    shape = cells.shape
    combine_shape =tuple([x for x in shape[0:3]]) + (shape[-4]*shape[-3], shape[-2]*shape[-1],)
    cells = np.reshape(cells, combine_shape)

    return cells
refit_unet_d8g_222_swrap_10.py 文件源码 项目:kaggle_dsb2017 作者: astoc 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def data_from_grid_by_proximity (cells, gridwidth, gridheight, grid=32):

    # disperse the sequential dats into layers and then use data_from_grid
    shape = cells.shape
    new_shape_1_dim = shape[0]// (gridwidth * gridheight)  # ws // 36 -- Improved on 20170306


    ### NOTE tha we invert the order of shapes below to get the required proximity type ordering
    new_shape = (new_shape_1_dim, gridwidth * gridheight,  ) +  tuple([x for x in shape][1:])   # was 36,  Improved on 20170306
    #new_shape = (gridwidth * gridheight, new_shape_1_dim, ) +  tuple([x for x in shape][1:])   # was 36,  Improved on 20170306

    # swap ordering of axes 
    cells = np.reshape(cells, new_shape) 
    cells = cells.swapaxes(0, 1)
    cells = np.reshape(cells, shape) 

    cells = data_from_grid (cells, gridwidth, gridheight, grid)

    return cells
fit_unet_d8g_222_swrap_06.py 文件源码 项目:kaggle_dsb2017 作者: astoc 项目源码 文件源码 阅读 37 收藏 0 点赞 0 评论 0
def data_from_grid (cells, gridwidth, gridheight, grid=32):

    width = cells.shape[4]
    crop = (width - grid ) // 2 ## for simplicity we are assuming the same crop (and grid) in x & y directions 

    if crop > 0:  # do NOT crop with 0 as we get empty cells ...
        cells = cells[:,:,:,crop:-crop,crop:-crop]     

    shape = cells.shape
    new_shape_1_dim = shape[0]// (gridwidth * gridheight)  # ws // 36 -- Improved on 20170306
    new_shape = (gridwidth * gridheight, new_shape_1_dim, ) +  tuple([x for x in shape][1:])   # was 36,  Improved on 20170306
    cells = np.reshape(cells, new_shape)  
    cells = np.moveaxis(cells, 0, -3)

    shape = cells.shape
    new_shape2 = tuple([x for x in shape[0:3]]) + (gridheight, gridwidth,) + tuple([x for x in shape[4:]])
    cells = np.reshape(cells, new_shape2)
    cells = cells.swapaxes(-2, -3)
    shape = cells.shape
    combine_shape =tuple([x for x in shape[0:3]]) + (shape[-4]*shape[-3], shape[-2]*shape[-1],)
    cells = np.reshape(cells, combine_shape)

    return cells
fit_unet_d8g_222_swrap_06.py 文件源码 项目:kaggle_dsb2017 作者: astoc 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def data_from_grid_by_proximity (cells, gridwidth, gridheight, grid=32):

    # disperse the sequential dats into layers and then use data_from_grid
    shape = cells.shape
    new_shape_1_dim = shape[0]// (gridwidth * gridheight)  # ws // 36 -- Improved on 20170306


    ### NOTE tha we invert the order of shapes below to get the required proximity type ordering
    new_shape = (new_shape_1_dim, gridwidth * gridheight,  ) +  tuple([x for x in shape][1:])   # was 36,  Improved on 20170306
    #new_shape = (gridwidth * gridheight, new_shape_1_dim, ) +  tuple([x for x in shape][1:])   # was 36,  Improved on 20170306

    # swap ordering of axes 
    cells = np.reshape(cells, new_shape) 
    cells = cells.swapaxes(0, 1)
    cells = np.reshape(cells, shape) 

    cells = data_from_grid (cells, gridwidth, gridheight, grid)

    return cells


问题


面经


文章

微信
公众号

扫码关注公众号