def get_photos_from_url(gender, type, url): crawler.open(url) crawler.infinite_scroll(slowly=True) images = crawler.find_elements('img.product-card--img') srcs = img2src(images) print '{} images got'.format(len(images)) download_images(srcs, os.path.join('gap', gender, type))
def get_photos_from_url(gender, type, url): crawler.open(url) crawler.infinite_scroll(slowly=True) images = crawler.find_elements('img.photo.default') srcs = img2src(images) print '{} images got'.format(len(images)) download_images(srcs, os.path.join('armanicollezioni', gender, type))
def main(): parser = argparse.ArgumentParser(description='Totality image classifier using VGG in Keras') parser.add_argument('--download', default=False, action='store_true') parser.add_argument('--img-dir', type=str, default='img') parser.add_argument('--label-file', type=str, default='labeled_data.json') parser.add_argument('--output-file', type=str, default='vgg_output_labels.json') args = parser.parse_args() if args.download: with open(args.label_file) as f: download_images(args.img_dir, list(json.load(f).keys())) print('Collecting dataset...') dataset = ImageDataNP(args.img_dir, labeled_data_file=args.label_file, train_ratio=1.0, squash=True) x_train, y_train = dataset.get_train() model = get_vgg('VGG16', weights='imagenet', classes=1000) writer = PredictionWriter() batch_size=32 start, end = 0, 0 print('Classifying images...') for i in range(int((x_train.shape[0] + batch_size - 1) / batch_size)): end = min((i + 1) * batch_size, x_train.shape[0]) print('Batch {}, images[{}:{}]'.format(i, start, end)) # Obtain predictions and print results preds = model.predict(x_train[start:end]) record_batch_results(writer, preds, y_train[start:end], dataset.train_keys, start) # Update start index start = end writer.commit(args.output_file)
def get_photos_from_url(gender, type, url): crawler.open(url) images = crawler.find_elements('span.back' '> img') srcs = img2src(images) print '{} images got'.format(len(images)) download_images(srcs, os.path.join('kuho', gender, type))
def download_nam3km_soundings(run, lat, lon): for fh in range(NAM3KM_SOUNDING_HOURS): sounding_url = sounding_img_url("nam3km", run, fh, lat, lon) sounding_filepath = "nam3km_sounding_fh" + str(fh).zfill(2) + ".png" logger.info("Downloading sounding: {:s} -> {:s}".format(sounding_url, sounding_filepath)) download_images(sounding_url, filename=sounding_filepath)
def get_photos_from_url(gender, type, url): crawler.open(url) crawler.infinite_scroll(slowly=True) images = crawler.find_elements('div.item-imgwrap' '> img:not(.hover)') srcs = img2src(images) print '{} images got'.format(len(images)) download_images(srcs, os.path.join('guess', gender, type))
def get_photos_from_url(gender, type, url): crawler.open(url) crawler.infinite_scroll(sleep_time=3.5) images = crawler.find_elements('img.product-tile__image') srcs = img2src(images) print '{} images got'.format(len(images)) download_images(srcs, os.path.join('hugoboss', gender, type))
def get_photos_from_url(gender, type, url): crawler.open(url) crawler.infinite_scroll() images = crawler.find_elements('img.grid-product__image') srcs = img2src(images) print '{} images got'.format(len(images)) if gender == 'women': srcs = map(lambda src: src.replace('model', 'prod'), srcs) download_images(srcs, os.path.join('hollister', gender, type))
def get_photos_from_url(gender, type, url): crawler.open(url) images = crawler.find_elements( 'a.product-tiles-grid-item-link ' '> div.product-tiles-grid-item-image-wrapper ' '> div.product-tiles-grid-item-image ' '> img') srcs = img2src(images) print '{} images got'.format(len(images)) download_images(srcs, os.path.join('gucci', gender, type))
def get_photos_from_url(gender, type, url): crawler.open(url) crawler.infinite_scroll(sleep_time=3.) images = crawler.find_elements('figure > noscript') def parse_src(elem): html = elem.get_attribute('innerHTML') for token in html.split(' '): if 'src' in token: src = token.split('"')[-2] return 'http://www.cosstores.com{}'.format(src) srcs = map(parse_src, images) print '{} images got'.format(len(images)) download_images(srcs, os.path.join('cos', gender, type))
def main(): parser = argparse.ArgumentParser(description='A test') parser.add_argument('--download', default=False, action='store_true') parser.add_argument('--img-dir', type=str, default='img') parser.add_argument('--label-file', type=str, default='labeled_data.json') parser.add_argument('--save', type=str, default=None) args = parser.parse_args() if args.download: with open(args.label_file) as f: download_images(args.img_dir, list(json.load(f).keys())) # VGG Phase print('Collecting dataset...') dataset = ImageDataNP(args.img_dir, labeled_data_file=args.label_file, train_ratio=1.0, squash=True) x_train, y_train = dataset.get_train() vgg = get_vgg('VGG19', weights='imagenet', classes=1000) inp = vgg.input out = vgg.get_layer(name='fc2').output functor = K.function([inp], [out]) vgg_relu_out = list() batch_size = 32 start, end = 0, 0 print('Classifying images...') for i in range(int((x_train.shape[0] + batch_size - 1) / batch_size)): end = min((i + 1) * batch_size, x_train.shape[0]) print('Batch {}, images[{}:{}]'.format(i, start, end)) vecs = functor([x_train[start:end]]) vgg_relu_out.extend(vecs[0]) # Update start index start = end # Logistic Regression Phase kfold_dataset = ImageDataKFold(nfolds=10, custom_data=(np.array(vgg_relu_out), y_train)) model = train_and_eval_lr(kfold_dataset) # Save model? if args.save is not None: model.save(args.save)
def get_photos_from_url(gender, type, url): crawler.open(url) button = crawler.find_element('button.cookie-compliance-ok-btn') if button is not None: button.click() crawler.infinite_scroll() if gender == 'men': images = crawler.find_elements('img.product-image-front.active') else: images = crawler.find_elements('img.product-image-front.active') # images = crawler.find_elements('img.product-image-reverse') srcs = img2srcset(images) srcs = filter(lambda src: src.strip() != '', srcs) srcs = map( lambda src: 'http:{}'.format( src.split(',')[-1].strip().split(' ')[0]), srcs) print '{} images got'.format(len(srcs)) download_images(srcs, os.path.join('americaneagle', gender, type))
def index(): payload = { 'api_key': config.LASTFM_API_KEY, 'method': 'chart.getTopArtists', 'limit': 9, 'format': 'json' } r = requests.get(config.url, params=payload) links = gen_artistlinks(r.text) filenames = download_images(links, 'index') generate_collage(filenames, 'index_image') return render_template('index.html')
def main(): parser = argparse.ArgumentParser(description='Totality image classifier') parser.add_argument('--download', default=False, action='store_true') parser.add_argument('--img-dir', type=str, default='img') parser.add_argument('--img-uri', type=str, default='img/img.txt') parser.add_argument('--lr-model', type=str, default='lr_model.h5') parser.add_argument('--save', type=str, default=None) args = parser.parse_args() # Create URI list with open(args.img_uri) as f: img_uri = [l.strip() for l in f.readlines()] if args.download: download_images(args.img_dir, img_uri) # Create list of paths to local image files img_paths = [ os.path.join(args.img_dir, os.path.basename(i)) for i in img_uri ] # ImageSet object will provide images in for loop below. # This object provides a generator to access batches of # images, allowing only one batch to be loaded into RAM # at a time. images = ImageSet(img_paths) # Create VGG19 model vgg = get_vgg('VGG19', weights='imagenet', classes=1000) inp = vgg.input out = vgg.get_layer(name='fc2').output functor = K.function([inp], [out]) print('Classifying images...') vgg_fc2_out = list() batch_size = 32 i = 0 for batch, start, end in images.get_batches(batch_size): print('Batch {}, images[{}:{}]'.format(i, start, end)) vecs = functor([batch]) vgg_fc2_out.extend(vecs[0]) i += 1 # Load trained logistic regression model model = load_model(args.lr_model) # Classify tensors from VGG19 using LR model predictions = model.predict(np.array(vgg_fc2_out)) # Prediction dictionary. Used if the --save argument is supplied pred_dict = dict() # Print predictions and assemble pred_dict for i in range(len(img_uri)): cur_img_uri = img_uri[i] cls_name = decode_totality_prediction(predictions[i]) pred_dict[cur_img_uri] = cls_name print(cur_img_uri, cls_name) # Save predictions? if args.save is not None: with open(args.save, 'w') as f: json.dump(pred_dict, f)
def get_product_images(dir): crawler.infinite_scroll() images = crawler.find_elements('article.product-item > a > img') print '{} images got'.format(len(images)) srcs = img2src(images) download_images(srcs, os.path.join('hnm', gender, type, dir))
import utils tf.enable_eager_execution() assert tf.__version__ == '1.13.1' or tf.__version__ == '1.14.0', "This code is only tested on Tensorflow 1.13.1 and 1.14.0" # Define model constants. flags = tf.app.flags flags = utils.create_flags(flags) # Use third party images with 102 categories flowers. BATCH_SIZE = 128 EPOCH = 7 INPUT_SIZE = 8189 BUFFER_SIZE = 8000 NUM_CLASSES = 102 iter_number = (int)(INPUT_SIZE / BATCH_SIZE) + 1 image_root = utils.download_images() train_ds = utils.load_data(image_root) train_ds = utils.prepare_train_ds(train_ds, BATCH_SIZE, BUFFER_SIZE, image_size=128) # Guild generator and discriminator model. generator_net = Generator(dtype=flags.FLAGS.dtype) generator_optimizer = tf.train.AdamOptimizer( learning_rate=flags.FLAGS.learning_rate_generator, beta1=flags.FLAGS.beta1, beta2=flags.FLAGS.beta2) discriminator_net = Discriminator(alpha=flags.FLAGS.alpha, dtype=flags.FLAGS.dtype)
def init_tests(): """Get the data required for the tests.""" get_cifar10_dataset() convert_cifar2imagenet_format() download_images() get_models()