Ejemplo n.º 1
0
def steps(pipeline):
    pipeline = int(pipeline.split('-')[0])
    steps = utils.get_images('static/img/pipelines/steps/{}'.format(pipeline))
    steps.sort(key=lambda x: int(x[1].split(')')[0]))
    response = jsonify({'success': True, 'steps': steps, 'pipeline': pipeline})
    response.status_code = 200
    return response
Ejemplo n.º 2
0
def take_picture():
    images = get_images()

    if len(images) >= 5:
        os.remove(images[-1])
 
    current_settings = None
    
    try: 
        current_settings = Settings.query.get(1)
    except: 
        pass
    
    if current_settings is not None:
        print("ISO:", current_settings.iso)
        print('Shutter speed', current_settings.shutter_speed)
        
        camera = picamera.PiCamera()
        camera.iso = current_settings.iso
        camera.shutter_speed = current_settings.shutter_speed
    else:
        camera = picamera.PiCamera()

    print('Capturing image')
    camera.capture('./static/camera-images/' + str(int(time.time())) + '.jpg')

    camera.close()
Ejemplo n.º 3
0
    def do_POST(self):
        content_len = int(self.headers.getheader('content-length', 0))
        data = json.loads(self.rfile.read(content_len))

        name = data['repository']['repo_name']
        log.info('Image updated on docker hub: {name}'
                 .format(name=name))

        response = {'state': 'success'}
        if 'callback_url' in data:
            requests.post(data['callback_url'],
                          data=json.dumps(response),
                          headers={'Content-Type': 'application/json'})
            log.debug('Sent reply to callback_url.')

        for image in get_images(self.compose_project):
            if image.options['image'] == name:
                image.pull()
                log.info('...image updated locally.')
                break

        else:
            log.info('No such image: {name}'.format(name=name))
            self.send_response(422)
            self.end_headers()
            return

        self.send_response(200)
        self.end_headers()
        self.wfile.write(json.dumps(response))
Ejemplo n.º 4
0
def set_kernel(args, section):
    if args.image:
        try:
            args.kernel = utils.get_images(args.image)['kernel']
        except KeyError:
            pass

    if args.kernel is None:
        args.kernel = section.get('kernel', None)

    if not args.kernel and not args.kernel_rpm:
        exit(
            "Must specify a linux kernel with --kernel, or a config file default"
        )

    if args.kernel_rpm is not None:
        args.kernel_rpm = os.path.realpath(args.kernel_rpm)
        if not os.path.isfile(args.kernel_rpm):
            raise ValueError("Kernel RPM %r does not exist" %
                             (args.kernel_rpm))
        args.kernel = None
    else:
        args.kernel = os.path.realpath(args.kernel)
        if not os.path.isdir(args.kernel):
            raise ValueError(
                "Kernel path %r is not a directory/does not exist" %
                (args.kernel))
Ejemplo n.º 5
0
def walk_through_dataset(root_folder, depth, start_from=False, plot_evolution=False):
    generator = utils.walk_level(root_folder, depth)
    gens = [[r, f] for r, d, f in generator if len(r.split("/")) == len(root_folder.split("/")) + depth]

    # This boolean controls whether the algorithm will be used on a specific image or not
    if start_from:
        go = False
    else:
        go = True

    for root, files in gens:
        images = utils.get_images(files, root)
        masks = utils.get_masks(files, root)
        cages = utils.get_cages(files, root)
        if not images or not masks or not cages:
            if not images:
                print root, 'has no .png image'
            if not masks:
                print root, 'has no .png mask'
            if not cages:
                print root, 'has no .txt cages'
        else:
            # TODO: FIX TO ALLOW MORE IMAGES
            for image in images:
                if image.spec_name == start_from:
                    go = True
                if not go:
                    continue
                for mask in masks:
                    for cage in cages:
                        print '\nSegmenting', image.root
                        aux_cage = copy.deepcopy(cage)
                        resulting_cage = cac_segmenter.cac_segmenter(image, mask, aux_cage, None,
                                                                     plot_evolution=plot_evolution)
                        evaluate_results(image, cage, mask, resulting_cage, files, root)
