def __init__(self, 
              content_img_addr, 
              style_img_addr, 
              img_width = 224, 
              img_height = 224):
     
     self.img_width = img_width
     self.img_height = img_height
     
     ### get content image, style image and initiate generated image
     self.content_img = utils.get_image(content_img_addr, img_width, img_height)
     self.style_img = utils.get_image(style_img_addr, img_width, img_height)
     self.gen_img = utils.generate_noise_image(self.content_img, img_width, img_height, noise_ratio=0.6)
     
     ### identify weight used for calculating total loss
     self.style_loss_weight = STYLE_LOSS_WEIGHT
     self.style_weight_trend = STYLE_WEIGHT_TREND
     self.content_loss_weight = CONTENT_LOSS_WEIGHT
     
     ### identify layers that represent style and content
     self.content_layers = CONTENT_LAYERS
     self.style_layers = STYLE_LAYERS
     
     ### identify image inputs
     with tf.variable_scope('inputs', reuse=tf.AUTO_REUSE) as scope:
         self.img_input = tf.get_variable(name='img_input',
                                         shape=([1,self.img_width,self.img_height,3]),
                                         dtype=tf.float32,
                                         initializer=tf.zeros_initializer())
         
     ### setup learning parameters
     self.learning_rate = LEARNING_RATE
     self.global_step = tf.Variable(0, trainable=False, name='global_step')
     self.training_epoch = TRAINING_EPOCH
Exemplo n.º 2
0
    def visualize(self, batch, return_image=False):
        self.eval()
        _, _, H_org, W_org = batch["meta"]["shape"]
        batch_dict = self.get_input(batch)
        targets_preds = self(batch_dict["imageList"])[0]
        annList_gt = batch["annList"][0]
        annList_pred = au.targets2annList(
            targets_preds,
            shape=(H_org, W_org),
            image_id=batch["meta"]["image_id"][0])
        # Resize
        W_img, H_img = targets_preds.size
        images_given = batch["images"].tensors[:, :, :H_img, :W_img]

        images = F.interpolate(images_given,
                               size=(H_org, W_org),
                               mode="nearest")

        pred_image = ut.get_image(images, annList=annList_pred, denorm="bgr")
        pred_image_blacked = ut.get_image(images * 0, annList=annList_pred)
        gt_image = ut.get_image(images, annList=annList_gt, denorm="bgr")

        result = np.concatenate([pred_image, gt_image], axis=2)

        return {
            "gt_image": gt_image,
            "pred_image": pred_image,
            "pred_image_blacked": pred_image_blacked
        }
def main():  
    # Load model
    model = load_model(MODEL_PATH, custom_objects={'AdaIN': AdaIN})

    # Get content image
    content = get_image(CONTENT_PATH, resize=False)
    content = preprocess(content)
    content = np.expand_dims(content, axis=0)

    # Get style image
    style = get_image(STYLE_PATH, resize=False)
    style = preprocess(style)
    style = np.expand_dims(style, axis=0)

    # Set alpha Value
    alpha = tf.convert_to_tensor(ALPHA)  # 0 < alpha <= 1
    alpha = np.expand_dims(alpha, axis=0)

    # Do inference
    y = model.predict([content, style, alpha])[0]

    # Convert output array to image
    y = np.squeeze(y, axis=0)
    y = deprocess(y)
    img = array_to_img(y)

    # Show image
    img.show(command='fim')
Exemplo n.º 4
0
    def batch_gen(self, path, batch_size, crop_size):
        content_path, mask_path = get_file_paths(path)

        while True:
            index = random.sample(range(1, len(content_path)), batch_size)
            try:
                offset_h = random.randint(0, (2448 - crop_size[0]))
                offset_w = random.randint(0, (2448 - crop_size[1]))
                offset = (offset_h, offset_w)

                contents = [
                    vgg_sub_mean(
                        random_crop(get_image(content_path[i]), offset,
                                    crop_size)) for i in index
                ]
                masks = [
                    mask_preprocess(
                        random_crop(get_image(mask_path[i]), offset,
                                    crop_size)) for i in index
                ]

                contents = np.asarray(contents, dtype=np.float32)
                masks = np.asarray(masks, dtype=np.uint8)

            except Exception as err:
                print("\nError: {}".format(err))
                continue

            yield contents, masks
Exemplo n.º 5
0
def image():
    uuid_val = request.cookies.get("uuid")

    print("UUID Cookie: ", uuid_val)
    # If the user has never been authenticated
    if (uuid_val is None or uuid_val not in images):
        # Assign user a uuid value
        uuid_val = str(uuid.uuid4())
        uuid_val = uuid_val.replace("-", "")

        # Get image and description pair
        images[uuid_val] = get_image()
    print("uuid_val: ", uuid_val)

    # Get a list of all prev words user has seen or empty list if none
    prev_words = users.get(uuid_val, [])

    word = get_word()[0]
    while word in prev_words:
        word = get_word()[0]

    prev_words.append(word)

    # Get prev img and desc for the user
    img_list = images[uuid_val]

    print("Prev words: ", prev_words)
    print("len(prev_words): ", len(prev_words))
    # Change image after 10 words
    if len(prev_words) % 10 == 0:
        print("Entered if")
        prev_img = images[uuid_val][0]
        img_list = get_image()
        print("img_list: ", img_list)
        print("prev_img: ", prev_img)
        # import pdb; pdb.set_trace()
        while prev_img == img_list[0]:
            img_list = get_image()
        images[uuid_val] = img_list
    users[uuid_val] = prev_words
    img_list = images[uuid_val]
    to_speech(word=word, save_to="static/audio/", filename=word)

    img_path = "images/" + img_list[0]
    audio_path = "./audio/" + word + ".mp3"
    img_desc = img_list[1]

    print("Description: ", img_list[1])

    response = make_response(url_for('static', filename=img_path))

    response.headers["img_description"] = img_desc
    response.headers["word"] = word
    response.headers["translation"] = translation(word)["translatedText"]
    response.headers["audio_file"] = url_for('static', filename=audio_path)
    response.set_cookie("uuid", value=uuid_val)

    return response
Exemplo n.º 6
0
 def find_the_emulator_game(self):
     image = get_image("new-super-mario-bros-find-emu-game.png", self.emulator)
     coordinates = pyautogui.locateCenterOnScreen(image)
     if coordinates is None:  # pixels not found
         image = get_image("new-super-mario-bros-enabled.png", self.emulator)
     # activate the emulator
     x, y = coordinates[0], coordinates[1]
     pyautogui.moveTo(x, y, self.duration)
     pyautogui.click()
     time.sleep(1)
Exemplo n.º 7
0
def x_interpolate(path1, path2):
    x0 = get_image(path1, 64, 64)
    x1 = get_image(path2, 64, 64)
    x_line = []
    for idx in range(11):
        x_tmp = x0*idx*0.1+x1*(10-idx)*0.1
        x_line.append(x_tmp)
    x_line = np.stack((x_line[0], x_line[1], x_line[2], x_line[3],
                             x_line[4], x_line[5], x_line[6], x_line[7],
                             x_line[8], x_line[9], x_line[10]))
    return x_line
Exemplo n.º 8
0
def main():
    if args.mode == 'train':
        content_path, mask_path = get_file_paths(args.image_path)    
        content_path.sort()
        mask_path.sort()
        for path in content_path:
            split(get_image(path), path, mode='sat')
        for path in mask_path:
            split(get_image(path), path, mode='mask')
    elif args.mode == 'validation':
        content_path, _ = get_file_paths(args.image_path)    
        content_path.sort()
        for path in content_path:
            split(get_image(path), path, mode='sat')
