summaryrefslogtreecommitdiff
path: root/data/recursive_dataset.py
blob: b4135dc6d9c5a77603d4e9bc8cc1c345ebafc829 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import os.path
from data.base_dataset import BaseDataset, get_transform
from data.image_folder import make_dataset
from PIL import Image
import random

class NextImage():
    def __init__(self):
        self.next_image = "lol"
        self.id = str(random.randint(1,100))
    def append(self, path):
        self.next_image = path
        print("APPEND " + self.id + ' ' + self.next_image)
    def get(self, index):
        print("GET " + self.id + ' ' + self.next_image)
        return self.next_image

im = NextImage()
im.append('a')
im.get(1)
im.append('b')
im.get(1)

class RecursiveDataset(BaseDataset):
    def initialize(self, opt):
        print('initialize')
        self.opt = opt
        self.root = opt.dataroot
        im.append(opt.dataroot + 'frame_0000.png')
        self.dir_A = os.path.join(opt.dataroot)
        self.A_paths = make_dataset(self.dir_A)
        self.A_paths = sorted(self.A_paths)

        self.stuff = [opt.dataroot + 'frame_0000.png']

        self.transform = get_transform(opt)

    def __getitem__(self, index):
        A_path = "recursive/frame_{:04d}.png".format(index)
        print('next image: ' + A_path)
        A_img = Image.open(A_path).convert('RGB')
        A = self.transform(A_img)
        if self.opt.which_direction == 'BtoA':
            input_nc = self.opt.output_nc
        else:
            input_nc = self.opt.input_nc

        if input_nc == 1:  # RGB to gray
            tmp = A[0, ...] * 0.299 + A[1, ...] * 0.587 + A[2, ...] * 0.114
            A = tmp.unsqueeze(0)

        return {'A': A, 'A_paths': A_path}

    def __len__(self):
        return 10000000

    def append(self, path):
        print('append', path)
        # next_image = path
        self.stuff.append(path)

    def name(self):
        return 'RecursiveImageDataset'