Code and demo dataset master
authorProject Hentai AI <hentai-ai@hentai-ai.org>
Wed, 2 Feb 2022 12:40:57 +0000 (12:40 +0000)
committerProject Hentai AI <hentai-ai@hentai-ai.org>
Wed, 2 Feb 2022 12:40:57 +0000 (12:40 +0000)
22 files changed:
demo_input_dir/thighs-0000-crop.png [new file with mode: 0644]
demo_input_dir/thighs-0001-crop.png [new file with mode: 0644]
demo_input_dir/thighs-0002-crop.png [new file with mode: 0644]
demo_input_dir/thighs-0003-crop.png [new file with mode: 0644]
demo_input_dir/thighs-0004-crop.png [new file with mode: 0644]
demo_input_dir/thighs-0005-crop.png [new file with mode: 0644]
demo_input_dir/thighs-0006-crop.png [new file with mode: 0644]
demo_input_dir/thighs-0007-crop.png [new file with mode: 0644]
demo_input_dir/thighs-0008-crop.png [new file with mode: 0644]
demo_input_dir/thighs-0009-crop.png [new file with mode: 0644]
demo_input_dir/thighs-0010-crop.png [new file with mode: 0644]
demo_input_dir/thighs-0011-crop.png [new file with mode: 0644]
demo_input_dir/thighs-0012-crop.png [new file with mode: 0644]
demo_input_dir/thighs-0013-crop.png [new file with mode: 0644]
demo_input_dir/thighs-0014-crop.png [new file with mode: 0644]
demo_input_dir/thighs-0015-crop.png [new file with mode: 0644]
demo_input_dir/thighs-0016-crop.png [new file with mode: 0644]
demo_input_dir/thighs-0017-crop.png [new file with mode: 0644]
demo_input_dir/thighs-0018-crop.png [new file with mode: 0644]
demo_input_dir/thighs-0019-crop.png [new file with mode: 0644]
demo_input_dir/thighs-0020-crop.png [new file with mode: 0644]
hentai-tinder.py [new file with mode: 0644]

