Пример #1
0
 def __init__(self, hal, device='/var/run/lirc/lircd'):
     """the default lirc socket to listen on is /var/run/lirc/lircd.
     Change that by setting self.irwSocket in setup()"""
     Serializer.__init__(self, hal)
     self.irwSocket = device
     self.protocol = None
     self.open()
Пример #2
0
    def process_arguments(self, arguments):
        self.arguments = arguments
        print("Input Directory: {}".format(self.arguments.input_dir))
        print("Output Directory: {}".format(self.arguments.output_dir))
        self.serializer = None
        if self.arguments.serializer is None and self.arguments.alignments_path is not None:
            ext = os.path.splitext(self.arguments.alignments_path)[-1]
            self.serializer = Serializer.get_serializer_fromext(ext)
            print(self.serializer, self.arguments.alignments_path)
        else:
            self.serializer = Serializer.get_serializer(self.arguments.serializer or "json")
        print("Using {} serializer".format(self.serializer.ext))

        print('Starting, this may take a while...')

        self.output_dir = get_folder(self.arguments.output_dir)
        try:
            self.input_dir = get_image_paths(self.arguments.input_dir)
        except:
            print('Input directory not found. Please ensure it exists.')
            exit(1)

        self.filter = self.load_filter()
        self.process()
        self.finalize()
Пример #3
0
 def __init__(self, hal, host='localhost', port=6419):
     Serializer.__init__(self, hal)
     self.host = host
     self.port = port
     self.protocol = None
     self.openDeferred = None
     self.prevChannel = None
     self.closeTimeout = 5
Пример #4
0
 def __init__(self, hal, device='/dev/denon', outlet=None):
     """default device is /dev/denon"""
     self.mutedVolume = None
     # never close because the Denon sends events
     # by its own if it is operated by other means (IR, front knobs)
     self.surroundIdx = 0
     self.lastSurroundTime = None
     Serializer.__init__(self, hal, outlet)
     self.__port = SerialPort(self, device, reactor)
Пример #5
0
 def __init__(self, hal, host, port=50000, outlet=None):
     Serializer.__init__(self, hal, outlet)
     self.host = host
     self.port = port
     self.protocol = None
     self.mutedVolume = None
     self.answersAsEvent = True
     self.closeTimeout = 2000000
     self.open()
Пример #6
0
 def get_serializer(self):
     """ Set the serializer to be used for loading and saving alignments """
     if not self.args.serializer and self.args.alignments_path:
         ext = os.path.splitext(self.args.alignments_path)[-1]
         serializer = Serializer.get_serializer_from_ext(ext)
         print("Alignments Output: {}".format(self.args.alignments_path))
     else:
         serializer = Serializer.get_serializer(self.args.serializer)
     print("Using {} serializer".format(serializer.ext))
     return serializer
Пример #7
0
    def load(self, swapped):
        serializer = Serializer.get_serializer('json')
        state_fn = ".".join([hdf['state'], serializer.ext]) 
        try:
            with open(str(self.model_dir / state_fn), 'rb') as fp:
                state = serializer.unmarshal(fp.read().decode('utf-8'))
                self._epoch_no = state['epoch_no']
        except IOError as e:
            print('Error loading training info:', e.strerror)
            self._epoch_no = 0
        except JSONDecodeError as e:
            print('Error loading training info:', e.msg)
            self._epoch_no = 0   
        
        (face_A,face_B) = (hdf['decoder_AH5'], hdf['decoder_BH5']) if not swapped else (hdf['decoder_BH5'], hdf['decoder_AH5'])                

        try:
            self.encoder.load_weights(str(self.model_dir / hdf['encoderH5']))
            self.decoder_A.load_weights(str(self.model_dir / face_A))
            self.decoder_B.load_weights(str(self.model_dir / face_B))
            print('loaded model weights')
            return True
        except Exception as e:
            print('Failed loading existing training data.')
            print(e)
            return False                            
Пример #8
0
 def send(self, *args):
     """when applicable ask Denon for current value before sending
     new value"""
     _, msg = self.args2message(*args)
     if msg.encoded in ['MVDOWN', 'MVUP']:
         # the current state is never UP or DOWN, so we just
         # send it without first asking for the old value.
         return self.push(msg)
     else:
         return Serializer.send(self, *args)
