def setUp(self):
        self.num_timestamps = 10
        self.fov = math.pi / 2
        self.image_width = 1000
        self.object_universe = ObjectUniverse(
            num_timestamps=self.num_timestamps)
        self.camera = Camera()

        self.camera.set_actual_position((1,1)).\
                    set_fov_rad(self.fov).\
                    set_num_timestamps(self.num_timestamps).\
                    set_range(50000)

        for timestamp in range(self.camera.get_num_timestamps()):
            self.camera.set_state_of_pan_motor_angle_at_timestamp_rad(
                math.pi / 4, timestamp)

        self.cv = ComputerVision()
        self.image_generator = ImageGenerator(image_width=self.image_width)
        self.camera.set_computer_vision(self.cv).\
                    set_image_generator(self.image_generator)

        self.viewable_objects = [
            StationaryObject((2, 1 + math.tan(math.pi / 8))),
            StationaryObject((1 + math.tan(math.pi / 8), 2)),
            StationaryObject((10000, 1.1)),
            StationaryObject((1.1, 10000)),
        ]
        self.object_universe.add_viewable_objects(self.viewable_objects)
        self.object_universe.add_camera(self.camera)

        self.d = self.image_width / (2 * math.tan(self.fov / 2))
        self.theta = math.pi / 8
def main():
    # Parameters
    images_directory = './data/images'
    categories_file = '../categories.json'

    if not os.path.isdir(images_directory):
        loader = ImageLoader(output_directory=images_directory,
                             categories_file=categories_file)
        loader.load()

    experience_file = './data/experience-new-ratings.csv'
    number_of_experiences, ids_for_categories = load_experience_data(
        experience_file, n_ratings=2)

    number_of_true_images_for_provider = 8
    number_of_noise_images_for_provider = 2
    number_of_images_in_collage = 6
    output_directory = './data/generated-data'
    features_original_images_file = './data/images/features-images-1'

    image_generator = ImageGenerator(images_directory, categories_file,
                                     features_original_images_file)
    image_generator.generate(
        number_of_true_images_for_provider=number_of_true_images_for_provider,
        number_of_noise_images_for_provider=number_of_noise_images_for_provider,
        number_of_images=number_of_experiences,
        ids=ids_for_categories,
        number_of_images_in_collage=number_of_images_in_collage,
        output_directory=output_directory)

    evaluator = Evaluator(output_directory,
                          features_file='./data/features-generated-data')
    evaluator.visualize(show='ratings')
    evaluator.classify()
Exemple #3
0
def generate_output_file(result, output_path, args):
    """
    Generate output file
    """
    if args.type == 'rp':
        ImageGenerator.save_recurrence_plot(result.recurrence_matrix_reverse,
                                            output_path)
    elif args.type == 'rqa':
        with open(output_path, 'w') as f:
            for line in result.to_string():
                f.write(line)
Exemple #4
0
    def __init__(self):
#=============================================================================
# Please select one of the valid ids, currently between 0 and 3
# 0: 'artificial_no_noise': Produce the artificial image and its analytical and numerical slope and curvatures without noise
# 1: 'artificial_noise': Same as 0 with noise
# 2: 'landscape': Compute numerical slope and curvature for Souris landscape
# 3: 'speed': Runtime over large basic image
# 4: 'difference': Shows difference between numerical and analytical results for IART
#     Assumes that all plosts exist already, so please choice 1!
# 5:  r_squared
        self.analyses = ['artificial_no_noise','artificial_noise','landscape','speed','difference']
        analysis_id = 1
# Display Tiff images using matplotlib.pyplot as they are created (True/False)
# Note that Choice 3 (speed) has auto_plot turned off unless it is changed further down
# and Choice 4 (difference) only provides pyplot figures as output, and does so regardless of auto_plot setting
        self.auto_plot = True
# Number of aggregations that are requested, maximum window size will be 2^num_aggre
        self.num_aggre = 6
#=============================================================================
        self.analysis = self.analyses[analysis_id]
        self.dtype = config.work_dtype
        if self.analysis == self.analyses[0]:
            self.img_dir = 'img_artificial/'
            self.image_size = 512
            self.img_gen = ImageGenerator(self.img_dir)
            self.img_gen.auto_plot = self.auto_plot
            self.multi_gauss = self.img_gen.multi_gauss(self.image_size,0,0)
        elif self.analysis == self.analyses[1]:
            self.img_dir = 'img_artificial/'
            self.image_size = 512
            self.img_gen = ImageGenerator(self.img_dir)
            self.img_gen.auto_plot = self.auto_plot
            self.multi_gauss = self.img_gen.multi_gauss(self.image_size,0,0.01)
        elif self.analysis == self.analyses[2]:
            self.img_dir = 'img_souris/'
            self.image_size = 500
            self.img_gen = ImageGenerator(self.img_dir)
            self.img_gen.auto_plot = self.auto_plot
            self.landscape = self.img_gen.landscape(self.img_dir+'SourisSmall.tif')
        elif self.analysis == self.analyses[3]:
            self.auto_plot = False
            self.img_dir = 'img_dome/'
            self.image_size = 5000
            self.img_gen = ImageGenerator(self.img_dir)
            self.img_gen.auto_plot = self.auto_plot
            self.dome = self.img_gen.dome(self.image_size)
        elif self.analysis == self.analyses[4]:
            self.img_dir = 'img_artificial/'
            self.image_size = 512
            self.img_gen = ImageGenerator(self.img_dir)
            self.img_gen.auto_plot = self.auto_plot
            self.landscape = self.img_gen.landscape(self.img_dir+'multi_random_id0_n10.tif')