Ejemplo n.º 6
0
def args_run(parser):
    section = utils.load_config_file()
    parser.add_argument("image",
                        nargs='?',
                        choices=sorted(utils.get_images()),
                        help="The IB card configuration to use")

    kernel = parser.add_mutually_exclusive_group()
    kernel.add_argument(
        '--kernel',
        help="Path to the top of a compiled kernel source tree to boot",
        default=None)
    kernel.add_argument('--kernel-rpm',
                        help="Path to a kernel RPM to boot",
                        default=None)

    parser.add_argument('--dir',
                        action="append",
                        help="Other paths to map",
                        default=[])
    parser.add_argument('--simx',
                        metavar='SIMX_DEV',
                        action="append",
                        default=[],
                        choices=sorted(get_simx_rdma_devices()),
                        help="Run using simx to create a mlx5 IB device")
    parser.add_argument(
        '--run-shell',
        action="store_true",
        default=False,
        help="Run a shell inside the container instead of invoking kvm")
    parser.add_argument(
        '--pci',
        metavar="PCI_BDF",
        action="append",
        default=[],
        choices=sorted(get_pci_rdma_devices().keys()),
        help="Pass a given PCI bus/device/function to the guest")
    parser.add_argument(
        '--virt',
        metavar="VIRT_DEV",
        action="append",
        default=[],
        choices=sorted(get_virt_rdma_devices()),
        help="Pass a virtual device type-interface format to the guest")
    parser.add_argument(
        '--boot-script',
        help="Path to the custom boot script which will be executed after boot",
        default=None)
    parser.add_argument('--gdbserver',
                        metavar='PORT',
                        type=int,
                        help="TCP port for QEMU's GDB server",
                        default=None)
    parser.add_argument('--nested_pci',
                        metavar='NESTED_PCI',
                        action="append",
                        default=[],
                        help="Provide PCI list for the nested VM")
Ejemplo n.º 7
0
def steps(original, folder):
    filepath = utils.get_filepath(app.config['INPUT_FOLDER'], original)
    if filepath is None:
        return redirect(url_for('index'))
    original = ['/' + filepath, original]
    steps = utils.get_images('static/img/pipelines/steps/{}'.format(folder))
    steps.sort(key=lambda x: int(x[1].split(')')[0]))
    return render_template('steps.html', original=original, steps=steps, folder=folder)
Ejemplo n.º 8
0
def get_hubble_collection(Hubble_collection):

    filename = 'hc'
    url = f'http://hubblesite.org/api/v3/images/{Hubble_collection}'
    all_id = get_id(url)
    images_formats = get_formats_for_hc(url, all_id)

    for image_id in all_id:
        url = f"http://hubblesite.org/api/v3/image/{image_id}"
        response = requests.get(url)
        response.raise_for_status()

        all_links = response.json()
        image_files = all_links["image_files"]

        for image_number, images in enumerate(image_files):
            url = f'https:{images["file_url"]}'
            get_images(image_id, url, image_number, images_formats, filename)
Ejemplo n.º 9
0
 def store_data_per_task(self, train=True):
     folders = self.metaval_character_folders
     self.val_tasks_data_classes = []
     for i in range(self.num_total_val_batches):
         task_folders = random.sample(folders, self.num_classes)
         random.shuffle(task_folders)
         support, query = get_images(task_folders, nb_samples=self.num_samples_per_class)
         data_class_task = Files_per_task(support, query, i)
         self.val_tasks_data_classes.append(data_class_task)
Ejemplo n.º 10
0
def processing(image):
    filepath = utils.get_filepath(app.config['INPUT_FOLDER'], image)
    if filepath is None:
        return redirect(url_for('index'))
    utils.delete_images(app.config['OUTPUT_FOLDER'])
    processing_lib.individual(filepath)
    original = ['/' + filepath, image]
    transformations = utils.get_images(app.config['OUTPUT_FOLDER'])
    transformations.sort(key=lambda x: x[1])
    return render_template('processing.html', original=original, transformations=transformations)
Ejemplo n.º 11
0
def index():
    images = utils.get_images(app.config['INPUT_FOLDER'])
    images.sort(key=lambda x: int(x[1]), reverse=True)
    if request.method == 'POST':
        new_file = request.files.get('file', None)
        if new_file is not None and utils.is_allowed_file(new_file.filename):
            filename = str(len(images) + 1) + '.' + new_file.filename.rsplit('.', 1)[1].lower()
            new_file.save(join(app.config['INPUT_FOLDER'], filename))
            return redirect(url_for('processing', image=filename.split('.')[0]))
    return render_template('index.html', images=images)