diff --git a/demo_input_dir/thighs-0000-crop.png b/demo_input_dir/thighs-0000-crop.png
new file mode 100644 (file)
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 (file)
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 (file)
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 (file)
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 (file)
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 (file)
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 (file)
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 (file)
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 (file)
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 (file)
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 (file)
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 (file)
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 (file)
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 (file)
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 (file)
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 (file)
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 (file)
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 (file)
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 (file)
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 (file)
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 (file)
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 (file)
index 0000000..0fe04bc
--- /dev/null
@@ -0,0 +1,175 @@
+from tkinter import *\r
+from PIL import ImageTk, Image\r
+import os\r
+import sys\r
+\r
+root = Tk()\r
+root.title('Hentai Tinder')\r
+DEBUG = False\r
+\r
+# Todo:\r
+\r
+\r
+def get_img(path):\r
+    img = Image.open(path).resize((250, 250), Image.ANTIALIAS)\r
+    return ImageTk.PhotoImage(img)\r
+\r
+\r
+def print_res(res, save_path):\r
+    print("saving results...")\r
+    with open(save_path, "w") as f:\r
+        for r in res:\r
+            f.write(r + '\n')\r
+\r
+\r
+class MainWindow:\r
+\r
+    def __init__(self, main):\r
+        self.canvas = Canvas(main, width=250, height=300)\r
+        self.canvas.pack()\r
+\r
+        main.bind('<Left>', self.left_key)\r
+        main.bind('<Right>', self.right_key)\r
+        main.bind('<Up>', self.up_key)\r
+        main.bind('<Down>', self.down_key)\r
+\r
+        self.results = []\r
+        self.my_images = []\r
+        self.batch_number = 0\r
+        self.my_image_number = 0\r
+\r
+        self.save_file = "results.txt"\r
+        self.ds_dir = "thighs_dataset"\r
+        if not os.path.isdir(self.ds_dir):\r
+            sys.exit('dataset directory not found!')\r
+        self.fnames = os.listdir(self.ds_dir)\r
+        if len(self.fnames) == 0:\r
+            sys.exit('found no data in dataset directory!')\r
+\r
+        for fname in self.fnames:\r
+            self.results.append(str(fname))\r
+\r
+        self.batch_size = 10\r
+        self.load_img_batch(0)\r
+\r
+        # load save-file\r
+        if os.path.isfile(self.save_file):\r
+            print(f"found {self.save_file}, loading...")\r
+            counter = 0\r
+            self.results = []\r
+            with open(self.save_file, "r") as f:\r
+                for line in f.read().splitlines():\r
+                    self.results.append(line)\r
+                    if "True" in line or "False" in line:\r
+                        counter += 1\r
+            if counter == len(self.results):\r
+                sys.exit(f"{self.save_file} is already completed")\r
+            self.batch_number = int(counter/self.batch_size)\r
+            self.load_img_batch(self.batch_number)\r
+            self.my_image_number = counter % self.batch_size\r
+\r
+        # set first image on canvas\r
+        self.image_on_canvas = self.canvas.create_image(0, 0, anchor=NW, image=self.my_images[self.my_image_number])\r
+\r
+        # buttons\r
+        self.button1 = Button(main, text="Smash", command=self.on_button1)\r
+        self.button1.pack(side=RIGHT, padx=20)\r
+\r
+        self.button2 = Button(main, text="Pass", command=self.on_button2)\r
+        self.button2.pack(side=LEFT, padx=20)\r
+\r
+        self.button3 = Button(main, text="Go back", command=self.on_button3)\r
+        self.button3.pack()\r
+\r
+        self.button4 = Button(main, text="Save", command=self.on_button4)\r
+        self.button4.pack()\r
+\r
+        # labels\r
+        index = self.my_image_number + (self.batch_number * self.batch_size)\r
+        self.label1 = Label(main, text=self.results[index].split('.')[0])\r
+        self.label1.place(x=80, y=260)\r
+\r
+        self.label2 = Label(main, text=f"{index+1}/{len(self.fnames)}")\r
+        self.label2.place(x=100, y=280)\r
+\r
+    def change_image(self):\r
+        self.my_image_number += 1\r
+        if DEBUG:\r
+            print(f"img: {self.my_image_number}, batch: {self.batch_number}")\r
+            print(self.results)\r
+\r
+        if self.my_image_number == len(self.my_images):\r
+            if DEBUG:\r
+                print("end of batch")\r
+            if self.batch_number == 9:\r
+                print_res(self.results, self.save_file)\r
+                print("exiting...")\r
+                root.destroy()\r
+                sys.exit(0)\r
+            else:\r
+                if DEBUG:\r
+                    print("loading new batch")\r
+                self.batch_number += 1\r
+                self.load_img_batch(self.batch_number)\r
+                self.my_image_number = 0\r
+        # change image and labels\r
+        self.canvas.itemconfig(self.image_on_canvas, image=self.my_images[self.my_image_number])\r
+        index = self.my_image_number + (self.batch_number * self.batch_size)\r
+        self.label1.configure(text=self.results[index].split('.')[0])\r
+        self.label2.configure(text=f"{index+1}/{len(self.fnames)}")\r
+\r
+    def on_button1(self):\r
+        # Smash\r
+        index = self.my_image_number + (self.batch_number * self.batch_size)\r
+        self.results[index] = self.results[index].split('_')[0] + "_True"\r
+        self.change_image()\r
+\r
+    def on_button2(self):\r
+        # Pass\r
+        index = self.my_image_number + (self.batch_number * self.batch_size)\r
+        self.results[index] = self.results[index].split('_')[0] + "_False"\r
+        self.change_image()\r
+\r
+    def on_button3(self):\r
+        # Go back\r
+        if not (self.my_image_number == 0 and self.batch_number == 0):  # can not go back at first image\r
+            # Revert last label\r
+            index = self.my_image_number + (self.batch_number * self.batch_size)\r
+            self.results[index-1] = self.results[index-1].split('_')[0]  # remove previous label\r
+\r
+            if self.my_image_number == 0:  # already in new batch\r
+                self.batch_number -= 1\r
+                self.my_image_number = 8  # will become 9 in change_image()\r
+                self.load_img_batch(self.batch_number)  # load previous batch\r
+            else:\r
+                self.my_image_number -= 2  # will increase once in change_image()\r
+            self.change_image()\r
+\r
+    def on_button4(self):\r
+        # Save\r
+        print_res(self.results, self.save_file)\r
+\r
+    def load_img_batch(self, index):\r
+        if DEBUG:\r
+            print(f"load_img_batch: {index}")\r
+        start = self.batch_size * index\r
+        end = start + self.batch_size\r
+        self.my_images = []\r
+        for fname in self.fnames[start:end]:\r
+            self.my_images.append(get_img(os.path.join(self.ds_dir, fname)))\r
+\r
+    def left_key(self, _):\r
+        self.on_button2()\r
+\r
+    def right_key(self, _):\r
+        self.on_button1()\r
+\r
+    def up_key(self, _):\r
+        self.on_button3()\r
+\r
+    def down_key(self, _):\r
+        self.on_button4()\r
+\r
+\r
+MainWindow(root)\r
+root.mainloop()\r