Exemple #5
0
def run_test():
    keywords = ['apple', 'blue', '안녕', 'money']
    #keywords = ['monday']

    for crawl_type in ['sync', 'async']:
        datas = []
        for keyword in keywords:
            data = run_wrk(keyword, crawl_type)
            datas.append(data)
        extracted_datas, website = extract_data(datas, keywords)
        image_generator = ImageGenerator(crawl_type)
        image_name = 'static/' + crawl_type + '_image.png'
        image_generator.generate_and_save_image(extracted_datas,
                                                website,
                                                image_name,
                                                latency_until=100)
Exemple #6
0
 def setUp(self) -> None:
     self.fd, self.name = tempfile.mkstemp(suffix=".db")
     self.sql_executor = SQLExecutor(self.name, debug=True)
     self.storage = StatStorage.make_with_executor(self.sql_executor)
     self.image_generator = ImageGenerator()
     routes = RoutesFactory.make_routes(self.storage, self.image_generator,
                                        RequestHandler)
     self.app = AppFactory.make_app(routes)
Exemple #7
0
def show_image_sample(generator, transition):
    image_generator = ImageGenerator(generator, transition)

    image_current, image_next = image_generator(generator.device.device.id)

    image_current.to_cpu()
    image_next.to_cpu()

    viewer.show_image(image_current.data[0][0], is_gray=True)
    viewer.show_image(image_next.data[0][0], is_gray=True)
Exemple #8
0
def img_filename_motivation():
    """
    Returns the number of the images from the motivation. It can be change if we want to modify them
    """
    # The image numbers of our motivation images
    img_nums = img_num_motivation

    # Initialise an image generator
    img_dir = 'images/val/images/'
    img_class_map_file = 'images/val/val.txt'
    class_file = 'images/val/synset_words.txt'
    image_generator = ImageGenerator(img_dir, img_class_map_file, class_file)
    
    # Get a path and label for each of our images
    img_filenames = list()
    
    for img in img_nums:
        filename=image_generator.get_image_filename(img)
        img_filenames.append(filename)
    
    return img_filenames
Exemple #9
0
def images_motivation(dnn_daemon):
    """
    Plots the images from the motivation section
    """
   # The image numbers of our motivation images
    img_nums = img_num_motivation

    # Initialise an image generator
    img_dir = 'images/val/images/'
    img_class_map_file = 'images/val/val.txt'
    class_file = 'images/val/synset_words.txt'
    image_generator = ImageGenerator(img_dir, img_class_map_file, class_file)

    # Get a path and label for each of our images
    img_paths = list()
    img_labels = list()
    for img in img_nums:
        path, label = image_generator.get_image_data(img)
        img_paths.append(path)
        img_labels.append(label)

    return img_paths
Exemple #10
0
    def run(self):
        np.random.seed(self.config['seed'])

        image_dict = {}
        for i,exppriment_parameters in enumerate(self.experiment_parameters_list):
            print(exppriment_parameters)
            (train_data, probe_data, train_update_sets, test_update_sets,  test_set)=DataExtractor().get_data()
            shadow_model=TrainShadow(exppriment_parameters).get_trained_model(train_data, test_set)
            train_deltas=TrainUpdateModels('train',exppriment_parameters).get_update_dataset(probe_data, train_update_sets, shadow_model)
            test_deltas=TrainUpdateModels('test',exppriment_parameters).get_update_dataset(probe_data, test_update_sets, shadow_model)
            (generator, encoder)=TrainGan(train_deltas,train_update_sets, exppriment_parameters).get_GAN()
            generated_images=ImageGenerator(exppriment_parameters).get_images(test_update_sets,test_deltas, encoder, generator)
            Utils().add_images_to_dict(3,image_dict,generated_images, exppriment_parameters)
            print (f'finished running experiment {i+1} out of {len(self.experiment_parameters_list)}')

        plot_dict(image_dict, len(self.experiment_parameters_list))
        Utils().plot_update(test_update_sets[1])
        Utils().plot_generated(generated_images[1])

        return generated_images
def up_down_selection():
   while True:
      dir = os.path.join(args.root, cases[k])
      result, img = process_dir(dir,  ImageGenerator(dir))
      if result == __PREVIOUS_CASE__:
         k=k-1
         if k<0:
            k = len(cases)-1
      elif result==__NEXT_CASE__:
         k = k + 1
         # if k == len(cases):
         #    print('finished')
         #    break
      else:
         with open('annotation.txt', 'a') as f:
            f.write(",".join([name(parent(img)), img]) + '\n')
         print(img,' is validated')
         k = k + 1
         if k == len(cases):
            k = 0
