{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "b74163c1-4b23-4c40-9afd-f963e4a1377d", "metadata": {}, "outputs": [], "source": [ "from glob import glob\n", "from datasets import Dataset, Features, Image, Value\n", "from PIL import Image as PILImage\n", "from torchvision.transforms import CenterCrop, Resize\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", "import torch" ] }, { "cell_type": "code", "execution_count": 2, "id": "912bc52b-2c88-421a-9d3d-d85c5a0f2a47", "metadata": {}, "outputs": [], "source": [ "LSDIR_paths = Dataset.from_dict({\"path\":glob(\"LSDIR/*/*.png\")})" ] }, { "cell_type": "code", "execution_count": 3, "id": "e4ffa17d-3a4e-4c84-bf1b-905001deff29", "metadata": {}, "outputs": [], "source": [ "lanczos = PILImage.Resampling.LANCZOS\n", "def load_image(sample):\n", " image_path = sample['path']\n", " image = PILImage.open(image_path)\n", " image = CenterCrop(540)(Resize(540,lanczos)(image))\n", " return {\n", " \"image\": image,\n", " \"w\":image.width,\n", " \"h\":image.height,\n", " \"mode\":image.mode,\n", " \"aspect\":image.width/image.height,\n", " \"n_pixels\":image.width*image.height}" ] }, { "cell_type": "code", "execution_count": 4, "id": "115873bf-a6ba-4a9d-a4c1-c2507b558e39", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "57423eb175b841baae368b89b2121523", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Map (num_proc=24): 0%| | 0/84991 [00:00