Merge pull request #1 from deeppomf/master

update
This commit is contained in:
ccppoo 2019-11-01 13:43:51 +09:00 committed by GitHub
commit 6b34feab97
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 62 additions and 48 deletions

View File

@ -60,7 +60,7 @@ Miscellaneous:
Follow me on Twitter [@deeppomf](https://twitter.com/deeppomf) (NSFW Tweets) for project updates.
## Contributions
Contributions are closed for the near future.
If you want to make a pull request to DeepCreamPy, you must first sign our [Contributor License Agreement](https://github.com/deeppomf/contributing/blob/master/sign-cla.md#sign-the-cla) (the "CLA"). Then I can accept your pull requests.
Special thanks to ccppoo, IAmTheRedSpy, 0xb8, deniszh, Smethan, mrmajik45, harjitmoe, itsVale, StartleStars, and SoftArmpit for their contributions!

View File

@ -42,7 +42,7 @@ class Decensor(QtCore.QThread):
self.decensor_input_original_path = args.decensor_input_original_path
self.decensor_output_path = args.decensor_output_path
self.signals = None # Singals class will be given by progressWindow
self.signals = None # Signals class will be given by progressWindow
if ui_mode is not None:
self.ui_mode = ui_mode
@ -65,14 +65,14 @@ class Decensor(QtCore.QThread):
self.terminate()
def find_mask(self, colored):
self.signals.update_progress_LABEL.emit("find_mask()", "finding mask...")
# self.signals.update_progress_LABEL.emit("find_mask()", "finding mask...")
mask = np.ones(colored.shape, np.uint8)
i, j = np.where(np.all(colored[0] == self.mask_color, axis=-1))
mask[0, i, j] = 0
return mask
def load_model(self):
self.signals.update_progress_LABEL.emit("load_model()", "loading model...")
self.signals.update_progress_LABEL.emit("load_model()", "Loading neural network. This may take a while.")
self.model = InpaintNN(bar_model_name = "./models/bar/Train_775000.meta",
bar_checkpoint_name = "./models/bar/",
mosaic_model_name = "./models/mosaic/Train_290000.meta",
@ -90,18 +90,18 @@ class Decensor(QtCore.QThread):
output_dir = self.decensor_output_path
# Change False to True before release --> file.check_file(input_dir, output_dir, True)
self.signals.update_progress_LABEL.emit("file.check_file()", "checking image files and directory...")
self.signals.update_progress_LABEL.emit("file.check_file()", "Checking image files and directory...")
file_names, self.files_removed = file.check_file(input_dir, output_dir, False)
self.signals.total_ProgressBar_update_MAX_VALUE.emit("set total progress bar MaxValue : "+str(len(file_names)),len(file_names))
#convert all images into np arrays and put them in a list
for n, file_name in enumerate(file_names, start = 1):
self.signals.total_ProgressBar_update_VALUE.emit("decensoring {} / {}".format(n, len(file_names)), n)
# singal progress bar value == masks decensored on image ,
self.signals.total_ProgressBar_update_VALUE.emit("Decensoring {} / {}".format(n, len(file_names)), n)
# signal progress bar value == masks decensored on image ,
# e.g) sample image : 17
self.signals.singal_ProgressBar_update_VALUE.emit("reset value", 0) # set to 0 for every image at start
self.signals.update_progress_LABEL.emit("for-loop, \"for file_name in file_names:\"","decensoring : "+str(file_name))
self.signals.signal_ProgressBar_update_VALUE.emit("reset value", 0) # set to 0 for every image at start
self.signals.update_progress_LABEL.emit("for-loop, \"for file_name in file_names:\"","Decensoring : "+str(file_name))
color_file_path = os.path.join(input_color_dir, file_name)
color_basename, color_ext = os.path.splitext(file_name)
@ -146,6 +146,8 @@ class Decensor(QtCore.QThread):
self.custom_print("\nDecensoring complete!")
#unload model to prevent memory issues
self.signals.update_progress_LABEL.emit("finished", "Decensoring complete! Close this window and reopen DCP to start a new session.")
tf.reset_default_graph()
def decensor_image_variations(self, ori, colored, file_name=None):
@ -203,11 +205,11 @@ class Decensor(QtCore.QThread):
self.custom_print("No green regions detected! Make sure you're using exactly the right color.")
return
self.signals.singal_ProgressBar_update_MAX_VALUE.emit("found {} masked regions".format(len(regions)), len(regions))
self.signals.signal_ProgressBar_update_MAX_VALUE.emit("Found {} masked regions".format(len(regions)), len(regions))
output_img_array = ori_array[0].copy()
for region_counter, region in enumerate(regions, 1):
self.signals.update_progress_LABEL.emit("for-loop, \"for region_counter, region in enumerate(regions, 1):\"","decensoring censor {}/{}".format(region_counter,len(regions)))
self.signals.update_progress_LABEL.emit("\"Decensoring regions in image\"","Decensoring censor {}/{}".format(region_counter,len(regions)))
bounding_box = expand_bounding(ori, region, expand_factor=1.5)
crop_img = ori.crop(bounding_box)
# crop_img.show()
@ -287,7 +289,7 @@ class Decensor(QtCore.QThread):
bounding_height_index = row + bounding_box[1]
if (bounding_width_index, bounding_height_index) in region:
output_img_array[bounding_height_index][bounding_width_index] = pred_img_array[i,:,:,:][row][col]
self.signals.singal_ProgressBar_update_VALUE.emit("{} out of {} regions decensored.".format(region_counter, len(regions)), region_counter)
self.signals.signal_ProgressBar_update_VALUE.emit("{} out of {} regions decensored.".format(region_counter, len(regions)), region_counter)
self.custom_print("{region_counter} out of {region_count} regions decensored.".format(region_counter=region_counter, region_count=len(regions)))
output_img_array = output_img_array * 255.0
@ -299,7 +301,7 @@ class Decensor(QtCore.QThread):
output_img = Image.fromarray(output_img_array.astype('uint8'))
output_img = self.apply_variant(output_img, variant_number)
self.signals.update_progress_LABEL.emit("finished", "decensoring finished, saving as file...")
self.signals.update_progress_LABEL.emit("current image finished", "Decensoring of current image finished. Saving image...")
if file_name != None:
#save the decensored image
@ -315,16 +317,17 @@ class Decensor(QtCore.QThread):
return output_img
def custom_print(self, text):
if self.ui_mode:
from PySide2.QtGui import QTextCursor
print(text)
# if self.ui_mode:
# from PySide2.QtGui import QTextCursor
self.text_cursor.insertText(text)
self.text_cursor.insertText("\n")
self.text_edit.moveCursor(QTextCursor.End)
else:
print(text)
# self.text_cursor.insertText(text)
# self.text_cursor.insertText("\n")
# self.text_edit.moveCursor(QTextCursor.End)
# else:
# print(text)
if __name__ == '__main__':
decensor = Decensor()
decensor.decensor_all_images_in_folder()
# if __name__ == '__main__':
# decensor = Decensor()
# decensor.decensor_all_images_in_folder()
# equivalent to decensor.start() (running as QtThread)

View File

@ -2,9 +2,10 @@
## Where can I get your training data?
I can't say what my data sources are because too many people downloading from them could cause them to block scraping.
[Danbooru2018](https://www.gwern.net/Danbooru2018) is a good starting point.
## Where can I get your training code?
My training code is mostly unchanged from MathiasGruber's project [Partial Convolutions for Image Inpainting using Keras](https://github.com/MathiasGruber/PConv-Keras), which is an unofficial implementation of the paper [Image Inpainting for Irregular Holes Using Partial Convolutions](https://arxiv.org/abs/1804.07723).
My training code is is modified from Forty-lock's project [PEPSI](https://github.com/Forty-lock/PEPSI), which is the official implementation of the paper [PEPSI : Fast Image Inpainting With Parallel Decoding Network](http://openaccess.thecvf.com/content_CVPR_2019/html/Sagong_PEPSI__Fast_Image_Inpainting_With_Parallel_Decoding_Network_CVPR_2019_paper.html). [PEPSI](https://github.com/Forty-lock/PEPSI) is licensed under the MIT license.
## Why aren't black and white images supported? Black and white images seem easier to decensor than color images.
Black and white images contain screentone patterns which are difficult for neural networks to replicate.
@ -13,4 +14,4 @@ Black and white images contain screentone patterns which are difficult for neura
It's on my to-do list, but it's not a high priority.
## Does this work with real life porn?
It's not meant to, but you might get OK results anyways.
DeepCreamPy is not trained on real life porn, so it will not work with real life porn.

View File

@ -24,7 +24,7 @@ Decensor the images by double-clicking on the decensor file.
Decensor the images by running
```
$ python decensor.py
$ python main.py
```
Decensored images will be saved to the "decensor_output" folder. Decensoring takes a few minutes per image.
@ -46,7 +46,7 @@ Decensor the images by double-clicking on the decensor_mosaic file.
Decensor the images by running
```
$ python decensor.py --is_mosaic=True
$ python main.py
```
Decensored images will be saved to the "decensor_output" folder. Decensoring takes a few minutes per image.

View File

@ -27,7 +27,7 @@ class MainWindow(QWidget):
#Tutorial
self.tutorialLabel = QLabel()
self.tutorialLabel.setText("Welcome to DeepCreamPy!\n\nIf you're new to DCP, please read the README.\nThis program does nothing without the proper setup of your images.\n\nSince this is an alpha release, expect issues like crashing or freezing.\nReport them to me on Github or Twitter @deeppomf.")
self.tutorialLabel.setText("Welcome to DeepCreamPy!\n\nIf you're new to DCP, please read the README.\nThis program does nothing without the proper setup of your images.\n\nReport any bugs you encounter to me on Github or Twitter @deeppomf.")
self.tutorialLabel.setAlignment(Qt.AlignCenter)
self.tutorialLabel.setFont(QFont('Sans Serif', 13))
@ -85,7 +85,7 @@ class MainWindow(QWidget):
#window size settings
self.resize(500, 500)
self.center()
self.setWindowTitle('DeepCreamPy v2.2.0-alpha')
self.setWindowTitle('DeepCreamPy v2.2.0-beta')
self.show()
def decensorClicked(self):
@ -121,6 +121,8 @@ class MainWindow(QWidget):
self.progress = ProgressWindow(self, decensor = decensor)
# decensor.decensor_all_images_in_folder()
# self.progress.hide()
# self.show()
# def showAbout(self):
# QMessageBox.about(self, 'About', "DeepCreamPy v2.2.0 \n Developed by deeppomf")

View File

@ -4,7 +4,7 @@
import sys
import PySide2
from PySide2.QtWidgets import (QApplication, QMainWindow, QPushButton,
from PySide2.QtWidgets import (QApplication, QMainWindow, QDesktopWidget, QPushButton,
QToolTip, QLabel, QProgressBar, QAction, qApp)
# from PyQt5.QtCore import QThread
from signals import Signals
@ -18,11 +18,13 @@ class ProgressWindow(QMainWindow):
self.width = 700
self.height = 500
self.resize(self.width, self.height)
self.setWindowTitle("DeepCreamPy v2.2.0 Decensoring...")
self.initUI()
# signal class that could share update progress ui from decensor class (Decensor)
self.setSignals()
self.center()
self.setWindowTitle("DeepCreamPy v2.2.0 Decensoring...")
self.show()
if not debug:
@ -64,19 +66,19 @@ class ProgressWindow(QMainWindow):
self.total_images_ProgressBar.setValue(0)
# showing progress of decensored area
self.singal_image_decensor_ProgressBar = QProgressBar(self)
self.singal_image_decensor_ProgressBar.setGeometry(bar_X, bar_Y+80, bar_width,bar_height )
self.singal_image_decensor_ProgressBar.setMaximum(100)
self.singal_image_decensor_ProgressBar.setValue(0)
self.signal_image_decensor_ProgressBar = QProgressBar(self)
self.signal_image_decensor_ProgressBar.setGeometry(bar_X, bar_Y+80, bar_width,bar_height )
self.signal_image_decensor_ProgressBar.setMaximum(100)
self.signal_image_decensor_ProgressBar.setValue(0)
progress_Label_1 = QLabel(self)
progress_Label_1.move(50, 270)
progress_Label_1.setText("Number of your images")
progress_Label_1.setText("Decensor progress of all images")
progress_Label_1.resize(progress_Label_1.sizeHint())
progress_Label_2 = QLabel(self)
progress_Label_2.move(50, 300 + 50)
progress_Label_2.setText("Number of image censoring")
progress_Label_2.setText("Decensor progress of current image")
progress_Label_2.resize(progress_Label_2.sizeHint())
self.progress_status_LABEL = QLabel(self)
@ -86,13 +88,19 @@ class ProgressWindow(QMainWindow):
setProgressBar()
def center(self):
qr = self.frameGeometry()
cp = QDesktopWidget().availableGeometry().center()
qr.moveCenter(cp)
self.move(qr.topLeft())
def setSignals(self):
self.signals = Signals()
# set signal variable name same as method name preventing confusion
self.signals.total_ProgressBar_update_MAX_VALUE.connect(self.total_ProgressBar_update_MAX_VALUE)
self.signals.total_ProgressBar_update_VALUE.connect(self.total_ProgressBar_update_VALUE)
self.signals.singal_ProgressBar_update_MAX_VALUE.connect(self.singal_ProgressBar_update_MAX_VALUE)
self.signals.singal_ProgressBar_update_VALUE.connect(self.singal_ProgressBar_update_VALUE)
self.signals.signal_ProgressBar_update_MAX_VALUE.connect(self.signal_ProgressBar_update_MAX_VALUE)
self.signals.signal_ProgressBar_update_VALUE.connect(self.signal_ProgressBar_update_VALUE)
self.signals.update_progress_LABEL.connect(self.update_progress_LABEL)
# total_images_to_decensor_ProgressBar
@ -106,15 +114,15 @@ class ProgressWindow(QMainWindow):
print(msg)
self.total_images_ProgressBar.setValue(val)
def singal_ProgressBar_update_MAX_VALUE(self, msg, max):
def signal_ProgressBar_update_MAX_VALUE(self, msg, max):
# print msg for debugging
print(msg)
self.singal_image_decensor_ProgressBar.setMaximum(max)
self.signal_image_decensor_ProgressBar.setMaximum(max)
def singal_ProgressBar_update_VALUE(self, msg, val):
def signal_ProgressBar_update_VALUE(self, msg, val):
# print msg for debugging
print(msg)
self.singal_image_decensor_ProgressBar.setValue(val)
self.signal_image_decensor_ProgressBar.setValue(val)
def update_progress_LABEL(self, msg, status):
print(msg)
@ -123,7 +131,7 @@ class ProgressWindow(QMainWindow):
def runDecensor(self):
# start decensor in other thread, preventing UI Freezing
print("start run")
# print("start run")
self.decensor.start()
if __name__ == "__main__":

View File

@ -9,7 +9,7 @@ Keras-Preprocessing==1.1.0
Markdown==3.1.1
numpy==1.17.0
opencv-python==4.1.0.25
Pillow==6.1.0
Pillow==6.2.0
protobuf==3.9.1
PySide2==5.13.0
scipy==1.3.0

View File

@ -9,7 +9,7 @@ Keras-Preprocessing==1.1.0
Markdown==3.1.1
numpy==1.17.0
opencv-python==4.1.0.25
Pillow==6.1.0
Pillow==6.2.0
protobuf==3.9.1
PySide2==5.13.0
scipy==1.3.0

View File

@ -10,8 +10,8 @@ class Signals(QtCore.QObject):
total_ProgressBar_update_MAX_VALUE = QtCore.Signal(str, int)
total_ProgressBar_update_VALUE = QtCore.Signal(str, int)
singal_ProgressBar_update_MAX_VALUE = QtCore.Signal(str, int)
singal_ProgressBar_update_VALUE = QtCore.Signal(str, int)
signal_ProgressBar_update_MAX_VALUE = QtCore.Signal(str, int)
signal_ProgressBar_update_VALUE = QtCore.Signal(str, int)
# str : tells status (print in cmd for debug)
# str : String to update label