Exemple #12
0
def save_sample_image(trainer):
    updater = trainer.updater
    g_optimizer = updater.get_optimizer('g_optimizer')
    t_optimizer = updater.get_optimizer('t_optimizer')

    generator = g_optimizer.target
    transition = t_optimizer.target

    image_generator = ImageGenerator(generator, transition)

    image_current, image_next = image_generator(generator.device.device.id)

    image_current.to_cpu()
    image_next.to_cpu()

    iterator = trainer.updater.get_iterator('main')
    filename_current = 'intermediate/epoch-{}-current.jpg'.format(
        iterator.epoch)
    filename_next = 'intermediate/epoch-{}-next.jpg'.format(iterator.epoch)

    print('image array: ', image_current.data[0][0][0])
    pyplot.imsave(filename_current, image_current.data[0][0], cmap='gray')
    pyplot.imsave(filename_next, image_next.data[0][0], cmap='gray')
Exemple #13
0
from images2gif import writeGif
from image_generator import ImageGenerator
from PIL import Image
import os


class Something(object):
    pass


if __name__ == '__main__':
    args = Something()
    args.fontfile = '/Users/timoeemelikoola/Downloads/Cardo/Cardo-Regular.ttf'
    imgs = []
    for i in xrange(20):
        ig = ImageGenerator({"text": str(i), "line": str(i)}, args)
        ig.generate()
        ig.save()
        imgs.append(Image.open(ig.file_name))

    size = (150, 150)
    for im in images:
        im.thumbnail(size, Image.ANTIALIAS)
    filename = "images/my_gif.GIF"
    writeGif(filename, images, duration=0.2)
from images2gif import writeGif
from image_generator import ImageGenerator
from PIL import Image
import os


class Something(object):
    pass

if __name__ == '__main__':
    args = Something()
    args.fontfile = '/Users/timoeemelikoola/Downloads/Cardo/Cardo-Regular.ttf'
    imgs = []
    for i in xrange(20):
        ig = ImageGenerator({"text": str(i), "line": str(i)}, args)
        ig.generate()
        ig.save()
        imgs.append(Image.open(ig.file_name))

    size = (150, 150)
    for im in images:
        im.thumbnail(size, Image.ANTIALIAS)
    filename = "images/my_gif.GIF"
    writeGif(filename, images, duration=0.2)
Exemple #15
0
                    tmp_targets = np.array(targets)
                    inputs = []
                    targets = []
                    yield preprocess_input(tmp_inp), tmp_targets


# In[6]:

path_prefix = 'VOC2007/JPEGImages/'
#path_prefix = '../../frames/'
# BATCH 11 is the maximum
#gen = Generator(gt, bbox_util, 11, path_prefix,
#                train_keys, val_keys,
#                (input_shape[0], input_shape[1]), do_crop=False)
#
gen = ImageGenerator(gt, bbox_util, 9, (input_shape[0], input_shape[1]),
                     train_keys, val_keys, path_prefix)
# In[7]:

model = SSD300(input_shape, num_classes=NUM_CLASSES)
model.load_weights('weights_SSD300.hdf5', by_name=True)

# In[8]:

freeze = [
    'input_1', 'conv1_1', 'conv1_2', 'pool1', 'conv2_1', 'conv2_2', 'pool2',
    'conv3_1', 'conv3_2', 'conv3_3', 'pool3'
]  #,
#           'conv4_1', 'conv4_2', 'conv4_3', 'pool4']

for L in model.layers:
    if L.name in freeze:
        'min_size': 222.0,
        'max_size': 276.0,
        'aspect_ratios': [1.0, 1.0, 2.0, 1 / 2.0, 3.0, 1 / 3.0]
    },
    {
        'layer_width': 1,
        'layer_height': 1,
        'num_prior': 6,
        'min_size': 276.0,
        'max_size': 330.0,
        'aspect_ratios': [1.0, 1.0, 2.0, 1 / 2.0, 3.0, 1 / 3.0]
    },
]

priors = create_prior_box(image_shape[0:2], box_configs, variances)
bounding_box_utils = BoundingBoxUtility(num_classes, priors)
ground_truth_data = XML_preprocessor(data_path + 'Annotations/').data

keys = sorted(ground_truth_data.keys())
num_train = int(round(training_data_ratio * len(keys)))
train_keys = keys[:num_train]
validation_keys = keys[num_train:]
num_val = len(validation_keys)

image_generator = ImageGenerator(ground_truth_data, bounding_box_utils,
                                 batch_size, data_path + 'JPEGImages/',
                                 train_keys, validation_keys, image_shape[:2])

gen = image_generator.flow(True)
next(gen)
Exemple #17
0
class SlidingWindowComparison():
    
    def __init__(self):
