(images, model, batch_size=64, dims=2048,
                    cuda=False, verbose=False)
return pred_arr
Calculates the activations of the pool_3 layer for all images.

    Params:
    -- images      : Numpy array of dimension (n_images, 3, hi, wi). The values
                     must lie between 0 and 1.
    -- model       : Instance of inception model
    -- batch_size  : the images numpy array is split into batches with
                     batch size batch_size. A reasonable batch size depends
                     on the hardware.
    -- dims        : Dimensionality of features returned by Inception
    -- cuda        : If set to True, use GPU
    -- verbose     : If set to True and parameter out_step is given, the number
                     of calculated batches is reported.
    Returns:
    -- A numpy array of dimension (num images, dims) that contains the
       activations of the given tensor when feeding inception with the
       query tensor.
Calculates the activations of the pool_3 layer for all images.
Calculates the activations of the pool_3 layer for all images .
def get_activations(images, model, batch_size=64, dims=2048,
                    cuda=False, verbose=False):
    """Calculates the activations of the pool_3 layer for all images.

    Params:
    -- images      : Numpy array of dimension (n_images, 3, hi, wi). The values
                     must lie between 0 and 1.
    -- model       : Instance of inception model
    -- batch_size  : the images numpy array is split into batches with
                     batch size batch_size. A reasonable batch size depends
                     on the hardware.
    -- dims        : Dimensionality of features returned by Inception
    -- cuda        : If set to True, use GPU
    -- verbose     : If set to True and parameter out_step is given, the number
                     of calculated batches is reported.
    Returns:
    -- A numpy array of dimension (num images, dims) that contains the
       activations of the given tensor when feeding inception with the
       query tensor.
    """
    model.eval()
    if cuda:
        dtype = torch.cuda.FloatTensor
    else:
        if torch.cuda.is_available():
            print("WARNING: You have a CUDA device, so you should probably set cuda=True")
        dtype = torch.FloatTensor
    #print(dtype)
    d0 = images.shape[0]
    if batch_size > d0:
        print(('Warning: batch size is bigger than the data size. '
               'Setting batch size to data size'))
        batch_size = d0

    n_batches = d0 // batch_size
    n_used_imgs = n_batches * batch_size

    pred_arr = np.empty((n_used_imgs, dims))
    for i in range(n_batches):
        if verbose:
            print('\rPropagating batch %d/%d' % (i + 1, n_batches),
                  end='', flush=True)
        start = i * batch_size
        end = start + batch_size

        batch = images[start:end].type(dtype)#torch.from_numpy(images[start:end]).type(torch.FloatTensor)
        batch = Variable(batch)
        # if cuda:
        #     batch = batch.cuda()
        #print(batch.size(), batch)
        with torch.no_grad():
            pred = model(batch)[0]
        #print(pred.size())

        # If model output is not scalar, apply global spatial average pooling.
        # This happens if you choose a dimensionality not equal 2048.
        if pred.shape[2] != 1 or pred.shape[3] != 1:
            pred = adaptive_avg_pool2d(pred, output_size=(1, 1))
        #print(pred.size())
        pred_arr[start:end] = pred.cpu().data.numpy().reshape(batch_size, -1)
        #print(pred.size())

    if verbose:
        print(' done')

    return pred_arr
def get_activations ( images , model , batch_size = 64 , dims = 2048 , cuda = False , verbose = False ) : model . eval ( ) if cuda : dtype = torch . cuda . FloatTensor else : if torch . cuda . is_available ( ) : print ( "WARNING: You have a CUDA device, so you should probably set cuda=True" ) dtype = torch . FloatTensor #print(dtype) d0 = images . shape [ 0 ] if batch_size > d0 : print ( ( 'Warning: batch size is bigger than the data size. ' 'Setting batch size to data size' ) ) batch_size = d0 n_batches = d0 // batch_size n_used_imgs = n_batches * batch_size pred_arr = np . empty ( ( n_used_imgs , dims ) ) for i in range ( n_batches ) : if verbose : print ( '\rPropagating batch %d/%d' % ( i + 1 , n_batches ) , end = '' , flush = True ) start = i * batch_size end = start + batch_size batch = images [ start : end ] . type ( dtype ) #torch.from_numpy(images[start:end]).type(torch.FloatTensor) batch = Variable ( batch ) # if cuda: #     batch = batch.cuda() #print(batch.size(), batch) with torch . no_grad ( ) : pred = model ( batch ) [ 0 ] #print(pred.size()) # If model output is not scalar, apply global spatial average pooling. # This happens if you choose a dimensionality not equal 2048. if pred . shape [ 2 ] != 1 or pred . shape [ 3 ] != 1 : pred = adaptive_avg_pool2d ( pred , output_size = ( 1 , 1 ) ) #print(pred.size()) pred_arr [ start : end ] = pred . cpu ( ) . data . numpy ( ) . reshape ( batch_size , - 1 ) #print(pred.size()) if verbose : print ( ' done' ) return pred_arr