From: Project Hentai AI Date: Wed, 2 Feb 2022 12:40:57 +0000 (+0000) Subject: Code and demo dataset X-Git-Url: https://git.hentai-ai.org/?a=commitdiff_plain;ds=inline;p=hentai-tinder.git%2F.git Code and demo dataset --- diff --git a/demo_input_dir/thighs-0000-crop.png b/demo_input_dir/thighs-0000-crop.png new file mode 100644 index 0000000..047ad73 Binary files /dev/null and b/demo_input_dir/thighs-0000-crop.png differ diff --git a/demo_input_dir/thighs-0001-crop.png b/demo_input_dir/thighs-0001-crop.png new file mode 100644 index 0000000..54e3196 Binary files /dev/null and b/demo_input_dir/thighs-0001-crop.png differ diff --git a/demo_input_dir/thighs-0002-crop.png b/demo_input_dir/thighs-0002-crop.png new file mode 100644 index 0000000..1f85ffb Binary files /dev/null and b/demo_input_dir/thighs-0002-crop.png differ diff --git a/demo_input_dir/thighs-0003-crop.png b/demo_input_dir/thighs-0003-crop.png new file mode 100644 index 0000000..3bd73d7 Binary files /dev/null and b/demo_input_dir/thighs-0003-crop.png differ diff --git a/demo_input_dir/thighs-0004-crop.png b/demo_input_dir/thighs-0004-crop.png new file mode 100644 index 0000000..8fa4b56 Binary files /dev/null and b/demo_input_dir/thighs-0004-crop.png differ diff --git a/demo_input_dir/thighs-0005-crop.png b/demo_input_dir/thighs-0005-crop.png new file mode 100644 index 0000000..1942ce3 Binary files /dev/null and b/demo_input_dir/thighs-0005-crop.png differ diff --git a/demo_input_dir/thighs-0006-crop.png b/demo_input_dir/thighs-0006-crop.png new file mode 100644 index 0000000..f80e0b6 Binary files /dev/null and b/demo_input_dir/thighs-0006-crop.png differ diff --git a/demo_input_dir/thighs-0007-crop.png b/demo_input_dir/thighs-0007-crop.png new file mode 100644 index 0000000..8c31a19 Binary files /dev/null and b/demo_input_dir/thighs-0007-crop.png differ diff --git a/demo_input_dir/thighs-0008-crop.png b/demo_input_dir/thighs-0008-crop.png new file mode 100644 index 0000000..a07883a Binary files /dev/null and b/demo_input_dir/thighs-0008-crop.png differ diff --git a/demo_input_dir/thighs-0009-crop.png b/demo_input_dir/thighs-0009-crop.png new file mode 100644 index 0000000..ba839db Binary files /dev/null and b/demo_input_dir/thighs-0009-crop.png differ diff --git a/demo_input_dir/thighs-0010-crop.png b/demo_input_dir/thighs-0010-crop.png new file mode 100644 index 0000000..4a3fbb8 Binary files /dev/null and b/demo_input_dir/thighs-0010-crop.png differ diff --git a/demo_input_dir/thighs-0011-crop.png b/demo_input_dir/thighs-0011-crop.png new file mode 100644 index 0000000..4a926f6 Binary files /dev/null and b/demo_input_dir/thighs-0011-crop.png differ diff --git a/demo_input_dir/thighs-0012-crop.png b/demo_input_dir/thighs-0012-crop.png new file mode 100644 index 0000000..45e4433 Binary files /dev/null and b/demo_input_dir/thighs-0012-crop.png differ diff --git a/demo_input_dir/thighs-0013-crop.png b/demo_input_dir/thighs-0013-crop.png new file mode 100644 index 0000000..a0840cb Binary files /dev/null and b/demo_input_dir/thighs-0013-crop.png differ diff --git a/demo_input_dir/thighs-0014-crop.png b/demo_input_dir/thighs-0014-crop.png new file mode 100644 index 0000000..5de3fee Binary files /dev/null and b/demo_input_dir/thighs-0014-crop.png differ diff --git a/demo_input_dir/thighs-0015-crop.png b/demo_input_dir/thighs-0015-crop.png new file mode 100644 index 0000000..92a5aae Binary files /dev/null and b/demo_input_dir/thighs-0015-crop.png differ diff --git a/demo_input_dir/thighs-0016-crop.png b/demo_input_dir/thighs-0016-crop.png new file mode 100644 index 0000000..2719090 Binary files /dev/null and b/demo_input_dir/thighs-0016-crop.png differ diff --git a/demo_input_dir/thighs-0017-crop.png b/demo_input_dir/thighs-0017-crop.png new file mode 100644 index 0000000..0fc8531 Binary files /dev/null and b/demo_input_dir/thighs-0017-crop.png differ diff --git a/demo_input_dir/thighs-0018-crop.png b/demo_input_dir/thighs-0018-crop.png new file mode 100644 index 0000000..89134d6 Binary files /dev/null and b/demo_input_dir/thighs-0018-crop.png differ diff --git a/demo_input_dir/thighs-0019-crop.png b/demo_input_dir/thighs-0019-crop.png new file mode 100644 index 0000000..98e6af5 Binary files /dev/null and b/demo_input_dir/thighs-0019-crop.png differ diff --git a/demo_input_dir/thighs-0020-crop.png b/demo_input_dir/thighs-0020-crop.png new file mode 100644 index 0000000..6fb4afd Binary files /dev/null and b/demo_input_dir/thighs-0020-crop.png differ diff --git a/hentai-tinder.py b/hentai-tinder.py new file mode 100644 index 0000000..0fe04bc --- /dev/null +++ b/hentai-tinder.py @@ -0,0 +1,175 @@ +from tkinter import * +from PIL import ImageTk, Image +import os +import sys + +root = Tk() +root.title('Hentai Tinder') +DEBUG = False + +# Todo: + + +def get_img(path): + img = Image.open(path).resize((250, 250), Image.ANTIALIAS) + return ImageTk.PhotoImage(img) + + +def print_res(res, save_path): + print("saving results...") + with open(save_path, "w") as f: + for r in res: + f.write(r + '\n') + + +class MainWindow: + + def __init__(self, main): + self.canvas = Canvas(main, width=250, height=300) + self.canvas.pack() + + main.bind('', self.left_key) + main.bind('', self.right_key) + main.bind('', self.up_key) + main.bind('', self.down_key) + + self.results = [] + self.my_images = [] + self.batch_number = 0 + self.my_image_number = 0 + + self.save_file = "results.txt" + self.ds_dir = "thighs_dataset" + if not os.path.isdir(self.ds_dir): + sys.exit('dataset directory not found!') + self.fnames = os.listdir(self.ds_dir) + if len(self.fnames) == 0: + sys.exit('found no data in dataset directory!') + + for fname in self.fnames: + self.results.append(str(fname)) + + self.batch_size = 10 + self.load_img_batch(0) + + # load save-file + if os.path.isfile(self.save_file): + print(f"found {self.save_file}, loading...") + counter = 0 + self.results = [] + with open(self.save_file, "r") as f: + for line in f.read().splitlines(): + self.results.append(line) + if "True" in line or "False" in line: + counter += 1 + if counter == len(self.results): + sys.exit(f"{self.save_file} is already completed") + self.batch_number = int(counter/self.batch_size) + self.load_img_batch(self.batch_number) + self.my_image_number = counter % self.batch_size + + # set first image on canvas + self.image_on_canvas = self.canvas.create_image(0, 0, anchor=NW, image=self.my_images[self.my_image_number]) + + # buttons + self.button1 = Button(main, text="Smash", command=self.on_button1) + self.button1.pack(side=RIGHT, padx=20) + + self.button2 = Button(main, text="Pass", command=self.on_button2) + self.button2.pack(side=LEFT, padx=20) + + self.button3 = Button(main, text="Go back", command=self.on_button3) + self.button3.pack() + + self.button4 = Button(main, text="Save", command=self.on_button4) + self.button4.pack() + + # labels + index = self.my_image_number + (self.batch_number * self.batch_size) + self.label1 = Label(main, text=self.results[index].split('.')[0]) + self.label1.place(x=80, y=260) + + self.label2 = Label(main, text=f"{index+1}/{len(self.fnames)}") + self.label2.place(x=100, y=280) + + def change_image(self): + self.my_image_number += 1 + if DEBUG: + print(f"img: {self.my_image_number}, batch: {self.batch_number}") + print(self.results) + + if self.my_image_number == len(self.my_images): + if DEBUG: + print("end of batch") + if self.batch_number == 9: + print_res(self.results, self.save_file) + print("exiting...") + root.destroy() + sys.exit(0) + else: + if DEBUG: + print("loading new batch") + self.batch_number += 1 + self.load_img_batch(self.batch_number) + self.my_image_number = 0 + # change image and labels + self.canvas.itemconfig(self.image_on_canvas, image=self.my_images[self.my_image_number]) + index = self.my_image_number + (self.batch_number * self.batch_size) + self.label1.configure(text=self.results[index].split('.')[0]) + self.label2.configure(text=f"{index+1}/{len(self.fnames)}") + + def on_button1(self): + # Smash + index = self.my_image_number + (self.batch_number * self.batch_size) + self.results[index] = self.results[index].split('_')[0] + "_True" + self.change_image() + + def on_button2(self): + # Pass + index = self.my_image_number + (self.batch_number * self.batch_size) + self.results[index] = self.results[index].split('_')[0] + "_False" + self.change_image() + + def on_button3(self): + # Go back + if not (self.my_image_number == 0 and self.batch_number == 0): # can not go back at first image + # Revert last label + index = self.my_image_number + (self.batch_number * self.batch_size) + self.results[index-1] = self.results[index-1].split('_')[0] # remove previous label + + if self.my_image_number == 0: # already in new batch + self.batch_number -= 1 + self.my_image_number = 8 # will become 9 in change_image() + self.load_img_batch(self.batch_number) # load previous batch + else: + self.my_image_number -= 2 # will increase once in change_image() + self.change_image() + + def on_button4(self): + # Save + print_res(self.results, self.save_file) + + def load_img_batch(self, index): + if DEBUG: + print(f"load_img_batch: {index}") + start = self.batch_size * index + end = start + self.batch_size + self.my_images = [] + for fname in self.fnames[start:end]: + self.my_images.append(get_img(os.path.join(self.ds_dir, fname))) + + def left_key(self, _): + self.on_button2() + + def right_key(self, _): + self.on_button1() + + def up_key(self, _): + self.on_button3() + + def down_key(self, _): + self.on_button4() + + +MainWindow(root) +root.mainloop()