#=============================================================================
# Please select one of the valid ids, currently between 0 and 3
# 0: 'artificial_no_noise': Produce the artificial image and its analytical and numerical slope and curvatures without noise
# 1: 'artificial_noise': Same as 0 with noise
# 2: 'landscape': Compute numerical slope and curvature for Souris landscape
# 3: 'speed': Runtime over large basic image
# 4: 'difference': Shows difference between numerical and analytical results for IART
#     Assumes that all plosts exist already, so please choice 1!
# 5:  r_squared
        self.analyses = ['artificial_no_noise','artificial_noise','landscape','speed','difference']
        analysis_id = 1
# Display Tiff images using matplotlib.pyplot as they are created (True/False)
# Note that Choice 3 (speed) has auto_plot turned off unless it is changed further down
# and Choice 4 (difference) only provides pyplot figures as output, and does so regardless of auto_plot setting
        self.auto_plot = True
# Number of aggregations that are requested, maximum window size will be 2^num_aggre
        self.num_aggre = 6
#=============================================================================
        self.analysis = self.analyses[analysis_id]
        self.dtype = config.work_dtype
        if self.analysis == self.analyses[0]:
            self.img_dir = 'img_artificial/'
            self.image_size = 512
            self.img_gen = ImageGenerator(self.img_dir)
            self.img_gen.auto_plot = self.auto_plot
            self.multi_gauss = self.img_gen.multi_gauss(self.image_size,0,0)
        elif self.analysis == self.analyses[1]:
            self.img_dir = 'img_artificial/'
            self.image_size = 512
            self.img_gen = ImageGenerator(self.img_dir)
            self.img_gen.auto_plot = self.auto_plot
            self.multi_gauss = self.img_gen.multi_gauss(self.image_size,0,0.01)
        elif self.analysis == self.analyses[2]:
            self.img_dir = 'img_souris/'
            self.image_size = 500
            self.img_gen = ImageGenerator(self.img_dir)
            self.img_gen.auto_plot = self.auto_plot
            self.landscape = self.img_gen.landscape(self.img_dir+'SourisSmall.tif')
        elif self.analysis == self.analyses[3]:
            self.auto_plot = False
            self.img_dir = 'img_dome/'
            self.image_size = 5000
            self.img_gen = ImageGenerator(self.img_dir)
            self.img_gen.auto_plot = self.auto_plot
            self.dome = self.img_gen.dome(self.image_size)
        elif self.analysis == self.analyses[4]:
            self.img_dir = 'img_artificial/'
            self.image_size = 512
            self.img_gen = ImageGenerator(self.img_dir)
            self.img_gen.auto_plot = self.auto_plot
            self.landscape = self.img_gen.landscape(self.img_dir+'multi_random_id0_n10.tif')
                                    
    def compute_multi(self,img_gen,num_aggre):
        with SlidingWindow(img_gen) as slide_window:
            print('img_gen: ',self.img_gen)
            slide_window.auto_plot = self.auto_plot
            slide_window.initialize_dem()
            slide_window.aggregate_dem(1)
            slide_window.dem_slope()
            for num_loc in range(2,num_aggre+1):
                slide_window.aggregate_dem(1)
                slide_window.dem_slope()
                slide_window.dem_profile()
                slide_window.dem_tangential()
                slide_window.dem_contour()
                slide_window.dem_proper_profile()
                slide_window.dem_proper_tangential()
 
    def speed_numbers(self,img_gen_fn,num_aggre):
        time_array = np.zeros([num_aggre-1,4])
        with SlidingWindow(img_gen_fn) as slide_window:
            slide_window.auto_plot = self.auto_plot
            slide_window.initialize_dem()
            time_start = time.time_ns()
            i = 0
            time_start = time.time_ns()
            slide_window.aggregate_dem()
            time0 = time.time_ns() - time_start
            print('time0: ',time0)
            time_start = time.time_ns()
            for num_aggre_loc in range(2,num_aggre+1):
                slide_window.aggregate_dem()
                time_array[i,0] = time.time_ns() - time_start
                time_start = time.time_ns()
                slide_window.dem_slope()
                time_array[i,1] = time.time_ns() - time_start
                time_start = time.time_ns()
                slide_window.dem_profile()
                time_array[i,2] = time.time_ns() - time_start
                time_start = time.time_ns()
                slide_window.dem_tangential()
                time_array[i,3] = time.time_ns() - time_start
                time_start = time.time_ns()
                i += 1
            print('============================================================')
            print('Aggregation [from w=2 to w=4, w=4 to w=8, w=8 to w=16, w=16 to w=32, and w=32 to w=64]')
            print(time_array[:,0])
            print()
            print('slope [w=4, w=8, w=16, w=32, w=64]')
            print(time_array[:,1])
            print()
            print('profile [w=4, w=8, w=16, w=32, w=64]')
            print(time_array[:,2])
            print()
            print('tangential [w=4, w=8, w=16, w=32, w=64]')
            print(time_array[:,3])
            print('============================================================')            
        return time_array

    def remove_frame_iart(self,arr,w):
        shift = int(w/2)
        out_array = np.empty((arr.shape[0]-w+1,arr.shape[1]-w+1))
        height = out_array.shape[0]
        width = out_array.shape[1]
        for j in range(height):
            for i in range(width):
                out_array[j,i] = arr[j+shift,i+shift]
        return out_array
    
    def plot_differences(self,fn_trunc,fn_trunc_analytical):
        base_name = os.path.basename(fn_trunc).split('.')[0]
        quant_min = 0.1
        quant_max = 0.9
        for analysis in ('_slope','_profile','_tangential'):
            for num_agg_loc in range (2,self.num_aggre+1):
                w = int(2**num_agg_loc)
                file_name = self.img_dir+base_name+analysis+'_w='+str(w)+'.tif'
                with rasterio.open(file_name) as img:
                    array_0 = img.read(1)
                    file_name_analytical = self.img_dir+base_name+analysis+'.tif'
                with rasterio.open(file_name_analytical) as img:
                    array_1 = self.remove_frame_iart(img.read(1),w)
    
                plt.figure()
                array_diff = array_0-array_1
                low = np.quantile(array_diff,quant_min)
                array_diff[array_diff < low] = low
                high = np.quantile(array_diff,quant_max)
                array_diff[array_diff > high] = high
                shift = int(round(array_diff.shape[0]/50))
                plt.text(0,-4*shift,'Difference from analytical for '+file_name)
                plt.text(0,-shift,'min: '+str(round(np.amin(array_diff),3))+' max: '+str(round(np.amax(array_diff),3)))
                plt.imshow(array_diff,'gray_r')
