-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 更新README * 新增AI放大,支持多种算法 * 更改启动方式,现在可以带参数启动了 * 新增install.py,现在可以作为库来引入你的项目 * 修复若干BUG
- Loading branch information
1 parent
0b2993a
commit 78080f5
Showing
16 changed files
with
824 additions
and
322 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
from .data import Data | ||
from .filter import Filter | ||
from .processor import Processor,ProcessorError | ||
from .processor import Processor, ProcessorError | ||
from .uitl import * | ||
from .tools import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from PIL import Image | ||
import os | ||
|
||
|
||
class Data: | ||
|
||
# 图片读取并初始化 | ||
def __init__(self, path: str, name: str, ext: str): | ||
self.token: list[str] = [] | ||
self.conduct = "" | ||
self.repeat = 0 | ||
self.id = 0 | ||
self.name = name | ||
self.ext = ext | ||
self.path = path | ||
# 读取图片 | ||
self.img = Image.open(os.path.join(path, name + ext)) | ||
self.size = self.img.size | ||
|
||
# 载入标签 | ||
def input_token(self, file_name: str, option=None): | ||
clean_tag = False | ||
NO_CHECK = [ # 清洗排除标签 | ||
':)', ';)', ':(', '>:)', '>:(', '\\(^o^)/', # 括号相关 | ||
'^_^', '@_@', '>_@', '+_+', '+_-', 'o_o', '0_0', '|_|', '._.', '>_<', '=_=', '<o>_<o>', '<|>_<|>' # 下划线相关 | ||
] | ||
if option.clean_tag: | ||
clean_tag = True | ||
with open(os.path.join(self.path, file_name), "r") as f: | ||
self.token = f.read(-1).split(",") | ||
for tag in self.token: | ||
tag = tag.strip() | ||
if clean_tag: | ||
if tag not in NO_CHECK: | ||
tag = tag.replace("_", " ") | ||
tag = tag.replace("(", "\\(") | ||
tag = tag.replace(")", "\\)") | ||
|
||
# 保存的方法 | ||
def save(self, output_dir, option): | ||
# 默认命名方式:id_conduct_repeat.ext 比如"000001_r_0.jpg" | ||
save_name = str(self.id).zfill(6) + self.conduct | ||
if option: | ||
if option.save_source_name or option.save_conduct_id: | ||
save_name = str(self.id).zfill(6) | ||
if option.save_source_name: | ||
save_name = save_name.join('_' + self.name) | ||
if option.save_conduct_id: | ||
save_name = save_name.join(self.conduct) | ||
self.img.save(os.path.join(output_dir, save_name + self.ext)) | ||
# print(save_name) | ||
with open(os.path.join(output_dir, save_name + ".txt"), mode="w") as f: | ||
text = ",".join(self.token) | ||
f.write(text) | ||
self.img.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from .data import Data | ||
|
||
|
||
class Filter: | ||
""" | ||
这是一个过滤器类,包含所有有关数据过滤的函数 | ||
编写规范如下: | ||
def 过滤器名(data:Data,arg)->bool: | ||
#代码块 | ||
return bool | ||
其中,True表示该数据会被过滤,False则会被保留 | ||
""" | ||
|
||
def img_size(data: Data, size: list) -> bool: | ||
min, max = tuple(size) | ||
x, y = data.size | ||
if min != -1: | ||
if data.size[0] <= min or data.size[1] <= min: | ||
return True | ||
if max != -1: | ||
if data.size[0] > max and data.size[1] > max: | ||
return True | ||
else: | ||
return False | ||
|
||
def tag_filter(data: Data, tag) -> bool: | ||
if tag in data.token: | ||
return True | ||
else: | ||
return False | ||
|
||
def tag_selector(data: Data, tag) -> bool: | ||
if tag in data.token: | ||
return False | ||
else: | ||
return True | ||
|
||
def tag_is_not_none(data: Data) -> bool: | ||
if data.token: | ||
return False | ||
else: | ||
return True | ||
|
||
def tag_is_none(data: Data) -> bool: | ||
if data.token: | ||
return True | ||
else: | ||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from .tagger import Tagger, TaggerOption | ||
from .upscale import UpscaleModel, UpcaleOption |
Oops, something went wrong.