This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
list_dataset = tf.data.Dataset.list_files(str(data_directory/'*/*')) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
image_batch, label_batch = next(dataset) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data_directory = pathlib.WindowsPath("./LEGO brick images/train") | |
CLASSES = np.array([item.name for item in data_directory.glob('*') if item.name != "LICENSE.txt"]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scrapy | |
class ImageItem(scrapy.Item): | |
images = scrapy.Field() | |
image_urls = scrapy.Field() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ITEM_PIPELINES = {'scrapy.pipelines.images.ImagesPipeline': 1} | |
IMAGES_STORE = 'C:/images/scrapy' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for i in range(0, len(image_info)): | |
download_image(image_info[i]) |