Exemple #18
0
from ssd import SSD300
from utils.prior_box_creator import PriorBoxCreator
from image_generator import ImageGenerator

num_classes = 21
model = SSD300()
image_shape = model.input_shape[1:]
box_creator = PriorBoxCreator(model)
prior_boxes = box_creator.create_boxes()

root_prefix = '../datasets/VOCdevkit/VOC2007/'
ground_data_prefix = root_prefix + 'Annotations/'
image_prefix = root_prefix + 'JPEGImages/'

ground_truth_manager = XMLParser(ground_data_prefix, background_id=None)
ground_truth_data = ground_truth_manager.get_data()

prior_boxes = flatten_prior_boxes(prior_boxes)
prior_boxes = add_variances(prior_boxes)
print('WTF')
bbox_util = BBoxUtility(num_classes, prior_boxes)

result = bbox_util.assign_boxes(ground_truth_data['000007.jpg'])
train_keys, val_keys = split_data(ground_truth_data, training_ratio=.8)
image_generator = ImageGenerator(ground_truth_data, bbox_util, 10, (300, 300),
                                 train_keys, val_keys, image_prefix)
data = next(image_generator.flow(mode='train'))

# test the differences here between you bbox_util
# why can't you train with this ?
def train(sgru_model, loss_func, optim_func, image_rgb_real, args):

    # Join the log directory with the experiment name
    output_dir = os.path.join(args.output_dir, args.name)
    vgg_ckpt = os.path.join(args.data_dir, 'vgg_19.ckpt')

    # Load VGG variables
    vgg_init_fn = slim.assign_from_checkpoint_fn(
        vgg_ckpt, slim.get_model_variables('vgg_19'))

    # Add an op to initialize the variables.
    init_op = tf.global_variables_initializer()

    # Tell tensorflow not to hog all gpu memory and to multithread
    tf_config = tf.ConfigProto(inter_op_parallelism_threads=args.num_cpus,
                               intra_op_parallelism_threads=args.num_cpus)
    tf_config.gpu_options.allow_growth = True

    with tf.Session(config=tf_config) as sess:

        # Summary operations for tensorboard
        summary_op = tf.summary.merge_all()
        writer = tf.summary.FileWriter(output_dir, graph=sess.graph)

        # Initialize all variables
        sess.run(init_op)

        # Initialize VGG variables (these were reset during global initialization)
        vgg_init_fn(sess)

        losses = []

        image_dir = os.path.join(args.data_dir, 'images')
        image_generator = ImageGenerator(image_dir, args.num_cpus)

        image_bw_op, image_rgb_op = image_generator.load_images()

        for epoch in range(args.epochs):

            for image_num in range(image_generator.num_images):

                image_bw, image_rgb = sess.run([image_bw_op, image_rgb_op])

                feed_dict = {
                    sgru_model.image_bw: image_bw,
                    image_rgb_real: image_rgb
                }
                out_list = [
                    sgru_model.images_rgb_fake, loss_func, optim_func,
                    summary_op
                ]
                images_rgb_fake_out, loss, _, summary = sess.run(
                    out_list, feed_dict=feed_dict)

                # Report to tensorboard all the summaries at the current timestep
                writer.add_summary(
                    summary, epoch * image_generator.num_images + image_num)

                print('Epoch {}, image number: {}, loss: {}'.format(
                    epoch, image_num, loss))

                losses.append(loss)

                if image_num % args.save_every == 0:
                    image_dir = os.path.join(output_dir, 'images')
                    if not os.path.isdir(image_dir):
                        os.mkdir(image_dir)
                    image_fname = os.path.join(
                        image_dir, '{}_{}.jpg'.format(epoch, image_num))
                    save_images(image_fname, images_rgb_fake_out, image_rgb,
                                image_bw)
                    sgru_model.save(os.path.join(output_dir, 'model.ckpt'))
