mm_action_prediction/tools/data_support.py [28:70]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
class ExponentialSmoothing:
    """Exponentially smooth and track losses.
    """

    def __init__(self):
        self.value = None
        self.blur = 0.95
        self.op = lambda x, y: self.blur * x + (1 - self.blur) * y

    def report(self, new_val):
        """Adds a new value.
        """
        if self.value is None:
            self.value = new_val
        else:
            self.value = {
                key: self.op(value, new_val[key]) for key, value in self.value.items()
            }
        return self.value


def setup_cuda_environment(gpu_id):
    """Setup the GPU/CPU configuration for PyTorch.
    """
    if gpu_id < 0:
        print("Running on CPU...")
        os.environ["CUDA_VISIBLE_DEVICES"] = ""
        return False
    else:
        print("Running on GPU {0}...".format(gpu_id))
        os.environ["CUDA_VISIBLE_DEVICES"] = str(gpu_id)
    return True


def pretty_print_dict(parsed):
    """Pretty print a parsed dictionary.
    """
    max_len = max(len(ii) for ii in parsed.keys())
    format_str = "\t{{:<{width}}}: {{}}".format(width=max_len)
    print("Arguments:")
    # Sort in alphabetical order and print.
    for key in sorted(parsed.keys()):
        print(format_str.format(key, parsed[key]))
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



mm_action_prediction/tools/support.py [13:58]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
class ExponentialSmoothing:
    """Exponentially smooth and track losses.
    """

    def __init__(self):
        self.value = None
        self.blur = 0.95
        self.op = lambda x, y: self.blur * x + (1 - self.blur) * y

    def report(self, new_val):
        """Add a new score.

        Args:
            new_val: New value to record.
        """
        if self.value is None:
            self.value = new_val
        else:
            self.value = {
                key: self.op(value, new_val[key]) for key, value in self.value.items()
            }
        return self.value


def setup_cuda_environment(gpu_id):
    """Setup the GPU/CPU configuration for PyTorch.
    """
    if gpu_id < 0:
        print("Running on CPU...")
        os.environ["CUDA_VISIBLE_DEVICES"] = ""
        return False
    else:
        print("Running on GPU {0}...".format(gpu_id))
        os.environ["CUDA_VISIBLE_DEVICES"] = str(gpu_id)
        return True


def pretty_print_dict(parsed):
    """Pretty print a parsed dictionary.
    """
    max_len = max(len(ii) for ii in parsed.keys())
    format_str = "\t{{:<{width}}}: {{}}".format(width=max_len)
    print("Arguments:")
    # Sort in alphabetical order and print.
    for key in sorted(parsed.keys()):
        print(format_str.format(key, parsed[key]))
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



