import numbers
import torch


def extract_item(x):
    """Extract value from single value tensor."""
    if isinstance(x, numbers.Number):
        return x
    elif isinstance(x, torch.Tensor):
        return x.item()
    else:
        raise ValueError('Unknown type: {}'.format(type(x)))