Exemple #20
0
 def __init__(self):
     self.img_generator = ImageGenerator()
Exemple #21
0
        'min_size': 168.0,
        'max_size': 222.0,
        'aspect_ratios': [1.0, 1.0, 2.0, 1 / 2.0, 3.0, 1 / 3.0]
    },
    {
        'layer_width': 3,
        'layer_height': 3,
        'num_prior': 6,
        'min_size': 222.0,
        'max_size': 276.0,
        'aspect_ratios': [1.0, 1.0, 2.0, 1 / 2.0, 3.0, 1 / 3.0]
    },
    {
        'layer_width': 1,
        'layer_height': 1,
        'num_prior': 6,
        'min_size': 276.0,
        'max_size': 330.0,
        'aspect_ratios': [1.0, 1.0, 2.0, 1 / 2.0, 3.0, 1 / 3.0]
    },
]
variances = [0.1, 0.1, 0.2, 0.2]
priors = create_prior_box(image_shape[0:2], box_configs, variances)
num_classes = 21
bounding_box_utils = BoundingBoxUtility(num_classes, priors)
data_path = '../datasets/VOCdevkit/VOC2007/'
batch_size = 16
ground_truth_data = XML_preprocessor(data_path + 'Annotations/').data
image_generator = ImageGenerator(ground_truth_data, bounding_box_utils,
                                 batch_size, data_path + 'JPEGImages')
Exemple #22
0
 def _set_object_stats_processor_in_image_renderer(self):
     if type(ImageGenerator()) in self._element_renderers:
         self._element_renderers[type(
             ImageGenerator())].set_object_stats_processor(
                 self.object_stats_processor)
Exemple #23
0
        # update the image TODO could have been done better
        self.update_image()

    def update_image(self) -> None:
        self.imageGenerator.generate()

    # update the message to send daily
    def update_message(self) -> None:
        self.messageGenerator.update()
        self.message = messageGenerator.get_message()

    # start the bot
    def run(self) -> int:
        self.logger.info("Polling BOT.")
        self.updater.start_polling()

        # Run the BOT until you press Ctrl-C or the process receives SIGINT,
        # SIGTERM or SIGABRT. This should be used most of the time, since
        # start_polling() is non-blocking and will stop the BOT gracefully.
        self.updater.idle()
        return 0


if __name__ == "__main__":
    TOKEN = get_token()
    messageGenerator = MessageGenerator()
    imageGenerator = ImageGenerator()
    BOT = Bot(TOKEN, messageGenerator, imageGenerator)
    BOT.run()
Exemple #24
0
def inference(dnn_daemon, img_nums, model_names, n_img_to_infer=5):
    """
    Allows to do inference using a list of images and models.
    """
    
    # Check all models are available
    for model in model_names:
        if not model_available(dnn_daemon, model):
            print("ERROR: Model", model, "not availale. Exiting.")
            sys.exit()

    # Initialise an image generator
    img_dir = 'images/val/images/'
    img_class_map_file = 'images/val/val.txt'
    class_file = 'images/val/synset_words.txt'
    image_generator = ImageGenerator(img_dir, img_class_map_file, class_file)

    # Get a path and label for each of our images
    img_paths = list()
    img_labels = list()
    for img in img_nums:
        path, label = image_generator.get_image_data(img)
        img_paths.append(path)
        img_labels.append(label)

    # Infer each image with each model, get the results
    # results: dict, mapping (img_num, model) to (inference_times, prediciton)
    print("Running inference on Jetson...")
    img_model_to_results = dict()
    img_model_to_img = []
    img_model_to_models = []
    img_model_to_inference = []
    img_model_to_prediction = []
    img_model_to_results = []
    
    if(len(model_names) is 0):
        print("Any model was selected!!!")
        return img_model_to_img, img_model_to_models, img_model_to_results
    
    percentage_of_each_execution=100/(len(img_paths)*len(model_names))
    counter=0
    first_time=0
    for img_num, path in enumerate(img_paths):
        img_model_to_inference = []
        img_model_to_img.append("Image " + `img_num`)
        for model in model_names:
            results = dnn_daemon.inference(model, [path], 1)
            inference_time, prediction_vals, prediction_classes = results
            inference_time = inference_time[0]
            ordered_prediction = convert_prediction(prediction_vals[0],
                                                    prediction_classes[0],
                                                    image_generator.class_names)
            #img_model_to_results[(img_num, model)] = (inference_time, ordered_prediction)
            
            if first_time is 0:
                img_model_to_models.append(model)
                
            img_model_to_inference.append(inference_time)
            #img_model_to_prediction.append(ordered_prediction)
            counter=counter+1
            print(percentage_of_each_execution*counter, "%\n")
            
        img_model_to_results.append(img_model_to_inference)
        first_time=first_time+1
        
    #print("All the images has been inferenced! ")
    return img_model_to_img, img_model_to_models, img_model_to_results
         k = k + 1
         # if k == len(cases):
         #    print('finished')
         #    break
      else:
         with open('annotation.txt', 'a') as f:
            f.write(",".join([name(parent(img)), img]) + '\n')
         print(img,' is validated')
         k = k + 1
         if k == len(cases):
            k = 0