Exemplo n.º 9
0
    def run(self):
        iter_counter = 0
        start_time = time.time()
        for e in range(self.args.epochs):
            shuffle(self.data_files)

            sample_files = self.data_files[0:self.args.sample_size]
            sample = [
                get_image(file,
                          128,
                          is_crop=self.args.is_crop,
                          resize_w=self.args.image_size,
                          is_grayscale=0) for file in sample_files
            ]
            sample_images = np.array(sample).astype(np.float32)
            print("[*] Sample images updated! time per epoch: {}".format(
                time.time() - start_time))

            batch_idxs = min(len(self.data_files),
                             self.args.train_size) // self.args.batch_size

            start_time = time.time()
            for idx in range(0, batch_idxs):
                batch_files = self.data_files[idx *
                                              self.args.batch_size:(idx + 1) *
                                              self.args.batch_size]
                batch = [
                    get_image(file,
                              128,
                              is_crop=self.args.is_crop,
                              resize_w=self.args.image_size,
                              is_grayscale=0) for file in batch_files
                ]
                batch_images = np.array(batch).astype(np.float32)
                batch_z = np.random.normal(loc=0.0,
                                           scale=1.0,
                                           size=(self.args.sample_size,
                                                 self.args.z_dim)).astype(
                                                     np.float32)

                g_err, d_err = self.gan.train(batch_images, batch_z)
                print("Epoch: [%2d/%2d] [%4d/%4d], d_loss: %.8f, g_loss: %.8f" \
                    % (e, self.args.epochs, idx, batch_idxs, d_err, g_err))

                iter_counter += 1
                if np.mod(iter_counter, self.args.sample_step) == 0:
                    img = self.gan.generate(self.sample_seed)
                    tl.visualize.save_images(
                        img, [8, 8], './{}/train_{:02d}_{:04d}.png'.format(
                            self.args.sample_dir, e, idx))
Exemplo n.º 10
0
    def shoggoth(img_num):
        image = get_image(img_num, in_dir)
        # Wykrycie narożników kartki, skorygowanie perspektywy oraz wycięcie kartki.
        image_perspective_operations, sPoints, tPoints = perspective_operations(
            image)
        # Usunięcie kratek z kartki tak, żeby zostały widoczne tylko słowa
        image_remove_lines_operations = removeLines(
            image_perspective_operations)
        image_checkered_operations = checkered_operations(
            image_remove_lines_operations)
        # Wykrycie słów
        image_detect_words = detect_words_operations(
            image_checkered_operations)
        # Wykrycie indeksów
        image_crop_numbers, cropped_numbers = crop_numbers(
            image_detect_words, image_perspective_operations)
        # Podział na cyfry
        image_crop_digits = crop_digits(cropped_numbers, image)

        cropped_rectangles = crop_small_rectangles(image_detect_words)
        mask = paint_lines(cropped_rectangles)
        mask = prepare_mask(mask)
        new_img = move_to_original_coords(mask, sPoints, tPoints,
                                          image.shape[:2])
        save_image(img_num, new_img, "png", out_dir)

        return image_crop_digits
Exemplo n.º 11
0
def train_products_keywords(products):
    """
    Поиск с помощью OpenVINO слов на каждом изображении в базе
    Добавление найденных слов в столбец keywords в датафрейм с продуктами
    :param products: датарфейм или часть датафрейма с продуктами, для которых необходимо получить слова
    :return: датафрейм с найденными словами для каждого изображения в столбце keywords
    """
    logging.info('Поиск и добавление в датафрейм слов по каждому изображению')
    products['keywords'] = products['vendor'] + ' ' + products['model']
    products['keywords'] = products['keywords'].str.replace(
        'мл', '').str.lower().str.split()
    http = requests.Session()
    http.mount("https://", utils.adapter)

    # загрузка модели OpenVINO
    text_spotting_net = TextSpotting().train_network()
    i = 0
    for index, row in products.iterrows():
        image = utils.get_image(row['picture'], http)
        image = image.convert('RGB')
        row['keywords'] = row['keywords'] + text_spotting_net.search_text(
            image)

        i += 1
        if i % 10 == 0:
            print(i)
            logging.info(f'Обработано строк: {i}')

    return products
Exemplo n.º 12
0
 def __getitem__(self, idx):
     picture_url = self.products.iloc[idx]['picture']
     image = utils.get_image(picture_url, self.http)
     image = image.convert('RGB')
     if self.transform:
         image = self.transform(image)
     return image
Exemplo n.º 13
0
def extract_to(path, cursor, limitportipo=100, crop=True):
    tipo_counter = Counter()
    try:
        os.mkdir(path)
    except FileExistsError:
        pass
    for linha in cursor:
        _id = linha['_id']
        ncms = linha.get('metadata').get('carga').get('ncm')
        ncms_encontrados = set()
        for ncm in ncms:
            posicao = ncm.get('ncm')[:4]
            ncms_encontrados.add(posicao)
        if len(ncms_encontrados) == 1:  # Achou 1 e somente 1 posição ncm
            posicao = list(ncms_encontrados)[0]
            if tipo_counter[posicao] < limitportipo:
                image = get_image(linha, crop=crop)
                if image:
                    sub_path = os.path.join(path, posicao)
                    try:
                        os.mkdir(sub_path)
                    except FileExistsError:
                        pass
                    filename = str(_id) + '.jpg'
                    image.save(os.path.join(sub_path, filename))
                    del image
                    tipo_counter[posicao] += 1
Exemplo n.º 14
0
def save_data_list(inpath, outpath, filenames):

    for size in IMG_SIZES:
        print('Processing images of size %d' % size)

        cnt = 0
        images = np.ndarray(shape=(len(filenames), size, size, 3), dtype=np.uint8)
        for idx, key in enumerate(filenames):
            f_name = '%s/%s.jpg' % (inpath, key)
            img = get_image(f_name, LOAD_SIZE, is_crop=False)
            img = img.astype('uint8')
            img = img.astype('uint8')

            if size != LOAD_SIZE:
                img = scipy.misc.imresize(img, [size, size], 'bicubic')
            images[idx, :, :, :] = np.array(img)

            cnt += 1
            if cnt % 100 == 0:
                print('\rLoad %d......' % cnt, end="", flush=True)

        print('Images processed: %d', len(filenames))

        outfile = outpath + str(size) + 'images.pickle'
        joblib.dump(images, outfile)
        print('save to: ', outfile)
Exemplo n.º 15
0
def save_data_list(inpath, outpath, filenames):
    hr_images = []
    lr_images = []
    lr_size = int(LOAD_SIZE / LR_HR_RETIO)
    cnt = 0
    for key in filenames:
        f_name = '%s/%s.jpg' % (inpath, key)
        img = get_image(f_name, LOAD_SIZE, is_crop=False)
        img = img.astype('uint8')
        hr_images.append(img)
        lr_img = resize(img, [lr_size, lr_size], order=3)
        lr_images.append(lr_img)
        cnt += 1
        if cnt % 100 == 0:
            print('Load %d......' % cnt)
    #
    print('images', len(hr_images), hr_images[0].shape, lr_images[0].shape)
    #
    outfile = outpath + str(LOAD_SIZE) + 'images.pickle'
    with open(outfile, 'wb') as f_out:
        pickle.dump(hr_images, f_out)
        print('save to: ', outfile)
    #
    outfile = outpath + str(lr_size) + 'images.pickle'
    with open(outfile, 'wb') as f_out:
        pickle.dump(lr_images, f_out)
        print('save to: ', outfile)