Ejemplo n.º 12
0
def main():

    graph = tf.Graph()
    with graph.as_default():
        with gfile.FastGFile(utils.PATH_TO_MERGED_GRAPH, 'rb') as f:
            graph_def = tf.GraphDef()
            graph_def.ParseFromString(f.read())
            tf.import_graph_def(graph_def, name='')

    # input tensor
    image_input = graph.get_tensor_by_name('image_input:0')

    # output tensors
    tensors = [
        "class/final_result", "detect/detection_classes",
        "detect/num_detections", "detect/detection_scores",
        "detect/detection_boxes"
    ]
    tensor_dict = {out: '%s:0' % out for out in tensors}
    tensor_dict = {
        out: graph.get_tensor_by_name(name)
        for out, name in tensor_dict.items()
    }

    # examples
    start = 1003
    examples_number = 500
    examples = pd.read_csv(utils.LABELLING_OUTPUT_PATH)
    examples = examples.sample(frac=1).reset_index(drop=True)
    examples = examples.iloc[start:start + examples_number]

    # categories = pd.read_csv('categories.csv')
    results = []

    with tf.Session(graph=graph) as sess:

        for row_id, row in examples.iterrows():
            image = utils.get_images(pd.Series(row['path_to_image']))[0]
            image = utils.transform_image(image)
            result = sess.run(tensor_dict, {image_input: image})
            result = {key: value[0] for key, value in result.items()}

            classification: np.ndarray = result['class/final_result']
            class_max = np.argmax(classification)
            results.append((class_max, row['label']))
            print(row_id, class_max, row['label'])

    results = pd.DataFrame(results, columns=['result', 'all_label'])
    results.to_csv('result2.csv')
    # results = pd.merge(results, categories)

    print(results)
def home():
    try:

        image_url_array = request.json['image_url_array']
        image_url_array = [
            each_url[1:-1] for each_url in image_url_array[1:-1].split(', ')
        ]

        cache_file_data = open(CACHE_FILE, 'r+')
        cache = json.loads(cache_file_data.read())

        cached_data, rem_image_url_array = get_data_from_cache(
            image_url_array, cache)

        response_value = []
        if (rem_image_url_array):
            saved_image_path_array = get_images(rem_image_url_array)
            # print(saved_image_path_array)
            # print(str(saved_image_path_array))
            # print(json.dumps(saved_image_path_array))
            # print(json.dumps(str(saved_image_path_array)))
            # return 'ok'
            err, question_array = get_questions_from_image(
                saved_image_path_array)
            if err:
                return jsonify({'error': err}), 500
            err, generated_answer_array = get_answer_from_image_and_question(
                saved_image_path_array, question_array)
            if err:
                return jsonify({'error': err}), 500

            for question, answer, image_path in zip(question_array,
                                                    generated_answer_array,
                                                    rem_image_url_array):
                response_value.append({
                    'question': question,
                    'answer': answer,
                    'image_path': image_path
                })

            cache_new_data(response_value, cache, cache_file_data)

            # cache_file_data.close()

        if cached_data: response_value += cached_data
        print(response_value)

        return jsonify({'result': response_value}), 200
    except Exception as e:
        print(e)
        return jsonify({'error': str(e)}), 500
Ejemplo n.º 14
0
def get_ocr_steps(original, folder):
    filepath = utils.get_filepath(app.config['INPUT_FOLDER'], original)
    if filepath is None:
        return redirect(url_for('index'))
    text = request.form.get('text', '')
    steps = utils.get_images('static/img/pipelines/steps/{}'.format(folder))
    steps.sort(key=lambda x: int(x[1].split(')')[0]))
    results = []
    for step in steps:
        result_text, percentage = ocr.compare(text, utils.get_filepath('static/img/pipelines/steps/{}'.format(folder), step[1]))
        results.append({'step': step[1].split('-')[0], 'original': text, 'result': result_text, 'percentage': percentage})

    result_text, percentage = ocr.compare(text, filepath)
    results.insert(0, {'step': 'original', 'original': text, 'result': result_text, 'percentage': percentage})
    return jsonify(results)