if __name__ == '__main__':
   parser = argparse.ArgumentParser(description='Annotate 3d files from 2d projected volumes')
   parser.add_argument('--root', default='samples')
   args = parser.parse_args()
   cases = set(os.listdir(args.root))
   cases_processed = set([line.split(",")[0] for line in open("annotation.txt", "r").readlines()])
   cases = cases.difference(cases_processed)
   cases = list(cases)
   k=0

   for k in tqdm(range(len(cases)), total=len(cases)):
      dir = os.path.join(args.root, cases[k])
      image_generator = ImageGenerator(dir)
      result, img = process_dir(dir,  image_generator)
      assert result==__VALIDATE_IMG__
      with open('annotation.txt', 'a') as f:
         image_generator.export(img, "samples/{name}.ply".format(name=name(parent(img))))
         f.write(",".join([name(parent(img)), img]) + '\n')
ground_truth_manager = XMLParser(ground_data_prefix,
                                 background_id=None,
                                 class_names=classes)
ground_truth_data = ground_truth_manager.get_data()
print('Number of ground truth samples:', len(ground_truth_data.keys()))
train_keys, validation_keys = split_data(ground_truth_data, training_ratio=.8)

prior_box_manager = PriorBoxManager(prior_boxes,
                                    box_scale_factors=[.1, .1, .2, .2],
                                    num_classes=num_classes)

image_generator = ImageGenerator(ground_truth_data,
                                 prior_box_manager,
                                 batch_size,
                                 image_shape[0:2],
                                 train_keys,
                                 validation_keys,
                                 image_prefix,
                                 vertical_flip_probability=0,
                                 horizontal_flip_probability=0.5)

model_names = ('../trained_models/model_checkpoints/' +
               'weights.{epoch:02d}-{val_loss:.2f}.hdf5')
model_checkpoint = ModelCheckpoint(model_names,
                                   monitor='val_loss',
                                   verbose=1,
                                   save_best_only=False,
                                   save_weights_only=True)
