(images, device=None, batch_size=50, print_every=20)
return preds
Get the output probabilities of images.

    Args:
        images (ndarray): Batch of images of shape (N, H, W, 3).
        device (Device): Torch device object.
        batch_size (int): Batch size for inference using inception model.
        print_every (int): Prints logging variable every n batch inferences.

    Returns:
        ndarray: Batch of probabilities of equal size as number of images input.
Get the output probabilities of images.
Get the output probabilities of images .
def get_predictions(images, device=None, batch_size=50, print_every=20):
    """
    Get the output probabilities of images.

    Args:
        images (ndarray): Batch of images of shape (N, H, W, 3).
        device (Device): Torch device object.
        batch_size (int): Batch size for inference using inception model.
        print_every (int): Prints logging variable every n batch inferences.

    Returns:
        ndarray: Batch of probabilities of equal size as number of images input.
    """
    if device is not None:
        # Avoid unbounded memory usage
        gpu_options = tf.compat.v1.GPUOptions(allow_growth=True,
                                              per_process_gpu_memory_fraction=0.15,
                                              visible_device_list=str(device))
        config = tf.compat.v1.ConfigProto(gpu_options=gpu_options)

    else:
        config = tf.compat.v1.ConfigProto(device_count={'GPU': 0})

    # Inference variables
    batch_size = min(batch_size, images.shape[0])
    num_batches = images.shape[0] // batch_size

    # Get predictions
    preds = []
    with tf.compat.v1.Session(config=config) as sess:
        # Batch input preparation
        inception_utils._get_inception_layer(sess)

        # Define input/outputs of default graph.
        pool3 = sess.graph.get_tensor_by_name('inception_model/pool_3:0')
        w = sess.graph.get_operation_by_name(
            "inception_model/softmax/logits/MatMul").inputs[1]
        logits = tf.matmul(tf.squeeze(pool3, [1, 2]), w)
        softmax = tf.nn.softmax(logits)

        # Predict images
        start_time = time.time()
        for i in range(num_batches):
            batch = images[i * batch_size:(i + 1) * batch_size]

            # curr_image = np.expand_dims(images[i], axis=0)
            pred = sess.run(softmax, {'inception_model/ExpandDims:0': batch})
            preds.append(pred)

            if (i + 1) % min(print_every, num_batches) == 0:
                end_time = time.time()
                print("INFO: Processed image {}/{}...({:.4f} sec/idx)".format(
                    (i + 1) * batch_size, images.shape[0],
                    (end_time - start_time) / (print_every * batch_size)))
                start_time = end_time

    preds = np.concatenate(preds, 0)

    return preds
def get_predictions ( images , device = None , batch_size = 50 , print_every = 20 ) : if device is not None : # Avoid unbounded memory usage gpu_options = tf . compat . v1 . GPUOptions ( allow_growth = True , per_process_gpu_memory_fraction = 0.15 , visible_device_list = str ( device ) ) config = tf . compat . v1 . ConfigProto ( gpu_options = gpu_options ) else : config = tf . compat . v1 . ConfigProto ( device_count = { 'GPU' : 0 } ) # Inference variables batch_size = min ( batch_size , images . shape [ 0 ] ) num_batches = images . shape [ 0 ] // batch_size # Get predictions preds = [ ] with tf . compat . v1 . Session ( config = config ) as sess : # Batch input preparation inception_utils . _get_inception_layer ( sess ) # Define input/outputs of default graph. pool3 = sess . graph . get_tensor_by_name ( 'inception_model/pool_3:0' ) w = sess . graph . get_operation_by_name ( "inception_model/softmax/logits/MatMul" ) . inputs [ 1 ] logits = tf . matmul ( tf . squeeze ( pool3 , [ 1 , 2 ] ) , w ) softmax = tf . nn . softmax ( logits ) # Predict images start_time = time . time ( ) for i in range ( num_batches ) : batch = images [ i * batch_size : ( i + 1 ) * batch_size ] # curr_image = np.expand_dims(images[i], axis=0) pred = sess . run ( softmax , { 'inception_model/ExpandDims:0' : batch } ) preds . append ( pred ) if ( i + 1 ) % min ( print_every , num_batches ) == 0 : end_time = time . time ( ) print ( "INFO: Processed image {}/{}...({:.4f} sec/idx)" . format ( ( i + 1 ) * batch_size , images . shape [ 0 ] , ( end_time - start_time ) / ( print_every * batch_size ) ) ) start_time = end_time preds = np . concatenate ( preds , 0 ) return preds