Ejemplo n.º 15
0
def main(image=0):
    if image == 0:
        init__file_results()

    images = utils.get_images(config['INPUT_FOLDER'])
    images.sort(key=lambda x: int(x[1]))
    images = images[image:]

    for image in images:
        print('Image {}'.format(image[1]))
        filepath = image[0][1:]
        text = ORIGINAL_TEXTS[image[1]]
        utils.delete_images(config['OUTPUT_FOLDER_PIPELINES'])

        time = default_timer()
        result_text, percentage = ocr.compare(text, filepath)
        time_end = default_timer() - time
        write_file_result(
            [image[1], 'original', percentage, text, result_text, time_end])

        steps, times = processing_lib.pipeline(filepath,
                                               config['TRANSFORMATIONS'])

        pipelines = utils.get_images(config['OUTPUT_FOLDER_PIPELINES'])
        for pipeline in pipelines:
            time = default_timer()
            result_text, percentage = ocr.compare(
                text,
                utils.get_filepath(config['OUTPUT_FOLDER_PIPELINES'],
                                   pipeline[1]))
            time_end = default_timer() - time
            write_file_result([
                image[1], '\r'.join(steps[int(pipeline[1].split('-')[0])]),
                percentage, text, result_text,
                times[int(pipeline[1].split('-')[0])] + time_end
            ])
Ejemplo n.º 16
0
def get_ocr_transformations(image):
    filepath = utils.get_filepath(app.config['INPUT_FOLDER'], image)
    if filepath is None:
        return redirect(url_for('index'))
    text = request.form.get('text', '')
    transformations = utils.get_images(app.config['OUTPUT_FOLDER'])
    results = []
    for transformation in transformations:
        result_text, percentage = ocr.compare(text, utils.get_filepath(app.config['OUTPUT_FOLDER'], transformation[1]))
        results.append({'transformation': transformation[1].split('-')[0], 'original': text, 'result': result_text, 'percentage': percentage})
    results = sorted(results, key=itemgetter('percentage'), reverse=True)

    result_text, percentage = ocr.compare(text, filepath)
    results.insert(0, {'transformation': 'original', 'original': text, 'result': result_text, 'percentage': percentage})
    return jsonify(results)
Ejemplo n.º 17
0
def pipeline(image):
    filepath = utils.get_filepath(app.config['INPUT_FOLDER'], image)
    if filepath is None:
        return redirect(url_for('index'))
    if request.method == 'POST':
        utils.delete_images(app.config['OUTPUT_FOLDER_PIPELINES'])
        list_transformations = request.form.get('list_transformations').split(',')
        processing_lib.pipeline(filepath, list_transformations)
    original = ['/' + filepath, image]
    pipelines = utils.get_images(app.config['OUTPUT_FOLDER_PIPELINES'])
    steps_count = utils.count_folders(app.config['OUTPUT_FOLDER_STEPS'])
    for index in range(1, steps_count + 1):
        if next((x for x in pipelines if int(x[1].split('-')[0]) == index), None) is None:
            pipelines.append(('/static/img/fail.gif', '{}-{}'.format(index, str(uuid.uuid4()).split('-')[0])))
    pipelines.sort(key=lambda x: int(x[1].split('-')[0]))
    return render_template('pipeline.html', original=original, pipelines=pipelines)
Ejemplo n.º 18
0
def get_ocr(image):
    filepath = utils.get_filepath(app.config['INPUT_FOLDER'], image)
    if filepath is None:
        return redirect(url_for('index'))
    text = request.form.get('text', '')
    pipelines = utils.get_images(app.config['OUTPUT_FOLDER_PIPELINES'])
    pipelines.sort(key=lambda x: int(x[1].split('-')[0]))
    results = []
    for pipeline in pipelines:
        result_text, percentage = ocr.compare(text, utils.get_filepath(app.config['OUTPUT_FOLDER_PIPELINES'], pipeline[1]))
        results.append({'pipeline': pipeline[1].split('-')[0], 'original': text, 'result': result_text, 'percentage': percentage})
    results = sorted(results, key=itemgetter('percentage'), reverse=True)

    result_text, percentage = ocr.compare(text, filepath)
    results.insert(0, {'pipeline': 'original', 'original': text, 'result': result_text, 'percentage': percentage})
    return jsonify(results)