learning_rate_schedule = ReduceLROnPlateau(monitor='val_loss',
                                           factor=0.1,
                                           patience=10,
class TestImageGenerator(unittest.TestCase):
    def setUp(self):
        self.num_timestamps = 10
        self.fov = math.pi / 2
        self.image_width = 1000
        self.object_universe = ObjectUniverse(
            num_timestamps=self.num_timestamps)
        self.camera = Camera()

        self.camera.set_actual_position((1,1)).\
                    set_fov_rad(self.fov).\
                    set_num_timestamps(self.num_timestamps).\
                    set_range(50000)

        for timestamp in range(self.camera.get_num_timestamps()):
            self.camera.set_state_of_pan_motor_angle_at_timestamp_rad(
                math.pi / 4, timestamp)

        self.cv = ComputerVision()
        self.image_generator = ImageGenerator(image_width=self.image_width)
        self.camera.set_computer_vision(self.cv).\
                    set_image_generator(self.image_generator)

        self.viewable_objects = [
            StationaryObject((2, 1 + math.tan(math.pi / 8))),
            StationaryObject((1 + math.tan(math.pi / 8), 2)),
            StationaryObject((10000, 1.1)),
            StationaryObject((1.1, 10000)),
        ]
        self.object_universe.add_viewable_objects(self.viewable_objects)
        self.object_universe.add_camera(self.camera)

        self.d = self.image_width / (2 * math.tan(self.fov / 2))
        self.theta = math.pi / 8

    def test_d_calculation_for_image_generator(self):
        self.camera.get_image_generator(
        ).get_x_for_all_inview_objects_for_all_camera_time()
        self.assertEqual(self.d, self.image_generator.d)

    def test_theta_calculation_for_image_generator(self):
        self.camera.get_image_generator(
        ).get_x_for_all_inview_objects_for_all_camera_time()
        self.assertAlmostEqual(
            -self.theta,
            self.image_generator._get_theta_rad(self.viewable_objects[0], 0))
        self.assertAlmostEqual(
            self.theta,
            self.image_generator._get_theta_rad(self.viewable_objects[1], 0))

    def test_get_x_for_all_inview_objects_for_all_camera_time(self):

        r = self.image_generator.get_x_for_all_inview_objects_for_all_camera_time(
        )

        for timestamp in range(self.camera.get_num_timestamps()):
            self.assertAlmostEqual(r[timestamp][self.viewable_objects[0]],
                                   -self.d * math.tan(math.pi / 8))
            self.assertAlmostEqual(r[timestamp][self.viewable_objects[1]],
                                   self.d * math.tan(math.pi / 8))

    def test_get_x_for_distant_objects_at_edge_of_view_remain_in_image_width(
            self):

        r = self.image_generator.get_x_for_all_inview_objects_for_all_camera_time(
        )

        for obj in self.viewable_objects:
            x = r[0][obj]
            self.assertLess(abs(x), self.image_width / 2)
        if args.destination is not None:
            np.savetxt(args.destination, depth, delimiter=",", fmt="%s")
    else:
        print("Playing camera feed. Press \'q\' to quit")
        while True:
            bgr, depth = depth_live_generator.generate()
            cv2.imshow("Video", bgr)
            cv2.imshow("Depth", depth)
            key = cv2.waitKey(1)
            if key == ord('c') and args.destination is not None:
                np.savetxt(args.destination, depth, delimiter=",", fmt="%s")
            if key == ord('q'):
                break

elif args.generator == "ImageGenerator":
    image_generator = ImageGenerator(args.image)
    rgb, depth = image_generator.generate()
    print(rgb.shape)

elif args.generator == "VideoLiveGenerator":
    video_live_generator = VideoLiveGenerator(1)
    rgb, depth = video_live_generator.generate()
    print(rgb.shape)

    if args.play:
        print("Playing camera feed. Press \'q\' to quit")
        while True:
            rgb, _ = video_live_generator.generate()
            cv2.imshow("Live video", cv2.cvtColor(rgb, cv2.COLOR_RGB2BGR))
            key = cv2.waitKey(1)
            if key == ord('q'):
layer_scale, box_arg = 0, 780
box_coordinates = prior_boxes[layer_scale][box_arg, :, :]
image_path = '../images/'
image_key = '007040.jpg'
box_creator.draw_boxes(image_path + image_key, box_coordinates)

data_path = '../datasets/VOCdevkit/VOC2007/'
ground_truths = XMLParser(data_path + 'Annotations/').get_data()
prior_box_manager = PriorBoxAssigner(prior_boxes, ground_truths)
assigned_boxes = prior_box_manager.assign_boxes()
prior_box_manager.draw_assigned_boxes(image_path, image_shape[0:2], image_key)
batch_size = 7
train_keys, validation_keys = split_data(assigned_boxes, training_ratio=.8)

assigned_image_generator = ImageGenerator(assigned_boxes, batch_size,
                                          image_shape[0:2], train_keys,
                                          validation_keys,
                                          data_path + 'JPEGImages/')

transformed_image = next(assigned_image_generator.flow(mode='demo'))[0]
transformed_image = np.squeeze(transformed_image[0]).astype('uint8')
original_image = read_image(data_path + 'JPEGImages/' + validation_keys[0])
original_image = resize_image(original_image, image_shape[0:2])
plt.figure(1)
plt.subplot(121)
plt.title('Original image')
plt.imshow(original_image)
plt.subplot(122)
plt.title('Transformed image')
plt.imshow(transformed_image)
plt.show()
Exemple #30
0
 def add_image_generator_if_none(self):
     if self.image_generator is None:
         self.set_image_generator(ImageGenerator())
     return self
Exemple #31
0
training_split = .8
do_random_crop = False
num_classes = 2
dataset_name = 'imdb'
input_shape = (48, 48, 3)
images_path = '../datasets/imdb_crop/'
log_file_path = 'log_files/gender_training.log'
trained_models_path = '../trained_models/gender_models/simple_CNN'

# data loader
data_loader = DataLoader(dataset_name)
ground_truth_data = data_loader.get_data()
train_keys, val_keys = split_data(ground_truth_data, training_split)
image_generator = ImageGenerator(ground_truth_data, batch_size,
                                input_shape[:2],
                                train_keys, val_keys, None,
                                path_prefix=images_path,
                                vertical_flip_probability=0,
                                do_random_crop=do_random_crop)

# model parameters/compilation
model = simple_CNN(input_shape, num_classes)
model.compile(optimizer='adam',
            loss='categorical_crossentropy',
            metrics=['accuracy'])
model.summary()

# model callbacks
csv_logger = CSVLogger(log_file_path, append=False)
model_names = trained_models_path + '.{epoch:02d}-{val_acc:.2f}.hdf5'
model_checkpoint = ModelCheckpoint(model_names,
                                   monitor='val_loss',
training_split = .8
do_random_crop = False
num_classes = 2
dataset_name = 'imdb'
input_shape = (48, 48, 3)
images_path = '../datasets/imdb_crop/'
log_file_path = 'log_files/gender_training.log'
trained_models_path = '../trained_models/gender_models/simple_CNN'

# data loader
data_loader = DataLoader(dataset_name)
ground_truth_data = data_loader.get_data()
train_keys, val_keys = split_data(ground_truth_data, training_split)
image_generator = ImageGenerator(ground_truth_data, batch_size,
                                input_shape[:2],
                                train_keys, val_keys, None,
                                path_prefix=images_path,
                                vertical_flip_probability=0,
                                do_random_crop=do_random_crop)

# model parameters/compilation
model = simple_CNN(input_shape, num_classes)
model.compile(optimizer='adam',
            loss='categorical_crossentropy',
            metrics=['accuracy'])
model.summary()

# model callbacks
csv_logger = CSVLogger(log_file_path, append=False)
model_names = trained_models_path + '.{epoch:02d}-{val_acc:.2f}.hdf5'
model_checkpoint = ModelCheckpoint(model_names,
                                   monitor='val_loss',