Пример #9
0
    def get_serializer(filename, serializer):
        """ Set the serializer to be used for loading and
            saving alignments

            If a filename with a valid extension is passed in
            this will be used as the serializer, otherwise the
            specified serializer will be used """
        logger.debug("Getting serializer: (filename: '%s', serializer: '%s')",
                     filename, serializer)
        extension = os.path.splitext(filename)[1]
        if extension in (".json", ".p", ".yaml", ".yml"):
            logger.debug("Serializer set from file extension: '%s'", extension)
            retval = Serializer.get_serializer_from_ext(extension)
        elif serializer not in ("json", "pickle", "yaml"):
            raise ValueError("Error: {} is not a valid serializer. Use "
                             "'json', 'pickle' or 'yaml'")
        else:
            logger.debug("Serializer set from argument: '%s'", serializer)
            retval = Serializer.get_serializer(serializer)
        logger.verbose("Using '%s' serializer for alignments", retval.ext)
        return retval
Пример #10
0
    def __init__(self, in_queue, queue_size, arguments):
        logger.debug("Initializing %s: (args: %s, queue_size: %s, in_queue: %s)",
                     self.__class__.__name__, arguments, queue_size, in_queue)
        self.batchsize = min(queue_size, 16)
        self.args = arguments
        self.in_queue = in_queue
        self.out_queue = queue_manager.get_queue("patch")
        self.serializer = Serializer.get_serializer("json")
        self.faces_count = 0
        self.verify_output = False
        self.model = self.load_model()
        self.predictor = self.model.converter(self.args.swap_model)
        self.queues = dict()

        self.thread = MultiThread(self.predict_faces, thread_count=1)
        self.thread.start()
        logger.debug("Initialized %s: (out_queue: %s)", self.__class__.__name__, self.out_queue)
Пример #11
0
    def process(self):
        """ Main processing function of the sort tool """

        # Setting default argument values that cannot be set by argparse

        # Set output dir to the same value as input dir
        # if the user didn't specify it.
        if self.args.output_dir.lower() == "_output_dir":
            self.args.output_dir = self.args.input_dir

        # Assigning default threshold values based on grouping method
        if (self.args.final_process == "folders"
                and self.args.min_threshold < 0.0):
            method = self.args.group_method.lower()
            if method == 'face':
                self.args.min_threshold = 0.6
            elif method == 'face-cnn':
                self.args.min_threshold = 7.2
            elif method == 'hist':
                self.args.min_threshold = 0.3

        # If logging is enabled, prepare container
        if self.args.log_changes:
            self.changes = dict()

            # Assign default sort_log.json value if user didn't specify one
            if self.args.log_file_path == 'sort_log.json':
                self.args.log_file_path = os.path.join(self.args.input_dir,
                                                       'sort_log.json')

            # Set serializer based on logfile extension
            serializer_ext = os.path.splitext(
                self.args.log_file_path)[-1]
            self.serializer = Serializer.get_serializer_from_ext(
                serializer_ext)

        # Prepare sort, group and final process method names
        _sort = "sort_" + self.args.sort_method.lower()
        _group = "group_" + self.args.group_method.lower()
        _final = "final_process_" + self.args.final_process.lower()
        self.args.sort_method = _sort.replace('-', '_')
        self.args.group_method = _group.replace('-', '_')
        self.args.final_process = _final.replace('-', '_')

        self.sort_process()
Пример #12
0
    def __init__(self, alignments_file, destination_format, verbose):
        print("\n[ALIGNMENT DATA]")  # Tidy up cli output
        self.alignments_file = alignments_file
        self.verbose = verbose

        self.check_alignments_file_exists()
        self.alignments_format = os.path.splitext(
            self.alignments_file)[1].lower()
        self.destination_format = self.get_destination_format(
            destination_format)

        self.serializer = Serializer.get_serializer_from_ext(
            self.alignments_format)
        self.alignments = self.load_alignments()
        self.count = len(self.alignments)
        self.count_per_frame = {key: len(value)
                                for key, value in self.alignments.items()}

        self.set_destination_serializer()
        if self.verbose:
            print("{} items loaded".format(self.count))