Exemplo n.º 16
0
    def extractRealFeatrue():
        f_data = glob(os.path.join(conf.data_dir, conf.dataset, "*"))
        n_iters = int(len(f_data) / conf.n_batch)

        for idx in range(0, n_iters):
            f_batch = f_data[idx * conf.n_batch:(idx + 1) * conf.n_batch]
            data_batch = [
                get_image(f,
                          conf.n_img_pix,
                          is_crop=conf.is_crop,
                          resize_w=conf.n_img_out_pix,
                          is_grayscale=conf.is_gray) for f in f_batch
            ]
            img_batch = np.array(data_batch).astype(np.float32)

            if conf.is_gray:
                s, h, w = img_batch.shape
                img_batch = img_batch.reshape(s, h, w, n_channel)

            l_featrue = sess.run(e_feature, feed_dict={g_net: img_batch})

            for i in range(len(l_featrue)):
                n_idx = 0
                f_df_real = open(
                    checkpoint_dir + '/' + str(i) + '_x_feature.csv', 'a')
                for j in range(1, l_featrue[i].shape[0]):
                    f_df_real.write(
                        str(n_idx) + ', ' + f_batch[j] +
                        ', ' + str(l_featrue[i][n_idx].tolist()).replace(
                            "[", "").replace("]", "") + '\n')
                    n_idx += 1
                f_df_real.close()
Exemplo n.º 17
0
 def manifoldD():
     f_data = glob(os.path.join(conf.data_dir, conf.dataset, "*"))
     shuffle(f_data)
     f_batch = f_data[0:conf.n_batch]
     x_test = [
         get_image(f,
                   conf.n_img_pix,
                   is_crop=conf.is_crop,
                   resize_w=conf.n_img_out_pix,
                   is_grayscale=conf.is_gray) for f in f_batch
     ]
     x_test = np.array(x_test).astype(np.float32)
     if conf.is_gray:
         s, h, w = x_test.shape
         x_test = x_test.reshape(s, h, w, n_channel)
     step = int(conf.n_batch / 2)
     for i in range(step):
         d_mnfd = [None] * 64
         d_mnfd[0] = x_test[i]
         d_mnfd[63] = x_test[i + step]
         for j in range(1, 63):
             d_mnfd[j] = d_mnfd[0] + ((d_mnfd[63] - d_mnfd[0]) / 63 * j)
         d_intp = sess.run(d_img, feed_dict={g_net: d_mnfd})
         save_image(
             d_intp, os.path.join(checkpoint_dir,
                                  str(i) + 'mnfd_anal_D.png'))
Exemplo n.º 18
0
def main(argv):
    pattern = "/gdata/CelebA/Img/img_align_celeba/*.jpg"
    files = glob(pattern)
    assert len(files) > 0

    shuffle(files)

    outfile = './data/CelebA_train_' + str(IMSIZE) + '.tfrecords'
    writer = tf.python_io.TFRecordWriter(outfile)

    for i, f in enumerate(files):
        print(i)
        image = get_image(f, IMSIZE, is_crop=True, resize_w=IMSIZE)
        image = colorize(image)
        assert image.shape == (IMSIZE, IMSIZE, 3)
        image += 1.
        image *= (255. / 2.)
        image = image.astype('uint8')

        image_raw = image.tostring()

        label = 0
        if i % 1 == 0:
            print(i)
        example = tf.train.Example(features=tf.train.Features(feature={
            'height': _int64_feature(IMSIZE),
            'width': _int64_feature(IMSIZE),
            'depth': _int64_feature(3),
            'image_raw': _bytes_feature(image_raw),
            'label': _int64_feature(label)
        }))
        writer.write(example.SerializeToString())

    writer.close()
Exemplo n.º 19
0
    def train(self, config):
        tf.global_variables_initializer().run()
        start_time = time.time()
        if self.load(self.checkpoint_dir):
            print("""Loading existing model""")
        else:
            print("""Initalizing new model""")

        for epoch in range(config.epoch):
            data = dataset_files(config.dataset)
            np.random.shuffle(data)
            batch_idx = min(len(data), config.train_size) // self.batch_size
            for idx in range(batch_idx):
                batch_files = data[idx * config.batch_size: (idx + 1) * config.batch_size]
                batch = [get_image(batch_file, self.image_size) for batch_file in batch_files]
                batch_images = np.array(batch).astype(np.float32)
                masks = np.ones([config.batch_size, config.image_size, config.image_size, 3])
                masks[:, 16:48, 16:48, :] = 0.0

                for i in range(D_ITERATIONS):
                    _, d_loss, summary_str = self.sess.run(
                        [self.d_optim, self.d_loss, self.d_summary],
                        feed_dict={self.images: batch_images, self.masks: masks})
                    self.writer.add_summary(summary_str, self.global_step.eval())

                for i in range(G_ITERATIONS):
                    _, g_loss, summary_str = self.sess.run(
                        [self.g_optim, self.g_loss, self.g_summary],
                        feed_dict={self.images: batch_images, self.masks: masks})
                    self.writer.add_summary(summary_str, self.global_step.eval())
                    print("Epoch: [{:2d}] [{:4d}/{:4d}] time: {:4.4f}, d_loss: {:.8f}, g_loss: {:.8f}".format(
                        epoch, idx, batch_idx, time.time() - start_time, d_loss, g_loss))

                if idx % 10 == 0:
                    self.save(config.checkpoint_dir, self.global_step.eval())
Exemplo n.º 20
0
    def get_sample_data(self, config):
        """Set up the inputs and labels of sample images.
        Samples are created periodically during training.
        """
        if config.dataset == 'mnist':
            sample_inputs = self.data_X[0:self.sample_num]
            sample_labels = self.data_y[0:self.sample_num]
        else:
            sample_files = self.data[0:self.sample_num]
            sample = [
                get_image(sample_file,
                          input_height=self.input_height,
                          input_width=self.input_width,
                          resize_height=self.output_height,
                          resize_width=self.output_width,
                          crop=self.crop,
                          grayscale=self.grayscale)
                for sample_file in sample_files
            ]
            if self.grayscale:
                sample_inputs = np.array(sample).astype(np.float32)[:, :, :,
                                                                    None]
            else:
                sample_inputs = np.array(sample).astype(np.float32)

        sample_z = np.random.uniform(-1, 1, size=(self.sample_num, self.z_dim))
        sample_feed_dict = {
            self.z: sample_z,
            self.inputs: sample_inputs,
        }

        if config.dataset == 'mnist':
            sample_feed_dict.update({self.y: sample_labels})

        return sample_feed_dict
def main(argv):
    pattern = "/scratch/nharness/Library/RAW/*TIF"
    files = glob(pattern)
    assert len(files) > 0
    assert len(files) < 1000000, len(files)
    shuffle(files)

    outfile = '/home/nharness/idcgans/datasets/patents' + str(IMSIZE) + '.tfrecords'
    writer = tf.python_io.TFRecordWriter(outfile)

    for i, f in enumerate(files):
        print i
        image = get_image(f, IMSIZE, is_crop=True, resize_w=IMSIZE)
        image = colorize(image)
        assert image.shape == (IMSIZE, IMSIZE, 3)
        image += 1.
        image *= (255. / 2.)
        image = image.astype('uint8')
        #print image.min(), image.max()
        # from pylearn2.utils.image import save
        # save('foo.png', (image + 1.) / 2.)
        image_raw = image.tostring()
        label = 0
        if i % 1 == 0:
            print i, '\t',label
        example = tf.train.Example(features=tf.train.Features(feature={
            'height': _int64_feature(IMSIZE),
            'width': _int64_feature(IMSIZE),
            'depth': _int64_feature(3),
            'image_raw': _bytes_feature(image_raw),
            'label': _int64_feature(label)
            }))
        writer.write(example.SerializeToString())

    writer.close()
