Exemplo n.º 1
0
import torch
import numpy as np

from torch.nn.parallel.data_parallel import DataParallel

from source.utils import get_logger, count_parameters_in_M
from source.losses import *
from source.autoencoders import *
from source.auditors import *

logger = get_logger(__name__)

class _CustomDataParallel(DataParallel):
    """
    DataParallel distribute batches across multiple GPUs

    https://github.com/pytorch/pytorch/issues/16885
    """

    def __init__(self, model):
        super(_CustomDataParallel, self).__init__(model)

    def __getattr__(self, name):
        try:
            return super(_CustomDataParallel, self).__getattr__(name)
        except AttributeError:
            return getattr(self.module, name)


class Model(object):
    """
from source.utils import get_logger

logger = get_logger()


# -----------------------------------------------------------------------------------------------------------

# Function to check if reference & data files are non-empty and within wavelength range

def Ref_Data_is_valid(ref_df,
                      data_df,
                      startNM,
                      stopNM,
                      range_no
                      ):
    """
    :param ref_df: dataFrame of reference diode
    :param data_df: dataFrame of measurement data
    :param startNM: start wavelength [float or int]
    :param stopNM: stop wavelength [float or int]
    :param range_no: number of measurment range to plot / reference correct [int]
    :return: True or False
    """

    if len(ref_df) != 0 and len(data_df) != 0:

        if startNM >= data_df['Wavelength'][0] and \
                startNM >= ref_df['Wavelength'][0] and \
                stopNM <= data_df['Wavelength'][int(len(data_df['Wavelength'])) - 1] and \
                stopNM <= ref_df['Wavelength'][int(len(ref_df['Wavelength'])) - 1]:
            return True