Exemple #1
0
def _process_detections(detections, path_to_conv_script, restricted=True):
    results = Results()
    local_vars = {
        "detections": detections,
        "results": results,
        }
    source_code = open(path_to_conv_script).read()

    if restricted:
        global_vars = {
            "__builtins__": {
                "str": str,
                "int": int,
                "float": float,
                "max": max,
                "min": min,
                "range": range,
                },
            }
    else:
        global_vars = globals()
        imports = import_modules(source_code)
        global_vars.update(imports)


    execute_python_code(source_code, global_vars, local_vars)

    return results
Exemple #2
0
    def upload(self, annotation_file, loader):
        annotation_importer = Annotation(
            annotation_ir=self.ir_data,
            db_task=self.db_job.segment.task,
            create_callback=self.create,
        )
        self.delete()
        db_format = loader.annotation_format
        with open(annotation_file, 'rb') as file_object:
            source_code = open(
                os.path.join(settings.BASE_DIR,
                             db_format.handler_file.name)).read()
            global_vars = globals()
            imports = import_modules(source_code)
            global_vars.update(imports)

            execute_python_code(source_code, global_vars)

            global_vars["file_object"] = file_object
            global_vars["annotations"] = annotation_importer

            execute_python_code(
                "{}(file_object, annotations)".format(loader.handler),
                global_vars)
        self.create(
            annotation_importer.data.slice(self.start_frame,
                                           self.stop_frame).serialize())
Exemple #3
0
    def dump(self, filename, dumper, scheme, host):
        anno_exporter = Annotation(
            annotation_ir=self.ir_data,
            db_task=self.db_task,
            scheme=scheme,
            host=host,
        )
        db_format = dumper.annotation_format

        with open(filename, 'wb') as dump_file:
            source_code = open(os.path.join(settings.BASE_DIR, db_format.handler_file.name)).read()
            global_vars = globals()
            imports = import_modules(source_code)
            global_vars.update(imports)
            execute_python_code(source_code, global_vars)
            global_vars["file_object"] = dump_file
            global_vars["annotations"] = anno_exporter

            execute_python_code("{}(file_object, annotations)".format(dumper.handler), global_vars)