Exemplo n.º 22
0
def get_pictures(dir_name, collection):
    image_ids = get_image_ids(collection)
    for image_id in image_ids:
        url = get_image_url(image_id)
        picture_name = f"hubble{image_id}.{get_image_extension(url)}"
        file_path = os.path.join(dir_name, picture_name)
        save_image(get_image(url), file_path)
Exemplo n.º 23
0
def transform_forward(path_in, path_out, checkpoint_dir):
    image_input = get_image(path_in)
    image_input = np.array([image_input])
    image_shape = image_input.shape

    config = tf.ConfigProto(allow_soft_placement=True)
    config.gpu_options.allow_growth = True
    with tf.Graph().as_default(), tf.device('/cpu:0'), tf.Session(config=config) as sess:
        initial_image = tf.placeholder(tf.float32,
                                       shape=image_shape,
                                       name='initial_image')
        with tf.variable_scope("Transform_net"):
            transformed_image_tensor = transform.net(initial_image)
        saver = tf.train.Saver()
        if os.path.isdir(checkpoint_dir):
            ckpt = tf.train.get_checkpoint_state(checkpoint_dir)
            if ckpt and ckpt.model_checkpoint_path:
                saver.restore(sess, ckpt.model_checkpoint_path)
            else:
                raise Exception("No checkpoint found...")
        else:
            saver.restore(sess, checkpoint_dir)

        transformed_image = sess.run(transformed_image_tensor,
                                     feed_dict={initial_image: image_input})

        save_img(path_out, transformed_image[0])
Exemplo n.º 24
0
def save_data_list(inpath, outpath, filenames, filename_bbox):
    hr_images = []
    lr_images = []
    lr_size = int(LOAD_SIZE / LR_HR_RETIO)
    cnt = 0
    for key in filenames:
        bbox = filename_bbox[key]
        f_name = '%s/CUB_200_2011/images/%s.jpg' % (inpath, key)
        img = get_image(f_name, LOAD_SIZE, is_crop=True, bbox=bbox)
        img = img.astype('uint8')
        hr_images.append(img)
        lr_img = scipy.misc.imresize(img, [lr_size, lr_size], 'bicubic')
        lr_images.append(lr_img)
        cnt += 1
        if cnt % 100 == 0:
            print('Load %d......' % cnt)
    #
    print('images', len(hr_images), hr_images[0].shape, lr_images[0].shape)
    #
    outfile = outpath + str(LOAD_SIZE) + 'images.pickle'
    with open(outfile, 'wb') as f_out:
        pickle.dump(hr_images, f_out)
        print('save to: ', outfile)
    #
    outfile = outpath + str(lr_size) + 'images.pickle'
    with open(outfile, 'wb') as f_out:
        pickle.dump(lr_images, f_out)
        print('save to: ', outfile)
Exemplo n.º 25
0
    def _read_by_function(self, filename1, filename_2):

        array1 = get_image(filename1,
                           108,
                           is_crop=True,
                           resize_w=self.output_size,
                           is_grayscale=False)
        array1 = np.array(array1, dtype=np.float32)
        array2 = get_image(filename_2,
                           108,
                           is_crop=True,
                           resize_w=self.output_size,
                           is_grayscale=False)
        array2 = np.array(array2, dtype=np.float32)

        return array1, array2
Exemplo n.º 26
0
def pinhole_demo(rotation=None, translation=None, save_fname="pinhole", idx=0):
    # assignment: section 3
    bfm = h5py.File(MODELS_PATH + BFM_FNAME, "r")
    bfm_params, color, triangles = utils.read_bfm(bfm)
    lms = utils.read_landmarks(MODELS_PATH + LM_FNAME)  # landmark annotations

    rotation = torch.tensor([0., 0., 0.]) if rotation is None else torch.tensor(rotation)
    translation = torch.tensor([0., 0., -500.]) if translation is None else torch.tensor(translation)

    G = morph.compute_G(bfm_params)
    G_transformed = pinhole.transform(G, rotation, translation)
    G_pinhole = pinhole.camera_model(G, rotation, translation)

    save_obj(OBJ_3D_PATH + save_fname + str(idx) + "_3d.obj", G_transformed, color, triangles)
    save_obj(OBJ_2D_PATH + save_fname + str(idx) + "_2d.obj", G_pinhole, color, triangles)

    print("Rendering...")
    img_2d = utils.get_image(G_pinhole, color, triangles)  # render img
    img_lm = utils.get_landmarks(G_pinhole[:, :2], lms)  # landmark coords

    utils.show_face(img_2d)
    utils.flip_y()
    plt.savefig(PINHOLE_PATH + save_fname + str(idx) + ".pdf")

    utils.show_landmarks(img_lm, indices=True)  # overlays landmarks on image
    plt.savefig(PINHOLE_PATH + save_fname + str(idx) + "_lm.pdf")
    plt.close()
Exemplo n.º 27
0
    def _read_by_function(self, filename):

        array = get_image(filename, 108, is_crop=True, resize_w=self.output_size,
                           is_grayscale=False)
        real_images = np.array(array)
        real_images = real_images[:,:,np.newaxis]
        return real_images
Exemplo n.º 28
0
class Powerup(pg.sprite.Sprite):
    """All the powerups: shield, weapon..."""

    POWERUPS = {osp.basename(f).split(".")[0]: get_image(f)
                for f in glob(osp.join(IMAGES_FOLDER, "powerups", "*png"))}

    def __init__(self, center):
        super(Powerup, self).__init__()
        self.type = ("bomb", "shield", "weapon")[randrange(3)]
        self.image = self.POWERUPS[self.type]
        self.rect = self.image.get_rect()
        self.rect.center = center
        self.centery = center[1]
        self.up = True

    def update(self):
        if self.rect.centery < self.centery - 50:
            self.up = False
        if self.rect.top > HEIGHT:
            self.kill()
            return
        if self.up:
            self.rect.y -= game.dt / 2
        else:
            self.rect.y += game.dt / 4
Exemplo n.º 29
0
def writex(conf, n_img):
    data_files = glob(os.path.join(conf.data_dir, conf.dataset, "*"))
    shuffle(data_files)
    l_f = data_files[0:n_img]
    l_x = [
        get_image(f,
                  conf.n_img_pix,
                  is_crop=conf.is_crop,
                  resize_w=conf.n_img_out_pix,
                  is_grayscale=conf.is_gray) for f in l_f
    ]

    with open(os.path.join(base_dir, 'x.csv'), 'w') as file:
        for i in range(len(l_x)):
            file.write(
                str(l_x[i].tolist()).replace("[", "").replace("]", "") + '\n')
    file.close()

    x_fix = np.array(l_x).astype(np.float32)

    if (conf.is_gray == 1):
        x_fix = x_fix.reshape(conf.n_batch, conf.n_img_out_pix,
                              conf.n_img_out_pix, 1)

    x_fix = np.clip((x_fix + 1) * 127.5, 0, 255)
    save_image(x_fix, '{}/x_fix.png'.format(base_dir))