Пример #13
0
 def __init__(self, model_dir, model_name, config_changeable_items,
              no_logs, pingpong, training_image_size):
     logger.debug("Initializing %s: (model_dir: '%s', model_name: '%s', "
                  "config_changeable_items: '%s', no_logs: %s, pingpong: %s, "
                  "training_image_size: '%s'", self.__class__.__name__, model_dir, model_name,
                  config_changeable_items, no_logs, pingpong, training_image_size)
     self.serializer = Serializer.get_serializer("json")
     filename = "{}_state.{}".format(model_name, self.serializer.ext)
     self.filename = str(model_dir / filename)
     self.name = model_name
     self.iterations = 0
     self.session_iterations = 0
     self.training_size = training_image_size
     self.sessions = dict()
     self.lowest_avg_loss = dict()
     self.inputs = dict()
     self.config = dict()
     self.load(config_changeable_items)
     self.session_id = self.new_session_id()
     self.create_new_session(no_logs, pingpong)
     logger.debug("Initialized %s:", self.__class__.__name__)
Пример #14
0
 def save_weights(self):
     model_dir = str(self.model_dir)
     for model in hdf.values():
         backup_file(model_dir, model)
     self.encoder.save_weights(str(self.model_dir / hdf['encoderH5']))
     self.decoder_A.save_weights(str(self.model_dir / hdf['decoder_AH5']))
     self.decoder_B.save_weights(str(self.model_dir / hdf['decoder_BH5']))
     
     print('saved model weights')
     
     serializer = Serializer.get_serializer('json')
     state_fn = ".".join([hdf['state'], serializer.ext])
     state_dir = str(self.model_dir / state_fn)                        
     try:
         with open(state_dir, 'wb') as fp:
             state_json = serializer.marshal({
                 'epoch_no' : self.epoch_no
                  })
             fp.write(state_json.encode('utf-8'))
     except IOError as e:
         print(e.strerror)                   
Пример #15
0
 def __init__(self, hal, device='/dev/steckerleiste'):
     Serializer.__init__(self, hal)
     self.device = device
Пример #16
0
 def set_destination_serializer(self):
     """ set the destination serializer """
     self.serializer = Serializer.get_serializer(self.destination_format)
Пример #17
0
 def lineReceived(self, data):
     Serializer.defaultInputHandler(self, data)
Пример #18
0
 def __init__(self, hal, device='/dev/steckerleiste', outlets=4):
     Serializer.__init__(self, hal)
     self.device = device
     self.outlets = list(
         GembirdOutlet(self, x) for x in range(1, outlets + 1))
Пример #19
0
from lib import Serializer
from tests.sample_objects import *
import math

ser = Serializer.Serializer()
ser.change_form('json')


class TestPrimesJson:
    def test_tuple(self):
        ser.string = '{".list": [1, 2, 3], ".collection_type": "tuple"}'

        assert ser.loads(ser.string) == sample_tuple

    def test_int(self):
        ser.string = '123445'

        assert ser.loads(ser.string) == sample_int

    def test_float(self):
        ser.string = '0.42'
        assert math.isclose(ser.loads(ser.string), sample_float)

    def test_bool(self):
        ser.string = 'true'
        assert ser.loads(ser.string) == sample_bool

    def test_string(self):
        ser.string = '"abacaba"'
        assert ser.loads(ser.string) == sample_string
Пример #20
0
 def __init__(self, hal, host, port=8102, outlet=None):
     Serializer.__init__(self, hal, outlet)
     self.host = host
     self.port = port
     self.protocol = None
Пример #21
0
 def __init__(self, hal, device='/dev/LGPlasma', outlet=None):
     Serializer.__init__(self, hal, outlet)
     self.device = device
     self.videoMuted = None
     self.tvTimeout = 300
     self.connect()
Пример #22
0
    def lineReceived(self, line):
        """we got a full line from Yamaha"""
        msg = Serializer.defaultInputHandler(self.wrapper, line)
        logDebug(self, 'p', 'READ from {}: {}'.format(self.wrapper.name(), repr(line)))
#        msg = YamahaMessage(line)
        self.status[msg.command()] = msg.value()
Пример #23
0
 def __init__(self, hal, device='/dev/LGPlasma', outlet=None):
     Serializer.__init__(self, hal, outlet)
     self.device = device
     self.videoMuted = None
     self.tvTimeout = 300
     self.connect()
Пример #24
0
from lib import Serializer as ser
import json


serializer = ser.Serializer("JSON")
yserializer = ser.Serializer("Yaml")
pserializer = ser.Serializer("PICKLE")
tserializer = ser.Serializer("TOML")

globala = "HI"

class MetaS(type):
    def __new__(cls, *args):
        obj = super(cls, cls).__new__(cls, *args)
        return obj

class Parent:
    def _getAttreasdasd(self):
        print(globala +  "Asdas")
    
class ClassA(Parent,metaclass=MetaS):
    a = range
    def __init__(self):
        self.dict = {"asd": 1}

def wrapper_(func):
    def wrap():
        print("boo!!!!")
        return func() 
    return wrap
Пример #25
0
    def process_arguments(self, arguments):
        self.arguments = arguments
        print("Input Directory: {}".format(self.arguments.input_dir))
        print("Output Directory: {}".format(self.arguments.output_dir))
        print("Filter: {}".format(self.arguments.filter))
        self.serializer = None
        if self.arguments.serializer is None and self.arguments.alignments_path is not None:
            ext = os.path.splitext(self.arguments.alignments_path)[-1]
            self.serializer = Serializer.get_serializer_fromext(ext)
            print(self.serializer, self.arguments.alignments_path)
        else:
            self.serializer = Serializer.get_serializer(
                self.arguments.serializer or "json")
        print("Using {} serializer".format(self.serializer.ext))

        try:
            if self.arguments.rotate_images is not None and self.arguments.rotate_images != "off":
                if self.arguments.rotate_images == "on":
                    self.rotation_angles = range(90, 360, 90)
                else:
                    rotation_angles = [
                        int(angle)
                        for angle in self.arguments.rotate_images.split(",")
                    ]
                    if len(rotation_angles) == 1:
                        rotation_step_size = rotation_angles[0]
                        self.rotation_angles = range(rotation_step_size, 360,
                                                     rotation_step_size)
                    elif len(rotation_angles) > 1:
                        self.rotation_angles = rotation_angles
        except AttributeError:
            pass

        print('Starting, this may take a while...')

        try:
            if self.arguments.skip_existing:
                self.already_processed = get_image_paths(
                    self.arguments.output_dir)
        except AttributeError:
            pass

        self.output_dir = get_folder(self.arguments.output_dir)

        try:
            try:
                if self.arguments.skip_existing:
                    self.input_dir = get_image_paths(self.arguments.input_dir,
                                                     self.already_processed)
                    print('Excluding %s files' % len(self.already_processed))
                else:
                    self.input_dir = get_image_paths(self.arguments.input_dir)
            except AttributeError:
                self.input_dir = get_image_paths(self.arguments.input_dir)
        except:
            print('Input directory not found. Please ensure it exists.')
            exit(1)

        self.filter = self.load_filter()
        self.process()
        self.finalize()
Пример #26
0
 def lineReceived(self, data):
     Serializer.defaultInputHandler(self, data)
Пример #27
0
 def set_destination_serializer(self):
     """ set the destination serializer """
     self.serializer = Serializer.get_serializer(self.dst_format)
Пример #28
0
 def __init__(self, hal, host, port=8102, outlet=None):
     Serializer.__init__(self, hal, outlet)
     self.host = host
     self.port = port
     self.protocol = None
Пример #29
0
 def __init__(self, hal, device='/dev/steckerleiste', outlets=4):
     Serializer.__init__(self, hal)
     self.device = device
     self.outlets = list(GembirdOutlet(self, x) for x in range(1, outlets + 1))
Пример #30
0
 def lineReceived(self, data):
     """nothing special here"""
     Serializer.defaultInputHandler(self, data)
Пример #31
0
from lib import Serializer as ser

serializer = ser.Serializer()

serializer.load("sample.json")

serializer.data()

serializer.load("lambda.json")

serializer.data("Name Asd")

serializer.load("class_a.json")

A = serializer.data()

print(A.dict)