Skip to content

Instantly share code, notes, and snippets.

View NMZivkovic's full-sized avatar

Nikola Živković NMZivkovic

View GitHub Profile
class DataSetCreator(object):
def __init__(self, batch_size, image_height, image_width, dataset):
self.batch_size = batch_size
self.image_height = image_height
self.image_width = image_width
self.dataset = dataset
def _get_class(self, path):
pat_splited = tf.strings.split(path, os.path.sep)
return pat_splited[-2] == CLASS_NAMES
list_dataset = tf.data.Dataset.list_files(str(data_directory/'*/*'))
image_batch, label_batch = next(dataset)
from tf.keras.preprocessing.image import ImageDataGenerator
image_generator = ImageDataGenerator(rescale=1./255)
dataset = image_generator.flow_from_directory(directory=str(data_directory),
batch_size=32,
shuffle=True,
target_size=(300, 500),
classes = list(CLASSES))
data_directory = pathlib.WindowsPath("./LEGO brick images/train")
CLASSES = np.array([item.name for item in data_directory.glob('*') if item.name != "LICENSE.txt"])
import pandas
import os
import numpy as np
import pathlib
import IPython.display as display
import matplotlib.pyplot as plt
from PIL import Image
import tensorflow as tf
import scrapy
from ..items import ImageItem
class ImgSpider(scrapy.spiders.Spider):
name = "img_spider"
start_urls = ["https://rubikscode.net/"]
def parse(self, response):
image = ImageItem()
img_urls = []
import scrapy
class ImageItem(scrapy.Item):
images = scrapy.Field()
image_urls = scrapy.Field()
ITEM_PIPELINES = {'scrapy.pipelines.images.ImagesPipeline': 1}
IMAGES_STORE = 'C:/images/scrapy'
for i in range(0, len(image_info)):
download_image(image_info[i])