Exemplo n.º 30
0
def main(args):
    model = get_model(training=False)
    model.summary()

    try:
        model.load_weights(args[2])
        print("....Previous weight data...")
    except:
        print("Weights not found, Aborting")
        exit()

    data_dir = args[0]
    annotation_file = args[1]
    outfile = open('outfile', 'w')

    with open(os.path.join(data_dir, annotation_file), 'r') as f:
        filenames = [line.split(' ')[0][2:] for line in f]

    iters = 0
    max_iters = 100
    for img_name in filenames:
        if iters == max_iters:
            break
        iters += 1
        img = get_image(os.path.join(data_dir, img_name))
        img = np.expand_dims(img, axis=0)

        y_pred = model.predict(img)

        label_true = img_name.split('_')[1]
        label_pred, label_unprocessed = activation_to_label(y_pred)

        outfile.write(label_true + ' ' + label_pred + ' ' + label_unprocessed + '\n')

    outfile.close()
Exemplo n.º 31
0
def extract_to(db, path, cursor, start, end, crop=False):
    try:
        os.mkdir(path)
        os.mkdir(path + '/COCAINA')
        os.mkdir(path + '/SEMCOCAINA')
    except FileExistsError:
        pass
    ind = 0
    # Colocar um número sequencial no início do nome do arquivo, para permitir treino
    # aos pares caso sejam utilizadas redes siamesas
    for ind, linha in enumerate(cursor):
        _id = linha['_id']
        container = linha['metadata']['numeroinformado']
        carga = linha.get('metadata').get('carga')
        if carga:
            ncms = linha.get('metadata').get('carga').get('ncm')
            conhecimento = linha.get('metadata').get('carga') \
                .get('conhecimento')[0].get('conhecimento')
        image = get_image(linha, crop=crop)
        if image:
            sub_path = os.path.join(path, 'COCAINA')
            filename = str(ind) + '_' + str(_id) + '.jpg'
            image.save(os.path.join(sub_path, filename))
            print(ind, sub_path)
            del image
            if carga:
                similar_image, similar_id = get_similar_image(db, conhecimento, ncms,
                                                              start, end, crop)
                if similar_image:
                    sub_path = os.path.join(path, 'SEMCOCAINA')
                    filename = str(ind) + '_' + str(similar_id) + '.jpg'
                    similar_image.save(os.path.join(sub_path, filename))
                    print(ind, sub_path)
                    del similar_image
    return ind
Exemplo n.º 32
0
def extract_to(rows: list, crop=False, min_ratio=MIN_RATIO):
    """Receives a list, reads images and save to dir VAZIO or NVAZIO
    
    Receives a list of MongoDB records. Each line must have _id of the image
    and a metadata.carga.vazio boolean field
    
    If crop=True, then the record MUST have a predictions.bbox, and the image
    will be croped on predictions[0].bbox

    """
    caminho = 'vazios'
    if crop:
        caminho += '_cropped'
    if not os.path.exists(caminho):
        os.mkdir(caminho)
    for destino in ('VAZIO', 'NVAZIO'):
        if not os.path.exists(os.path.join(caminho, destino)):
            os.mkdir(os.path.join(caminho, destino))
    count = 0
    for count, row in enumerate(rows):
        _id = row['_id']
        vazio = row['metadata']['carga']['vazio']
        destino = 'VAZIO' if vazio else 'NVAZIO'
        caminho_atual = os.path.join(caminho, destino)
        arquivo_atual = os.path.join(caminho_atual, str(_id)) + '.jpg'
        if os.path.exists(arquivo_atual):
            print(str(_id), ' existe, abortando...')
            continue
        image = get_image(row, crop, min_ratio)
        if image:
            image.save(arquivo_atual)
    print('%s arquivos exportados...' % count)
    return count
Exemplo n.º 33
0
 def post(self):
     try:
         parser = reqparse.RequestParser()
         parser.add_argument("image", required=True, location=['form', 'args', 'json', 'files'])
         args = parser.parse_args(strict=True)
         if "FileStorage" in args.image:
             parser.replace_argument('image', type=FileStorage, required=True, location='files')
         args = parser.parse_args(strict=True)
         img, byte_image = get_image(args.image)
         img_compressed = compress_image(img, byte_image)
         img_compressed.seek(0)
         return send_file(
             img_compressed,
             mimetype='image/jpeg',
             as_attachment=True,
             attachment_filename="compressed_image.jpg"
         )
     except ImageException as e:
         return {
             "status_code": 400,
             "message": str(e)
         }
     except Exception as e:
         return {
             "status_code": 500,
             "message": "Internal Server Error."
         }
Exemplo n.º 34
0
def spookjoke():
    name = random.choice(utils.file_to_list('Sp00k.txt'))
    path_name = slugify(name,
                        word_boundary=True, separator="_")
    path = "{0}/{1}".format("spook", path_name)
    tweet_image = utils.get_image(path)
    name = re.sub(r' \([^)]*\)', '', name)
    m = "Oh oh! Looks like your command was stolen by {0}!! #Sp00ky".format(name)
    return m, tweet_image
Exemplo n.º 35
0
 def skip_enemy(self):
     print("Jumping over enemy ...")
     image = get_image("enemy-mushroom.png", self.emulator)
     searching = True;
     while(searching):
         coordinates = pyautogui.locateCenterOnScreen(image)
         if coordinates is not None:
             x, y = coordinates[0], coordinates[1]
             print(x, y)
             searching = False;
Exemplo n.º 36
0
def get_image(note_id):
	note = None
	try:
		note = Note.objects.get(pk=note_id)
	except ObjectDoesNotExist:
		return {RSP_CODE : RC_NO_SUCH_NOTE}
	if note.image_path is None:
		return {RSP_CODE : RC_NO_IMAGE}
	result = {RSP_CODE : RC_SUCESS}
	result['image'] = utils.get_image(note.image_path)
	return result
Exemplo n.º 37
0
def waifu(gender, args="", otp=False, DISCORD=False, user_id=False):
    if gender == 0:
        list_name = "Waifu"
        end_tag = "1girl+solo"
    else:
        list_name = "Husbando"
        end_tag = "-1girl+-female"
    result = ""
    lines = utils.file_to_list(
        os.path.join(settings['list_loc'],
                     list_name + " List.txt"))
    args = ' '.join(args.split()).lower()
    matched = []
    ignore = ["high-school-dxd", "love-live",
              "aoki-hagane-no-arpeggio", "kantai-collection",
              "aikatsu", "akb0048", "idolmaster",
              "idolmaster-cinderella-girls"]
    if len(args) > 4:
        for entry in lines:
            if slugify(entry[1], word_boundary=True) in ignore:
                continue
            if slugify(args, word_boundary=True) ==\
               slugify(entry[1], word_boundary=True):
                matched.append(entry)
        # It's not really that random if there isn't that many people matched.
        if len(matched) > 4:
            result = random.choice(matched)
    if not result:
        result = random.choice(lines)

    name, show, otp_img = result
    if otp:
        return name, show, otp_img
    path_name = slugify(name,
                        word_boundary=True, separator="_")
    path = os.path.join(list_name, path_name)
    tweet_image = utils.get_image(path)
    if not tweet_image and not DISCORD:
        tags = [name.replace(" ", "_"), "solo", "-genderswap", end_tag]
        tweet_image = utils.get_image_online(tags, 0, 1,
                                             "", path)
    name = re.sub(r' \([^)]*\)', '', name)
    m = "Your {0} is {1} ({2})".format(list_name.title(),
                                       name, show)
    if user_id:
        st = "{} ({})".format(name, show)
        count_command(list_name, st,
                      os.path.join(settings['user_count_loc'], user_id))
    count_command(list_name, "{} ({})".format(name, show),
                  settings['count_file'])

    return m, tweet_image
Exemplo n.º 38
0
    def prepare_data(self):
        """ Treat the pictures """
        tmp = 'test' if self.test else 'train'
        print " ---- Loading "+tmp+" set ----"
        for i, img_id in tqdm(enumerate(self.images_id)):
            features = get_image(self.path, img_id, width=self.width)
            if self.X is None:
                self.n_features = features.shape[0]
                self.X = np.zeros((self.n_images, self.n_features),
                                  dtype=np.uint8)

            if not features.shape[0] == self.n_features:
                print "Error on image {}".format(img_id)

            self.X[i, :] = features
        print "Feature_matrix shape: {}".format(self.X.shape)
Exemplo n.º 39
0
def mywaifu(user_id, gender):
    if gender == 0:
        gender = "Waifu"
        filename = "users_waifus.json"
    else:
        gender = "Husbando"
        filename = "users_husbandos.json"
    user_waifus_file = open(
        os.path.join(settings['list_loc'], filename), 'r',
        encoding='utf-8')
    user_waifus = json.load(user_waifus_file)
    user_waifus_file.close()
    for user in user_waifus['users']:
        if int(user['twitter_id']) == user_id:
            break
    if int(user['twitter_id']) != user_id:
        count_trigger("mywaifu")
        m = ("I don't know who your {0} is!\n"
             "Use {1}Register!\n"
             "Help: {2}").format(gender, gender,
                                 config_get('Help URLs', 'include_name'))
        return m, False
    tags = user['name'] + user['tags']
    if user.get('max_page'):
        max_page = user['max_page']
    else:
        max_page = 20
    path_name = slugify(user['name'],
                        word_boundary=True, separator="_")
    path = os.path.join(settings['image_loc'],
                        gender.lower(), path_name)
    ignore_list = "user_ignore/{0}".format(user['twitter_id'])
    tweet_image = utils.get_image_online(tags, user['web_index'],
                                         max_page, ignore_list)
    if not tweet_image:
        tweet_image = utils.get_image(path, ignore_list)
    if not tweet_image:
        m = ("Failed to get an image (website could be offline).\n"
             "Help: {0}").format(config_get('Help URLs', 'website_offline'))
        remove_one_limit(user_id, "my" + gender.lower())
        return m, False
    if datetime.datetime.now().isoweekday() == 3:
        m = "#{0}Wednesday".format(gender)
    else:
        m = "#{0}AnyDay".format(gender)
    return m, tweet_image
def main(argv):
    pattern = "/home/ian/imagenet/ILSVRC2012_img_train_t1_t2/n*/*JPEG"
    files = glob(pattern)
    assert len(files) > 0
    assert len(files) > 1000000, len(files)
    shuffle(files)

    dirs = glob("/home/ian/imagenet/ILSVRC2012_img_train_t1_t2/n*")
    assert len(dirs) == 1000, len(dirs)
    dirs = [d.split('/')[-1] for d in dirs]
    dirs = sorted(dirs)
    str_to_int = dict(zip(dirs, range(len(dirs))))


    outfile = '/media/NAS_SHARED/imagenet/imagenet_train_labeled_' + str(IMSIZE) + '.tfrecords'
    writer = tf.python_io.TFRecordWriter(outfile)

    for i, f in enumerate(files):
        print i
        image = get_image(f, IMSIZE, is_crop=True, resize_w=IMSIZE)
        image = colorize(image)
        assert image.shape == (IMSIZE, IMSIZE, 3)
        image += 1.
        image *= (255. / 2.)
        image = image.astype('uint8')
        #print image.min(), image.max()
        # from pylearn2.utils.image import save
        # save('foo.png', (image + 1.) / 2.)
        image_raw = image.tostring()
        class_str = f.split('/')[-2]
        label = str_to_int[class_str]
        if i % 1 == 0:
            print i, '\t',label
        example = tf.train.Example(features=tf.train.Features(feature={
            'height': _int64_feature(IMSIZE),
            'width': _int64_feature(IMSIZE),
            'depth': _int64_feature(3),
            'image_raw': _bytes_feature(image_raw),
            'label': _int64_feature(label)
            }))
        writer.write(example.SerializeToString())

    writer.close()
Exemplo n.º 41
0
def random_list(list_name, args="", DISCORD=False):
    gender = "waifu"
    hashtag = ""
    search_for = ""
    m = False
    lines = False
    show_series = False
    scrape_images = True
    if list_name == "Shipgirl":
        if "aoki" in args:
            lines = utils.file_to_list('Shipgirl Aoki.txt')
        elif "all" in args:
            if "otp" in args:
                list_name += " OTP"
                lines = utils.file_to_list('Shipgirl All OTP.txt')
            else:
                lines = utils.file_to_list('Shipgirl Aoki.txt')
                lines += utils.file_to_list('Shipgirl.txt')
        else:
            hashtag = "#Kancolle"
            if "otp" in args:
                list_name += " OTP"
                lines = utils.file_to_list('Shipgirl OTP.txt')
            else:
                lines = utils.file_to_list('Shipgirl.txt')
    elif list_name == "Touhou":
        hashtag = "#Touhou"
        if "otp" in args:
            list_name += " OTP"
            lines = utils.file_to_list('Touhou OTP.txt')
        else:
            lines = utils.file_to_list('Touhou.txt')
    elif list_name == "Vocaloid":
        hashtag = "#Vocaloids"
        if "otp" in args:
            list_name += " OTP"
            lines = utils.file_to_list('Vocaloid OTP.txt')
        else:
            lines = utils.file_to_list('Vocaloid.txt')
    elif list_name == "Imouto":
        list_name = "Imouto"
        show_series = True
        lines = utils.file_to_list('Imouto.txt')
    elif list_name == "Idol":
        show_series = True
        if "love live" in args or "lovelive" in args:
            search_for = "Love Live!"
            hashtag = "#LoveLive"
            if "otp" in args:
                list_name = "Love Live! OTP"
                show_series = False
                lines = utils.file_to_list('Idol Love Live OTP.txt')
        elif "cinderella" in args or "cinderella" in args:
            search_for = "Idolmaster Cinderella Girls"
            hashtag = "#Idolmaster"
        elif "idolmaster" in args or "idolm@ster" in args:
            search_for = "Idolmaster"
            hashtag = "#Idolmaster"
        elif "akb0048" in args:
            search_for = "AKB0048"
            hashtag = "#akb0048"
        elif "wake" in args:
            search_for = "Wake Up Girls!"
            hashtag = "#WUG_JP"
        elif "aikatsu" in args:
            search_for = "Aikatsu!"
            hashtag = "#Aikatsu"
        if "male" in args:
            list_name = "Male Idol"
            lines = utils.file_to_list('Idol Males.txt')
        else:
            if not lines:
                lines = utils.file_to_list('Idol.txt')
                if search_for:
                    temp_lines = []
                    for line in lines:
                        if line[1] == search_for:
                            temp_lines.append(line)
                    lines = temp_lines
                    del temp_lines
    elif list_name == "Shota":
        show_series = True
        gender = "husbando"
        lines = utils.file_to_list('Shota.txt')
    elif list_name == "Onii":
        list_name = "Onii-chan"
        show_series = True
        gender = "husbando"
        lines = utils.file_to_list('Onii-chan.txt')
    elif list_name == "Onee":
        list_name = "Onee-chan"
        show_series = True
        lines = utils.file_to_list('Onee-chan.txt')
    elif list_name == "Sensei":
        show_series = True
        if "female" in args:
            lines = utils.file_to_list('Sensei Female.txt')
        elif "male" in args:
            gender = "husbando"
            lines = utils.file_to_list('Sensei Male.txt')
        else:
            lines = utils.file_to_list('Sensei Male.txt')
            lines += utils.file_to_list('Sensei Female.txt')
    elif list_name == "Senpai":
        show_series = True
        if "female" in args:
            lines = utils.file_to_list('Senpai Female.txt')
        elif "male" in args:
            gender = "husbando"
            lines = utils.file_to_list('Senpai Male.txt')
        else:
            lines = utils.file_to_list('Senpai Male.txt')
            lines += utils.file_to_list('Senpai Female.txt')
    elif list_name == "Kouhai":
        show_series = True
        if "female" in args:
            lines = utils.file_to_list('Kouhai Female.txt')
        elif "male" in args:
            gender = "husbando"
            lines = utils.file_to_list('Kouhai Male.txt')
        else:
            lines = utils.file_to_list('Kouhai Male.txt')
            lines += utils.file_to_list('Kouhai Female.txt')
    elif list_name == "Monstergirl":
        show_series = True
        scrape_images = True
        lines = utils.file_to_list('Monstergirl.txt')
    elif list_name == "Witchgirl":
        hashtag = "#s_witch"
        show_series = False
        scrape_images = True
        lines = utils.file_to_list('Witchgirl.txt')
    elif list_name == "Tankgirl":
        hashtag = "#garupan"
        show_series = False
        scrape_images = True
        lines = utils.file_to_list('Tankgirl.txt')

    # Under heavy stuff random.choice can be very weak
    # so just a quick way to make sure it's 'random random'
    random.shuffle(lines)
    entry = random.choice(lines)
    if list_name.endswith("OTP"):
        names = entry.split("(x)")
        if list_name == "Touhou":
            tags = "{0}+{1}+2girls+yuri+touhou+-asai_genji+-comic".format(
                names[0].replace(" ", "_"),
                names[1].replace(" ", "_"))
        if "love live" in list_name.lower():
            tags = "{0}+{1}+2girls+yuri+-comic".format(
                names[0].replace(" ", "_"),
                names[1].replace(" ", "_"))
        else:
            tags = "{0}+{1}+yuri+2girls+-comic".format(
                names[0].replace(" ", "_"),
                names[1].replace(" ", "_"))
        name = "{0}(x){1}".format(names[0], names[1])
    else:
        if isinstance(entry, list):
            name = entry[0]
            show = entry[1]
        else:
            name = entry
        if scrape_images:
            tags = "{0}+solo".format(name.replace(" ", "_"))
    path_name = slugify(name,
                        word_boundary=True, separator="_")
    path = "{0}/{1}".format(gender.lower(), path_name)
    tweet_image = utils.get_image(path)
    if scrape_images and not DISCORD or not tweet_image and not DISCORD:
        tweet_image_temp = utils.get_image_online(tags, 0, 1, "", path)
        if tweet_image_temp is not False:
            tweet_image = tweet_image_temp

    name = re.sub(r' \([^)]*\)', '', name)
    hashtag = ""  # TODO: Temp (testing with twitter)
    if show_series:
        m = "Your {0} is {1} ({2}) {3}".format(list_name, name,
                                               show, hashtag)
    elif list_name.endswith("OTP"):
        name_one = re.sub(r' \([^)]*\)', '', names[0])
        name_two = re.sub(r' \([^)]*\)', '', names[1])
        name = "{0} x {1}".format(name_one, name_two)
    if not m:
        m = "Your {0} is {1} {2}".format(list_name, name, hashtag)
        if not list_name.endswith("OTP"):
            count_trigger(name, gender)
    return m, tweet_image
Exemplo n.º 42
0
def mywaifu(user_id, gender, DISCORD=False, SKIP_DUP_CHECK=False):
    tweet_image = False
    if gender == 0:
        gender = "Waifu"
        filename = "users_waifus.json"
    else:
        gender = "Husbando"
        filename = "users_husbandos.json"
    user_waifus_file = open(
        os.path.join(settings['list_loc'], filename), 'r',
        encoding='utf-8')
    user_waifus = json.load(user_waifus_file)
    user_waifus_file.close()
    for user in user_waifus['users']:
        if int(user['twitter_id']) == int(user_id):
            break
    if int(user['twitter_id']) != int(user_id):
        count_trigger("mywaifu")
        m = ("I don't know who your {0} is!\n"
             "Use {1}Register!\n"
             "Help: {2}").format(gender, gender,
                                 config_get('Help URLs', 'include_name'))
        return m, False
    tags = user['name'] + user['tags']
    if user.get('max_page'):
        max_page = user['max_page']
    else:
        max_page = 20
    path_name = slugify(user['name'],
                        word_boundary=True, separator="_")
    path = os.path.join(settings['image_loc'],
                        gender.lower(), path_name)
    if DISCORD:
        ignore_list = "user_ignore/discord_{0}".format(user['twitter_id'])
        tweet_image = utils.get_image(path, ignore_list)
    else:
        ignore_list = "user_ignore/{0}".format(user['twitter_id'])

    if not DISCORD:
        tweet_image = utils.get_image_online(tags, user['web_index'],
                                             max_page, ignore_list,
                                             path=path)
    if not tweet_image:
        tweet_image = utils.get_image(path, ignore_list)

    if not tweet_image and SKIP_DUP_CHECK:
        tweet_image = utils.get_image(path)

    if not tweet_image:
        m = ("Failed to grab a new image!\nThe main image website could be offline.\n"
             "Help: {0}").format(config_get('Help URLs', 'website_offline'))
        remove_one_limit(user_id, "my" + gender.lower())
        return m, False
    if datetime.datetime.now().isoweekday() == 3:
        # TODO: Remember hashtags here
        m = "{0}Wednesday".format(gender)
    else:
        m = "{0}AnyDay".format(gender)
    if DISCORD:
        # @user's x is x
        m = " {gender} is {name}!".format(
            gender=gender, name=user['name'].replace("_", " ").title())
    return m, tweet_image
Exemplo n.º 43
0
 def set_image(self, filename):
     image = utils.get_image(filename, (64, 64))
     self.button.set_image(image)
Exemplo n.º 44
0

""" The theme starts here """

#ui.Entry.font_desc = pango.FontDescription('Danube 8')
#ui.Label.font_desc = pango.FontDescription('Danube 8')

@override(ui.Label)
def do_render(self):
    """the label is looking for an background_image attribute and if it is found
    it paints it"""
    if getattr(self, "background_image", None):
        self.background_image.render(self.graphics, self.width, self.height)

ui.Button.images = {
    "normal": get_image("themes/assets/button_normal.png", 3, 3, 3, 3),
    "highlight": get_image("themes/assets/button_highlight.png", 3, 3, 3, 3),
    "pressed": get_image("themes/assets/button_pressed.png", 3, 3, 3, 3),
    "disabled": get_image("themes/assets/button_disabled.png", 3, 3, 3, 3),
}

ui.Button.font_desc = pango.FontDescription('Serif 10')
@override(ui.Button)
def do_render(self, state=None):
    """ Properties that affect rendering:
        state:   normal / highlight / pressed
        focused: True / False
        enabled: True / False
    """
    state = state or self.state
Exemplo n.º 45
0
    def __init__ (self, debug_level=0, args=[], optlist=[]) :
        ChallengeBase.__init__(self, debug_level)

        self.message ="""
    usage: %s [-h] [-v] [-d] [ -k key-key  ] [ -c cert ] [ -i image-id ]\
[ -f flavor-id ] -n FQDN-name  

    image-id -f flavor-id
        -h - usage help 
        -v - verbose / debug output 
        -d - delete objects if they existed in cloud before creating new one
        -k - certificate pritate key (see -c below)
        -c - public certificate ( see -k above)
        -n - FQDN name like www.myexample.com
        -i - specify image-id or use the default for Ubuntu 10.04
        -f - specify flavor-id or use the default for the smallest cloud server
    """ % (PROGRAM_NAME) 

        self.cert_use_default = False
        self.cert_key_name = None
        self.cert_key = None
        self.cert_name = None
        self.cert = None

        self.opt_delete = False

        self.fqdn_name = None
        self.domain_name = None
        self.domain = None
        self.recs = None

        self.lb=None
        self.lb_name = None
        self.vip=None
        self.vip_address = None
        self.nodes=[]

        self.image = None
        self.image_id = None

        self.flavor = None
        self.flavor_id = None

        self.server_prefix=None
        self.cs_count=3
        self.server_passord = "SecretP@ss1"
        self.servers = []

        self.storage_name = None
        self.volumes=[]

        self.network_name = None
        self.network_range = "192.168.100.0/24"
        self.network = None
        self.network_id = None


        for o, val in optlist:
            if o == "-n":
                self.fqdn_name = val
                self.domain_name =  ".".join( self.fqdn_name.split('.')[1:] )
                self.domain=None
                self.recs = None
            elif o == "-d":
                self.opt_delete = True
            elif o == "-i":
                self.image_id = val
            elif o == "-f":
                self.flavor_id = val
            elif o == "-k":
                self.cert_key_name = val
            elif o == "-c":
                self.cert_name = val
            elif o == "-i":
                self.image_id = val
            elif o == "-f":
                self.flavor_id = val

        if not self.fqdn_name :
            self.usage()
            sys.exit(-1)

        #default values for some variables 

        self.image = None
        if not self.image_id :
            self.image_id = utils.get_image(self.cs)
        
        self.flavor= None
        if not self.flavor_id :
            self.flavor_id = utils.get_flavor(self.cs)

        self.lb_name = self.fqdn_name
        self.storage_name = self.fqdn_name
        self.server_prefix = self.fqdn_name
        self.network_name = self.fqdn_name

        if not self.cert_key_name and not self.cert_name :
            self.cert_use_default = True
            self.cert_key_name = self.fqdn_name + ".key"
            self.cert_key="""-----BEGIN RSA PRIVATE KEY-----
MIICXAIBAAKBgQCypZq3lUHWhBjDxV6hOtOQFI3WvcGlp9RP+ZHVTcwDb/buaGIL
99xCUabM5TIjzfSMthddEb+43RIdZeaXSnqV0Ut+xF9fPIHiky+DrOS2i77ltu67
RGTerezjM36D4TW5N3vQOR+qIezp1yko1qJr5hROp2ykqcgIL5GzR4980QIDAQAB
AoGBAKIZyKDqa3pGFN6XWf18jnn/XJDNUEiLWAhVkfF2DTfVQcAksUrg1ljLFEp5
chyxBkUj+WE2+Lu6xXQtgaYoK7/+mRRpKEZ6aHEsd5KqoVgxp2igyRZOGyVWaAJ3
loi+GmMiRkjC6o6xxNGG7UNfXSACfbB8eEBaGw61ZhbZJ28NAkEA5rVk/mqQFYzO
WynHT1DUz4YeIpj1ZAnhjn/957knU61VoAjeruLANOmN5bQ2gCKJm7MsPJ11iAdp
Cfltaprq7wJBAMY7Jp0hQBWOp3J1VNTkeG23At/ZQv5QzkUih2hcHjXy54RYqFe/
pIH9qrLC01BjhG2PePrJwaKMmhl7TvQ7FD8CQHmG7848n+1aIJFQ7pZPQ+qVAWbE
H+80bUY9EahwldC0K7iDM5n4A7tbk81+In9Yshf8R78eSnz/Oktwwjw3oq0CQEyZ
3PEJQUdTSdeMCYz/AJ59AwpXXXEC7sJ+dk7YkgAM7nQRAnRuJPbqfET5zkiZPDpO
H9ThlAbpSD8ijD8KeWcCQBxun2xWhCH19BulbUufsocKrwaxAijJ4pc5fX+cabEU
Na05oMyXQxN2tR4gWlbyVrGuZPVRDH39oRej5z2/JUA=
-----END RSA PRIVATE KEY-----
"""
        self.cert_name = self.fqdn_name + ".crt"
        self.cert = """-----BEGIN CERTIFICATE-----
Exemplo n.º 46
0
    def __init__ (self, debug_level=0, args=[], optlist=[]) :
        ChallengeBase.__init__(self, debug_level)

        self.message ="""
    usage: %s [-h] [-v] [-d] [ -s ssh-key ] [ -e error-page ] [ -c container-name ] [ -i image-id ] [ -f flavor-id ] -n FQDN-name  

    image-id -f flavor-id
        -h - usage help 
        -v - verbose / debug output 
        -d - delete objects if they existed in cloud before creating new one
        -n - FQDN name like www.myexample.com
        -s - path to your ssh public key (not priv!)
        -e - path to a html file that will be served from the LB when all pool members are down
        -c - name of cloud files container-name to store the backup data
        -i - specify image-id or use the default for Ubuntu 10.04
        -f - specify flavor-id or use the default for the smallest cloud server
    """ % (PROGRAM_NAME)

        self.optlist = optlist
        self.args = args

        self.opt_delete = False

        self.fqdn_name = None
        self.domain_name = None
        self.domain = None
        self.recs = None

        self.ssh_public_key_name = None
        self.ssh_public_key = None

        self.error_page_name = None
        self.error_page_path = None
        self.error_page = None

        self.container_name = None
        self.container = None

        self.image = None
        self.image_id = None

        self.flavor = None
        self.flavor_id = None

        self.server_prefix=None
        self.cs_count=2
        self.servers = []
        
        self.lb=None
        self.lb_name =None
        self.vip=None
        self.vip_address = None
        self.nodes=[]

        for o, val in optlist:
            if o == "-n":
                self.fqdn_name = val
                self.domain_name =  ".".join( self.fqdn_name.split('.')[1:] )
                self.domain=None
                self.recs = None
            elif o == "-s":
                self.ssh_public_key_name = val
            elif o == "-e":
                self.error_page_path = val
            elif o == "-d":
                self.opt_delete = True
            elif o == "-c":
                self.container_name = val
            elif o == "-i":
                self.image_id = val
            elif o == "-f":
                self.flavor_id = val

        if not self.fqdn_name :
            self.usage()
            sys.exit(-1)

        #default values for some variables 

        if not self.container_name :
            self.container_name = self.fqdn_name 

        self.image = None
        if not self.image_id :
            self.image_id = utils.get_image(self.cs)
        
        self.flavor= None
        if not self.flavor_id :
            self.flavor_id = utils.get_flavor(self.cs)

        self.lb_name = self.fqdn_name

        self.server_prefix = self.fqdn_name