• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python numpy.swapaxes函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中numpy.swapaxes函数的典型用法代码示例。如果您正苦于以下问题:Python swapaxes函数的具体用法?Python swapaxes怎么用?Python swapaxes使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了swapaxes函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: prep_image

def prep_image(im, IMAGE_W, IMAGE_H, BGR=BGR):
    if len(im.shape) == 2:
        im = im[:, :, np.newaxis]
        im = np.repeat(im, 3, axis=2)
    h, w, _ = im.shape
    if h*IMAGE_W < w*IMAGE_H:
        im = skimage.transform.resize(im, (IMAGE_H, w*IMAGE_H//h), preserve_range=True)
    else:
        im = skimage.transform.resize(im, (h*IMAGE_W//w, IMAGE_W), preserve_range=True)        

    # Central crop
    h, w, _ = im.shape
    im = im[h//2-IMAGE_H//2:h//2+IMAGE_H//2, w//2-IMAGE_W//2:w//2+IMAGE_W//2]
    
    rawim = im.astype('uint8')
    
    # Shuffle axes to c01
    im = np.swapaxes(np.swapaxes(im, 1, 2), 0, 1)
    
    # Convert RGB to BGR
    if not BGR:
        im = im[::-1, :, :]

    im = im - MEAN_VALUES
    return rawim, floatX(im[np.newaxis])
开发者ID:ChunHungLiu,项目名称:Quick-Neural-Art-Transfer,代码行数:25,代码来源:neuralStyle.py


示例2: load_minibatch

def load_minibatch(input_list, color, labels, start,num):
    # Enforce maximum on start
    start = max(0,start)

    # Enforce minimum on end
    end = start + num
    end = min(len(input_list), end)

    # Isolate files
    files = input_list[start:end]

    images = []
    for file in files:
        img = caffe.io.load_image(file, color)
        
        # Handle incorrect image dims for uncropped images
        # TODO: Get uncropped images to import correctly
        if img.shape[0] == 3 or img.shape[0] == 1:
            img = np.swapaxes(np.swapaxes(img, 0, 1), 1, 2)
        
        # BUG FIX: Is this ok?
        # color=True gets the correct desired dimension of WxHx3
        # But color=False gets images of WxHx1. Need WxHx3 or will get "Index out of bounds" exception
        # Fix by concatenating three copies of the image
        if img.shape[2] == 1:
            img = cv.merge([img,img,img])

        # Add image array to batch
        images.append(img)

    labelsReduced = labels[start:end]
    return images, labelsReduced
开发者ID:GautamShine,项目名称:emotion-conv-net,代码行数:32,代码来源:caffe_functions.py


示例3: rgb2caffe

def rgb2caffe(im, downscale=True, out_size=(128, 171)):
    '''
    Converts an RGB image to caffe format and downscales it as needed by C3D

    Parameters
    ----------
    im an RGB image
    downscale

    Returns
    -------
    a caffe image (channel,height, width) in BGR format

    '''
    im=np.copy(im)
    if len(im.shape)==2: # Make sure the image has 3 channels
        im = color.gray2rgb(im)

    if downscale:
        h, w, _ = im.shape
        im = skimage.transform.resize(im, out_size, preserve_range=True)
    else:
        im=np.array(im,theano.config.floatX)
    im = np.swapaxes(np.swapaxes(im, 1, 2), 0, 1)

    # Convert to BGR
    im = im[::-1, :, :]

    return np.array(im,theano.config.floatX)
开发者ID:znaoya,项目名称:Recipes,代码行数:29,代码来源:c3d.py


示例4: acorr

def acorr(x, axis=-1, onesided=False, scale='none'):
    """Compute autocorrelation of x along given axis.

    Parameters
    ----------
        x : array-like
            signal to correlate.
        axis : int
            axis along which autocorrelation is computed.
        onesided: bool, optional
            if True, only returns the right side of the autocorrelation.
        scale: {'none', 'coeff'}
            scaling mode. If 'coeff', the correlation is normalized such as the
            0-lag is equal to 1.

    Notes
    -----
        Use fft for computation: is more efficient than direct computation for
        relatively large n.
    """
    if not np.isrealobj(x):
        raise ValueError("Complex input not supported yet")
    if not scale in ['none', 'coeff']:
        raise ValueError("scale mode %s not understood" % scale)

    maxlag = x.shape[axis]
    nfft = 2 ** nextpow2(2 * maxlag - 1)

    if axis != -1:
        x = np.swapaxes(x, -1, axis)
    a = _acorr_last_axis(x, nfft, maxlag, onesided, scale)
    if axis != -1:
        a = np.swapaxes(a, -1, axis)
    return a
开发者ID:Lathomas42,项目名称:Envelope_Detection,代码行数:34,代码来源:correlations.py


示例5: load_image

    def load_image(self, impath, normalize=False):

        if os.path.splitext(impath)[1] == ".npz":
            im = np.load(impath)["im"]

        else:

            im = skimage.io.imread(impath)
            if normalize:
                im = im / 255.0

            im = resize(im, self.imshape, mode="nearest")

        if self.mean_im is not None:
            im -= self.mean_im

        # shuffle from (W,H,3) to (3,W,H)
        if not self.greyscale:
            im = np.swapaxes(im, 0, 2)
            im = np.swapaxes(im, 1, 2)
        else:
            if im.ndim == 3:
                im = skimage.color.rgb2grey(im)

        return im
开发者ID:kencoken,项目名称:theano-wrap,代码行数:25,代码来源:data.py


示例6: _read_img

    def _read_img(self, img, label):
        if self.regress_overlay:
            label = label
        else:
            label = 0

        img = np.array(img)
        img = img.reshape(self.crop_size, self.crop_size)
        #cv2.imshow("GRAY", img)
        #cv2.waitKey(0)
        
        if self.scale_size is not None:
            img = cv2.resize(img, (self.scale_size, self.scale_size), interpolation=cv2.INTER_AREA).astype(float)        
    

        img = img.reshape(img.shape[0], img.shape[1], 1)           
        img = np.swapaxes(img, 0, 2)
        img = np.swapaxes(img, 1, 2)  # (c, h, w)
        
        label_1 = label#20161026
        flag = False
##        for t in label:
##            if t > 1:
##                print("label_1: ", label_1)
##                flag =True

        
        label = np.array(label_1)             
        img = np.expand_dims(img, axis=0)  # (1, c, h, w) or (1, h, w)
        #print(label)

        return img, label, False#label_1, label_2, flag
开发者ID:7oud,项目名称:FileCache,代码行数:32,代码来源:helpers_fileiter.py


示例7: _npBatchMatmul

 def _npBatchMatmul(self, x, y, adjoint_a, adjoint_b):
   # output's shape depends on adj[0] and adj[1]
   if adjoint_a:
     x = np.conjugate(np.swapaxes(x, -1, -2))
   if adjoint_b:
     y = np.conjugate(np.swapaxes(y, -1, -2))
   return np.matmul(x, y)
开发者ID:adit-chandra,项目名称:tensorflow,代码行数:7,代码来源:batch_matmul_op_test.py


示例8: prepare_image

def prepare_image(img, width, means):
    
    # if not RGB, force 3 channels
    if len(img.shape) == 2:
        img = img[:, :, np.newaxis]
        img = np.repeat(img, 3, axis=2)
    h, w, _ = img.shape
    if h < w:
        img = skimage.transform.resize(img, (width, w*width/h), preserve_range=True)
    else:
        img = skimage.transform.resize(img, (h*width/w, width), preserve_range=True)

    # crop the center
    h, w, _ = img.shape
    img = img[h//2 - width//2:h//2 + width//2, w//2 - width//2:w//2 + width//2]
    
    rawim = np.copy(img).astype('uint8')
    
    # shuffle axes to c01
    img = np.swapaxes(np.swapaxes(img, 1, 2), 0, 1)
    
    # convert RGB to BGR
    img = img[::-1, :, :]
    
    # zero mean scaling
    img = img - means
    
    return rawim, floatX(img[np.newaxis])
开发者ID:bebee,项目名称:ArtsyNetworks,代码行数:28,代码来源:art_it_up.py


示例9: predictions_grid_color

def predictions_grid_color(samples, predictions, k, imgshape, title):
    batch_size = samples.shape[0]
    print("printintg predictions:")
    print(samples.shape)
    print(imgshape)
    print(predictions.shape)
    samples = samples.reshape(batch_size, imgshape[1], imgshape[2], imgshape[3])
    predictions = predictions.reshape(batch_size, imgshape[1], imgshape[2], imgshape[3])
    plt.figure(figsize=(10, 10))
    gs = gridspec.GridSpec(5, 2)
    for i in range(10):
        ax = plt.subplot(gs[i])
        if i % 2 == 0:
            w = samples[i/2, :, :, :]
        else:
            w = predictions[i/2, :, :, :]
        w = np.swapaxes(w, 0, 1)
        w = np.swapaxes(w, 1, 2)
        ax.imshow(w,
                  cmap=plt.cm.gist_yarg,
                  interpolation='nearest',
                  aspect='equal')
        ax.set_xticklabels([])
        ax.set_yticklabels([])
        ax.axis('off')
    gs.update(wspace=0)
    plt.savefig(os.path.join('convpredictions', str(k) + '_' + title + '.png'),
                bbox_inches='tight')
    plt.close('all')
开发者ID:MaGold,项目名称:VAE,代码行数:29,代码来源:Plots.py


示例10: initializeIndices

    def initializeIndices(self, ni, nj):
        if not ni==None:
            self.ni = numpy.array(ni,int)
        if not nj==None:
            self.nj = numpy.array(nj,int)
        if self.mSide==-1:
            if ni==None:
                self.ni = [1,self.mComp.ms[0].shape[0],1]
            if nj==None:
                self.nj = [1,self.mComp.ms[2].shape[0],1]
        else:
            if ni==None:
                self.ni = [1,0,1]
            if nj==None:
                self.nj = [1,self.mComp.ms[0].shape[0],1]

        if self.fRot==0:
            self.rotate = lambda P: P
            self.flip = lambda nu, nv: [nu,nv]
        elif self.fRot==1:
            self.rotate = lambda P: numpy.swapaxes(P,0,1)[::-1,:]
            self.flip = lambda nu, nv: [nv[::-1],nu]
        elif self.fRot==2:
            self.rotate = lambda P: P[::-1,::-1]
            self.flip = lambda nu, nv: [nu[::-1],nv[::-1]]
        elif self.fRot==3:
            self.rotate = lambda P: numpy.swapaxes(P,0,1)[:,::-1]
            self.flip = lambda nu, nv: [nv,nu[::-1]]

        self.fK = self.rotate(self.fComp.Ks[self.fFace])[self.fNW[0]:self.fNW[0]+sum(self.ni),self.fNW[1]:self.fNW[1]+sum(self.nj)]
开发者ID:OpenMDAO-Plugins,项目名称:GeoMACH,代码行数:30,代码来源:junction.py


示例11: reorder_array

def reorder_array(the_array, order_list):
	# put time first as by agrreement in IDTxL
	time_dimension = order_list.index("time")
	if time_dimension != 1:
		the_array = np.swapaxes(the_array,1,time_dimension)
		# also swap the list to reflect the new arrangement
		order_list[1], order_list[time_dimension] = \
		order_list[time_dimension], order_list[1]
		
	# put channel second
	channel_dimension = order_list.index("channel")
	if channel_dimension !=2:
		the_array = np.swapaxes(the_array,2,channel_dimension)
		# also swap the list to reflect the new arrangement
		order_list[2], order_list[channel_dimension] = \
		order_list[channel_dimension], order_list[2]
		
	# put repetitions third - unnecessary in principle as n-1 permutations
	# are guaranteed to sort our array dimensions for n dimensions
	#assert order_list.index("repetition") == 3, print('something went wrong with reordering')
	
	# uncomment the following code when expanding
	#repetition_dimension = order_list.index("repetition")
	#if repetition_dimension !=2:
	#	the_array = np.swapaxes(the_array,2,repetition_dimension)
	#	# also swap the list to reflect the new arrangement
	#	order_list[3], order_list[repetition_dimension] = \
	#	order_list[repetition_dimension], order_list[3]
	
	# put further dimensions fourth in future versions...
	return the_array
开发者ID:mwibral,项目名称:IDTxl,代码行数:31,代码来源:matarray2idtxl.py


示例12: generate_batch

 def generate_batch(num_samples, obj_type='circle'):
     # generate a minibatch of trajectories
     traj_pos, traj_vel = TRAJ.generate_trajectories(num_samples, traj_len)
     traj_x = traj_pos[:,:,0]
     traj_y = traj_pos[:,:,1]
     # draw the trajectories
     center_x = to_fX( traj_x.T.ravel() )
     center_y = to_fX( traj_y.T.ravel() )
     delta = to_fX( np.ones(center_x.shape) )
     sigma = to_fX( np.ones(center_x.shape) )
     if obj_type == 'circle':
         W = paint_circle(center_y, center_x, delta, 0.05*sigma)
     else:
         W = paint_cross(center_y, center_x, delta, 0.05*sigma)
     # shape trajectories into a batch for passing to the model
     batch_imgs = np.zeros((num_samples, traj_len, obs_dim))
     batch_coords = np.zeros((num_samples, traj_len, 2))
     for i in range(num_samples):
         start_idx = i * traj_len
         end_idx = start_idx + traj_len
         img_set = W[start_idx:end_idx,:]
         batch_imgs[i,:,:] = img_set
         batch_coords[i,:,0] = center_x[start_idx:end_idx]
         batch_coords[i,:,1] = center_y[start_idx:end_idx]
     batch_imgs = np.swapaxes(batch_imgs, 0, 1)
     batch_coords = np.swapaxes(batch_coords, 0, 1)
     return [to_fX( batch_imgs ), to_fX( batch_coords )]
开发者ID:Philip-Bachman,项目名称:Sequential-Generation,代码行数:27,代码来源:TestRAMVideoFT.py


示例13: dGamma_dgam

    def dGamma_dgam(self,gam_IM,gam_MD1,gam_D1D2,gam_D2R,
                    lam_IM,lam_MD1,lam_D1D2,lam_D2R):

        dgdgam_IM, dgdgam_MD1, dgdgam_D1D2, dgdgam_D2R = \
            self.dFrequencyCostdGamma_dgdgam(gam_IM,gam_MD1,gam_D1D2,gam_D2R)
        dedgam_IM, dedgam_MD1, dedgam_D1D2, dedgam_D2R = \
            self.dEmissionCostdGamma_dedgam(gam_IM,gam_MD1,gam_D1D2,gam_D2R)

        w_IM = np.reshape(np.tile(np.swapaxes(self.w[None],0,1),
                                  np.prod(dedgam_IM.shape[1:])).flatten(),
                          dedgam_IM.shape)
        w_MD1 = np.reshape(np.tile(np.swapaxes(self.w[None],0,1),
                                   np.prod(dedgam_MD1.shape[1:])).flatten(),
                           dedgam_MD1.shape)
        w_D1D2 = np.reshape(np.tile(np.swapaxes(self.w[None],0,1),
                                    np.prod(dedgam_D1D2.shape[1:])).flatten(),
                            dedgam_D1D2.shape)
        w_D2R = np.reshape(np.tile(np.swapaxes(self.w[None],0,1),
                                   np.prod(dedgam_D2R.shape[1:])).flatten(),
                           dedgam_D2R.shape)

        dgam_IM = dgdgam_IM + w_IM*dedgam_IM - self.u_IM*lam_IM
        dgam_MD1 = dgdgam_MD1 + w_MD1*dedgam_MD1 - self.u_MD1*lam_MD1
        dgam_D1D2 = dgdgam_D1D2 + w_D1D2*dedgam_D1D2 - self.u_D1D2*lam_D1D2
        dgam_D2R = dgdgam_D2R + w_D2R*dedgam_D2R - self.u_D2R*lam_D2R

        return dgam_IM, dgam_MD1, dgam_D1D2, dgam_D2R
开发者ID:all-umass,项目名称:VI-Solver,代码行数:27,代码来源:SupplyChain.py


示例14: dLinkFlow_df

    def dLinkFlow_df(self,f_IM,f_MD1,f_D1D2,f_D2R,
                     lam_IM,lam_MD1,lam_D1D2,lam_D2R):

        dcdf_IM, dcdf_MD1, dcdf_D1D2, dcdf_D2R = \
            self.dOperationalCostdLinkFlow_dcdf(f_IM,f_MD1,f_D1D2,f_D2R)
        dedf_IM, dedf_MD1, dedf_D1D2, dedf_D2R = \
            self.dEmissionCostdLinkFlow_dedf(f_IM,f_MD1,f_D1D2,f_D2R)

        w_IM = np.reshape(np.tile(np.swapaxes(self.w[None],0,1),
                                  np.prod(dedf_IM.shape[1:])).flatten(),
                          dedf_IM.shape)
        w_MD1 = np.reshape(np.tile(np.swapaxes(self.w[None],0,1),
                                   np.prod(dedf_MD1.shape[1:])).flatten(),
                           dedf_MD1.shape)
        w_D1D2 = np.reshape(np.tile(np.swapaxes(self.w[None],0,1),
                                    np.prod(dedf_D1D2.shape[1:])).flatten(),
                            dedf_D1D2.shape)
        w_D2R = np.reshape(np.tile(np.swapaxes(self.w[None],0,1),
                                   np.prod(dedf_D2R.shape[1:])).flatten(),
                           dedf_D2R.shape)

        df_IM = dcdf_IM + w_IM*dedf_IM + lam_IM
        df_MD1 = dcdf_MD1 + w_MD1*dedf_MD1 + lam_MD1
        df_D1D2 = dcdf_D1D2 + w_D1D2*dedf_D1D2 + lam_D1D2
        df_D2R = dcdf_D2R + w_D2R*dedf_D2R + lam_D2R

        return df_IM, df_MD1, df_D1D2, df_D2R
开发者ID:all-umass,项目名称:VI-Solver,代码行数:27,代码来源:SupplyChain.py


示例15: _read_img

 def _read_img(self, img_name, label_name):
     img = Image.open(os.path.join(self.root_dir, img_name))
     label = Image.open(os.path.join(self.root_dir, label_name))
     assert img.size == label.size
     img = np.array(img, dtype=np.float32)  # (h, w, c)
     label = np.array(label)  # (h, w)
     if self.cut_off_size is not None:
         max_hw = max(img.shape[0], img.shape[1])
         min_hw = min(img.shape[0], img.shape[1])
         if min_hw > self.cut_off_size:
             rand_start_max = round(np.random.uniform(0, max_hw - self.cut_off_size - 1))
             rand_start_min = round(np.random.uniform(0, min_hw - self.cut_off_size - 1))
             if img.shape[0] == max_hw :
                 img = img[rand_start_max : rand_start_max + self.cut_off_size, rand_start_min : rand_start_min + self.cut_off_size]
                 label = label[rand_start_max : rand_start_max + self.cut_off_size, rand_start_min : rand_start_min + self.cut_off_size]
             else :
                 img = img[rand_start_min : rand_start_min + self.cut_off_size, rand_start_max : rand_start_max + self.cut_off_size]
                 label = label[rand_start_min : rand_start_min + self.cut_off_size, rand_start_max : rand_start_max + self.cut_off_size]
         elif max_hw > self.cut_off_size:
             rand_start = round(np.random.uniform(0, max_hw - min_hw - 1))
             if img.shape[0] == max_hw :
                 img = img[rand_start : rand_start + min_hw, :]
                 label = label[rand_start : rand_start + min_hw, :]
             else :
                 img = img[:, rand_start : rand_start + min_hw]
                 label = label[:, rand_start : rand_start + min_hw]
     reshaped_mean = self.mean.reshape(1, 1, 3)
     img = img - reshaped_mean
     img = np.swapaxes(img, 0, 2)
     img = np.swapaxes(img, 1, 2)  # (c, h, w)
     img = np.expand_dims(img, axis=0)  # (1, c, h, w)
     label = np.array(label)  # (h, w)
     label = np.expand_dims(label, axis=0)  # (1, h, w)
     return (img, label)
开发者ID:zhaw,项目名称:wine_private,代码行数:34,代码来源:data.py


示例16: plot_color_filters

def plot_color_filters(x, idx, title=""):
    num_filters = x.shape[0]
    numrows = 10
    numcols = int(np.ceil(num_filters/10))
    plt.figure(figsize=(numrows, numcols))
    gs = gridspec.GridSpec(numcols, numrows)
    gs.update(wspace=0.1)
    gs.update(hspace=0.0)

    print("plotting color filters")
    for i in range(num_filters):
        ax = plt.subplot(gs[i])
        w = x[i, :, :, :]
        w = np.swapaxes(w, 0, 1)
        w = np.swapaxes(w, 1, 2)

        #normalize
        
        r = w[:,:,0] - np.min(w[:,:,0])
        g = w[:,:,1] - np.min(w[:,:,1])
        b = w[:,:,2] - np.min(w[:,:,2])
        r = r * 1.0 / np.max(r)
        g = g * 1.0 / np.max(g)
        b = b * 1.0 / np.max(b)
        w = np.dstack((r,g,b))
        ax.imshow(w,
                  cmap=plt.cm.gist_yarg,
                  interpolation='nearest',
                  aspect='equal')
        ax.set_xticklabels([])
        ax.set_yticklabels([])
        ax.axis('off')
    plt.savefig(os.path.join('convfilters', title+ '_' + str(idx) + '_convcaustics.png'))
    print(os.path.join('convfilters', title+ '_' + str(idx) + '_convcaustics.png'))
    plt.close('all')
开发者ID:MaGold,项目名称:VAE,代码行数:35,代码来源:Plots.py


示例17: rotateLeft

    def rotateLeft(self):
        self._fakeEntities = None
        self._Blocks = swapaxes(self._Blocks, 1, 2)[:, ::-1, :]  # x=z; z=-x
        if "Biomes" in self.root_tag:
            self.root_tag["Biomes"].value = swapaxes(self.root_tag["Biomes"].value, 0, 1)[::-1, :]

        self.root_tag["Data"].value = swapaxes(self.root_tag["Data"].value, 1, 2)[:, ::-1, :]  # x=z; z=-x
        self._update_shape()

        blockrotation.RotateLeft(self.Blocks, self.Data)

        log.info(u"Relocating entities...")
        for entity in self.Entities:
            for p in "Pos", "Motion":
                if p == "Pos":
                    zBase = self.Length
                else:
                    zBase = 0.0
                newX = entity[p][2].value
                newZ = zBase - entity[p][0].value

                entity[p][0].value = newX
                entity[p][2].value = newZ
            entity["Rotation"][0].value -= 90.0
            if entity["id"].value in ("Painting", "ItemFrame") or MCEDIT_IDS.get(entity["id"]) in ('DEFS_ENTITIES_PAINTING', 'DEFS_ENTITIES_ITEM_FRAME'):
                x, z = entity["TileX"].value, entity["TileZ"].value
                newx = z
                newz = self.Length - x - 1

                entity["TileX"].value, entity["TileZ"].value = newx, newz
                facing = entity.get("Facing", entity.get("Direction"))
                if facing is None:
                    dirFacing = entity.get("Dir")
                    if dirFacing is not None:
                        if dirFacing.value == 0:
                            dirFacing.value = 2
                        elif dirFacing.value == 2:
                            dirFacing.value = 0
                        facing = dirFacing
                    else:
                        raise Exception("None of tags Facing/Direction/Dir found in entity %s during rotating -  %r" % (entity["id"].value, entity))
                facing.value = (facing.value - 1) % 4

        for tileEntity in self.TileEntities:
            if 'x' not in tileEntity:
                continue

            newX = tileEntity["z"].value
            newZ = self.Length - tileEntity["x"].value - 1

            tileEntity["x"].value = newX
            tileEntity["z"].value = newZ

        if "TileTicks" in self.root_tag:
            for tileTick in self.TileTicks:
                newX = tileTick["z"].value
                newZ = tileTick["x"].value

                tileTick["x"].value = newX
                tileTick["z"].value = newZ
开发者ID:TropicSapling,项目名称:MCEdit-Unified,代码行数:60,代码来源:schematic.py


示例18: plot_predictions

def plot_predictions(samples, predictions, k, batch_size, imgshape):
    samples = samples.reshape(batch_size, 3, imgshape, imgshape)
    predictions = predictions.reshape(batch_size, 3, imgshape, imgshape)
    samples = np.swapaxes(samples, 1,2)
    samples = np.swapaxes(samples, 2,3)
    predictions = np.swapaxes(predictions, 1,2)
    predictions = np.swapaxes(predictions, 2,3)
    for i in range(samples.shape[0]):
        fig = plt.figure(figsize=(5, 5))
        plt.imshow(samples[i, :, :, :],
                cmap=plt.cm.gist_yarg, interpolation='nearest',
                aspect='equal')
        path = "convpredictions"
        fname = str(k) + '_' + str(i) + 'sample_IN.png'
        plt.subplots_adjust(left=0, right=1, bottom=0, top=1)
        plt.savefig(os.path.join(path, fname), dpi=imgshape)
        plt.close('all')
        fig = plt.figure(figsize=(5, 5))
        print(predictions[i, :, :, :].shape)
        print(predictions[i, :, :, :])
        plt.imshow(predictions[i, :, :, :],
                cmap=plt.cm.gist_yarg, interpolation='nearest',
                aspect='equal')
        fname = str(k) + '_' + str(i) + 'sample_OUT.png'
        plt.subplots_adjust(left=0, right=1, bottom=0, top=1)
        plt.savefig(os.path.join(path, fname), dpi=imgshape)
        plt.close('all')
开发者ID:MaGold,项目名称:VAE,代码行数:27,代码来源:Plots.py


示例19: preprocess_image

def preprocess_image(im_file):
    """
    preprocess image to 256 for neural network to work
    """
    # ways to get image on the web
    # import io
    # ext = url.split('.')[-1]
    # im = plt.imread(io.BytesIO(urllib.urlopen(url).read()), ext)

    im = plt.imread(open(im_file, 'r'))

    # resize to smalled dimension of 256 while preserving aspect ratio
    h, w, c = im.shape

    if h < w:
        im = skimage.transform.resize(im, (256, w/h*256), preserve_range=True)
    else:
        im = skimage.transform.resize(im, (h/w*256, 256), preserve_range=True)

    h, w, c = im.shape

    # central crop to 224x224
    im = im[h//2-112:h//2+112, w//2-112:w//2+112]

    rawim = np.copy(im).astype('uint8')

    # Shuffle axes to c01
    im = np.swapaxes(np.swapaxes(im, 1, 2), 0, 1)

    # Convert to BGR
    im = im[::-1, :, :]

    im = im - MEAN_IMAGE
    return rawim, floatX(im[np.newaxis])
开发者ID:han928,项目名称:urFarmer,代码行数:34,代码来源:featurize_image.py


示例20: get_minibatch

    def get_minibatch(self, firstIdxHMDB, lastIdxHMDB, firstIdxUCF, lastIdxUCF, batch_size,
                      data_specs, return_tuple):
 
        x = np.zeros([batch_size, self.data2.shape[1]] , dtype="float32")
        y = np.zeros([batch_size, self.nbTags],  dtype="float32")
        second_y = np.zeros([batch_size, self.nbTags2],  dtype="float32")
		
        #UCF
        dataTmp = self.data[firstIdxUCF:lastIdxUCF,0:1570800]
        # re-scale back to float32 (UCF101)
        dataTmp=dataTmp.astype("float32")
        dataTmp *= (1./255.)
        x[0:(lastIdxUCF -firstIdxUCF),:] = dataTmp
        #import pdb; pdb.set_trace()
        y[0:(lastIdxUCF -firstIdxUCF),:] = self.labels[firstIdxUCF:lastIdxUCF]
        second_y[0:(lastIdxUCF -firstIdxUCF),:] = 0.0	
        #HMDB
        dataTmp = self.data2[firstIdxHMDB:lastIdxHMDB]
        x[(lastIdxUCF -firstIdxUCF):,:] = dataTmp
        y[(lastIdxUCF -firstIdxUCF):,:] = 0.0;
        second_y[(lastIdxUCF -firstIdxUCF):,:] = self.labels2[firstIdxHMDB:lastIdxHMDB];
		
        y = np.concatenate((y, second_y), axis=1)
        x = x.reshape(batch_size, self.nb_t, self.nb_x, self.nb_y, self.nb_feats)
        x  = np.swapaxes(x, 1, 2) # 'b, 0, 't', 1, 'c'
        x  = np.swapaxes(x, 2, 3) # 'b, 0, 1, 't', 'c'
      
        print "Returned a minibatch", lastIdxHMDB, lastIdxUCF
        return x, y
开发者ID:AtousaTorabi,项目名称:HumanActivityRecognition,代码行数:29,代码来源:UCF101Dataset_h5_MultiTask3.py



注:本文中的numpy.swapaxes函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python numpy.take函数代码示例发布时间:2022-05-27
下一篇:
Python numpy.sum函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap