Beispiel #1
0
 def _load_from_stream(self, stream):
     try:
         obj = numpy.load(stream)
         if isinstance(obj, dict):
             return next(iter(obj.values()))
         return obj
     except Exception as e:
         self.debug("Not a numpy file: %s", e)
         stream.seek(0)
     try:
         return numpy.loadtxt(stream, **self._loadtxt_kwargs)
     except Exception as e:
         self.debug("Not a text file: %s", e)
         stream.seek(0)
     try:
         img = Image.open(stream)
         return numpy.array(img), MODE_COLOR_MAP[img.mode]
     except Exception as e:
         self.debug("Not an image file: %s", e)
         stream.seek(0)
     try:
         with NamedTemporaryFile() as tmpf:
             tmpf.write(stream.read())
             tmpf.seek(0)
             return SndFileMixin.decode_file(tmpf.name)
     except Exception as e:
         self.debug("Not an audio file: %s", e)
         stream.seek(0)
     raise ValueError("Unknown stream type")
Beispiel #2
0
 def _load_from_stream(self, stream):
     try:
         obj = numpy.load(stream)
         if isinstance(obj, dict):
             return next(iter(obj.values()))
         return obj
     except Exception as e:
         self.debug("Not a numpy file: %s", e)
         stream.seek(0)
     try:
         return numpy.loadtxt(stream, **self._loadtxt_kwargs)
     except Exception as e:
         self.debug("Not a text file: %s", e)
         stream.seek(0)
     try:
         img = Image.open(stream)
         return numpy.array(img), MODE_COLOR_MAP[img.mode]
     except Exception as e:
         self.debug("Not an image file: %s", e)
         stream.seek(0)
     try:
         with NamedTemporaryFile() as tmpf:
             tmpf.write(stream.read())
             tmpf.seek(0)
             return SndFileMixin.decode_file(tmpf.name)
     except Exception as e:
         self.debug("Not an audio file: %s", e)
         stream.seek(0)
     raise ValueError("Unknown stream type")
Beispiel #3
0
def mp_run(files, extr):
    try:
        logging.debug("Reading %d files...", len(files))
        loader = SndFileMixin()
        extr.inputs = [loader.decode_file(f) for f in files]
        logging.debug("Extracting features from %d files...", len(files))
        extr.run()
        return extr.outputs
    except:
        logging.exception("Subprocess failed")
Beispiel #4
0
def mp_run(files, extr):
    try:
        logging.debug("Reading %d files...", len(files))
        loader = SndFileMixin()
        extr.inputs = [loader.decode_file(f) for f in files]
        logging.debug("Extracting features from %d files...", len(files))
        extr.run()
        return extr.outputs
    except:
        logging.exception("Subprocess failed")