Ejemplo n.º 19
0
    def make_data_tensor(self, train=True):
        if train:
            folders = self.metatrain_character_folders
            # number of tasks, not number of meta-iterations. (divide by metabatch size to measure)
            num_total_batches = 200000
        else:
            folders = self.metaval_character_folders
            num_total_batches = 600

        # make list of files
        print('Generating filenames')
        all_filenames = []
        for _ in range(num_total_batches):
            sampled_character_folders = random.sample(folders, self.num_classes)
            random.shuffle(sampled_character_folders)
            labels_and_images = get_images(sampled_character_folders, range(self.num_classes), nb_samples=self.num_samples_per_class, shuffle=False)
            # make sure the above isn't randomized order
            labels = [li[0] for li in labels_and_images]
            filenames = [li[1] for li in labels_and_images]
            all_filenames.extend(filenames)

        # make queue for tensorflow to read from
        filename_queue = tf.train.string_input_producer(tf.convert_to_tensor(all_filenames), shuffle=False)
        print('Generating image processing ops')
        image_reader = tf.WholeFileReader()
        _, image_file = image_reader.read(filename_queue)
        if FLAGS.datasource == 'miniimagenet':
            image = tf.image.decode_jpeg(image_file, channels=3)
            image.set_shape((self.img_size[0],self.img_size[1],3))
            image = tf.reshape(image, [self.dim_input])
            image = tf.cast(image, tf.float32) / 255.0
        else:
            image = tf.image.decode_png(image_file)
            image.set_shape((self.img_size[0],self.img_size[1],1))
            image = tf.reshape(image, [self.dim_input])
            image = tf.cast(image, tf.float32) / 255.0
            image = 1.0 - image  # invert
        num_preprocess_threads = 1 # TODO - enable this to be set to >1
        min_queue_examples = 256
        examples_per_batch = self.num_classes * self.num_samples_per_class
        batch_image_size = self.batch_size  * examples_per_batch
        print('Batching images')
        images = tf.train.batch(
                [image],
                batch_size = batch_image_size,
                num_threads=num_preprocess_threads,
                capacity=min_queue_examples + 3 * batch_image_size,
                )
        all_image_batches, all_label_batches = [], []
        print('Manipulating image data to be right shape')
        for i in range(self.batch_size):
            image_batch = images[i*examples_per_batch:(i+1)*examples_per_batch]

            if FLAGS.datasource == 'omniglot':
                # omniglot augments the dataset by rotating digits to create new classes
                # get rotation per class (e.g. 0,1,2,0,0 if there are 5 classes)
                rotations = tf.multinomial(tf.log([[1., 1.,1.,1.]]), self.num_classes)
            label_batch = tf.convert_to_tensor(labels)
            new_list, new_label_list = [], []
            for k in range(self.num_samples_per_class):
                class_idxs = tf.range(0, self.num_classes)
                class_idxs = tf.random_shuffle(class_idxs)

                true_idxs = class_idxs*self.num_samples_per_class + k
                new_list.append(tf.gather(image_batch,true_idxs))
                if FLAGS.datasource == 'omniglot': # and FLAGS.train:
                    new_list[-1] = tf.stack([tf.reshape(tf.image.rot90(
                        tf.reshape(new_list[-1][ind], [self.img_size[0],self.img_size[1],1]),
                        k=tf.cast(rotations[0,class_idxs[ind]], tf.int32)), (self.dim_input,))
                        for ind in range(self.num_classes)])
                new_label_list.append(tf.gather(label_batch, true_idxs))
            new_list = tf.concat(new_list, 0)  # has shape [self.num_classes*self.num_samples_per_class, self.dim_input]
            new_label_list = tf.concat(new_label_list, 0)
            all_image_batches.append(new_list)
            all_label_batches.append(new_label_list)
        all_image_batches = tf.stack(all_image_batches)
        all_label_batches = tf.stack(all_label_batches)
        all_label_batches = tf.one_hot(all_label_batches, self.num_classes)
        return all_image_batches, all_label_batches
Ejemplo n.º 20
0
def display_images(request):
	# Get existing images
	images = utils.get_images()
	keys = images[images.keys()[0]].keys()

	return render(request, 'manager/images.html', { 'keys': keys, 'images': images })