Removed files help/binary files from CartoonSegmentation project directory to encourage users to head to that CartoonSegmentation GitHub.

This commit is contained in:
nlar
2024-01-25 15:26:09 -07:00
parent 111483f503
commit ac9e32a0be
11 changed files with 0 additions and 5878 deletions
@@ -1 +0,0 @@
Character_NewLine="\n"
@@ -1,20 +0,0 @@
import numpy as Number
# Pending
def depth_edges_mask(depth):
"""Returns a mask of edges in the depth map.
Args:
depth: 2D numpy array of shape (H, W) with dtype float32.
Returns:
mask: 2D numpy array of shape (H, W) with dtype bool.
"""
# Compute the x and y gradients of the depth map.
depth_dx, depth_dy = Number.gradient(depth)
# Compute the gradient magnitude.
depth_grad = Number.sqrt(depth_dx ** 2 + depth_dy ** 2)
# Compute the edge mask.
mask = depth_grad > 0.05
return mask
@@ -1,80 +0,0 @@
import os.path as Pathing
import os as OS
import torch
from diffusers import StableDiffusionPipeline as Pipeline
import torch as Engine
# !需要完全地面向对象传值
# ·Stable Diffusion Web UI使用ldm Library读取Model,超出本项目的需求,直接恢复PyTorch直读
class Model:
# Field
ListModel = [ ]
Model_Activated=None
# !需要转为Private
Directory_Diffusion = F"./Reference/Model/Diffusion"
# Method
# 拉取相对路径
@staticmethod
def List_CheckPointTile () :
if Model.ListModel is True :
return Model.Refresh ()
else :
return Model.Initialise ()
# Core
@staticmethod
def IsCorrectModelType ( File , Filter = None ) :
if (Filter is None) :
return File.endswith ( F".vae." ) == False # 需要调整
else :
return True # 暂定
@staticmethod
def Initialise () :
# Path_Processing = Directory.join ( OS.getcwd ().replace ( "\\" , "/" ) , Model.Directory_Diffusion ) # !需要更优雅地跨平台
Path_Processing = Model.Directory_Diffusion
List_Return = Model.ListModel = [ File for File in OS.listdir ( Path_Processing ) if Model.IsCorrectModelType ( File ) ] # Only scan the 1st level folder as item
return List_Return
@staticmethod
def Refresh () :
pass
# ?我记得是等号不是冒号+等号
# ?Diffusion能否直接使用PyTorch操作,不能的话需要转为Diffusers Library的Pipeline进行Instantiate
# Load_Model:=lambda Model_Input :Model_Activated=Engine.load(Directory_Diffusion)
@staticmethod
def Load_Model ( Model_Input , Variant_In = "fp16" , Type_In = torch.float16 ) :
# Path_Relative=OS.path.join(Directory_Diffusion,Model_Input)
# Path_Relative=F"{Directory_Diffusion}/{Model_Input}"
Path_Relative = F"{Model.Directory_Diffusion}/{Model_Input}"
Model_Return:str=str()
try:
Model_Return=Pipeline.from_pretrained(Path_Relative,variant = Variant_In,torch_dtype = Type_In)
# Model_Return = Pipeline.from_pretrained ( Path_Relative )
except Exception: # !需要扩充|替换
# !需要增加try来解决不合格Model的剔除,或转为其他方式调用(如原生PyTorch)
print(F"Error occurred: {Exception}")
return Model_Return # !需要去除冗余
else:
pass
Model_Return.to ( "cuda" ) # !需要提取常量|变量
# Debug
print ( F"Model {Model_Input} has been loaded successfully." ) # !需要转为Model的自身描述信息
return Model_Return
@@ -1,32 +0,0 @@
import os.path as Pathing
import os as OS
# ·!未实现
# Field
ListSampler = [ ]
# Method
# 拉取绝对路径
def List_Sampler () :
if ListSampler is not None :
Refresh ()
else :
Initialise ()
# Core
def IsCorrectStyleType ( File , Filter = None ) :
if (Filter is None) :
return True # 暂定
else :
return True # 暂定
def Initialise () :
Path_Processing = Directory.join ( OS.getcwd ().replace ( "\\" , "/" ) , F"./Reference/Model/Diffusion" )
List_Return = [ File for File in OS.listdir ( Path_Processing ) if IsCorrectStyleType ( File ) ]
return List_Return
def Refresh () :
pass
@@ -1,32 +0,0 @@
import os.path as Pathing
import os as OS
# ·!未实现
# Field
ListStyle = [ ]
# Method
# 拉取绝对路径
def List_Style () :
if ListStyle is not None :
Refresh ()
else :
Initialise ()
# Core
def IsCorrectStyleType ( File , Filter = None ) :
if (Filter is None) :
return True # 暂定
else :
return True # 暂定
def Initialise () :
Path_Processing = Pathing.join ( OS.getcwd ().replace ( "\\" , "/" ) , F"./Reference/Model/Diffusion" )
List_Return = [ File for File in OS.listdir ( Path_Processing ) if IsCorrectStyleType ( File ) ]
return List_Return
def Refresh () :
pass
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -1,93 +0,0 @@
#region Script Pre-processing
# Test by Francis
import os as OS
#
print ( F"{OS.getcwd()=}" )
# import os.path as Pathing
# import sys as Environment
# #
# Directory_Current = Pathing.dirname ( Pathing.abspath ( __file__ ) )
# Directory_Project = Pathing.dirname(Pathing.dirname ( Directory_Current ))
# print ( F"{Directory_Project=}" )
# Environment.path.append ( Directory_Project )
# OS.chdir(Directory_Project)
# #
# print ( F"{OS.getcwd()=}" )
#endregion Script Pre-processing
import gradio as Framework
import Web_UI.Component.Component_AIS as Control_AIS
import Web_UI.Component.Component_Style_Editing as Control_StyleEditing
# ·当前的Gradio有如下限制,导致必须将UI相关的定义Inline放置:
# -在Block中直接创建Control的Instance,否则不显示
# -强制Control的Event Binding在Block中
# ·探索是否具有Class点出Member的方式简化各个COntrol的Variable的调用+区分
# Class
class Application :
def Launch ( self , IsSharing_In = False , Address_In = F"0.0.0.0" , Port_In = 7860 ) : # ?或更名为Create_UI(),与其他部分的Initialising一起调用的部分叫Launch()
# !需要COnstant化
# Debug
print ( F"Gradio based Web Site has been launched successfully, on https://{Address_In}:{Port_In}" )
Title=F"Web UI-Anime Instance Segmentation" #!需要修改一致
# Draw basic Frame Page
Framework.Markdown ( Title ) # Title
Framework.Markdown ( F"" ) # Version
Framework.Markdown ( F"" ) # Description
with Framework.Blocks\
(
css = F"file=Resource/Style/Style-Genral.css",
# _js = F"file=Resource/Function/Function-Genral.js",
) as Page :
Content_Page = self.Create_Content_Page ()
# return Page.launch\
return Page.queue ()\
.launch\
(
share = IsSharing_In,
server_name =Address_In,
server_port = Port_In,
)
# !布局为主的部分虽然用函数的形式分离了,但感觉还是应该在Frame的File中
def Create_Content_Page (self) :
"""
Tabs of Anime Instance Segementation, created by 林 健
Returns:
"""
Framework.Markdown(F"<h1>Instance-guided Cartoon Editing</ h1>")
# 2 Ways: 1st separate Functions into Event Handler; 2nd just read Temporary Result
# Now, only 2nd Way succeeded
Tab_Demonstration_Steping = Control_AIS.Create_Stepping_Demonstration_Tab ()
# Pending
# Tab_Demonstration_Original = Control_AIS.Create_Original_Demonstration_Tab ()
# Style Editing
Tab_Demonstration_StyleEditing = Control_StyleEditing.Create_Style_Editing_Demonstration_Tab ()
# Tab_Demonstration_Migrated = Create_Demonstration_Tab ()
# Tab_Information = Create_Information_Tab ()
# Tab_Setting = Control_AIS.Create_Setting_Tab ()
# Bind Event handler
-69
View File
@@ -1,69 +0,0 @@
#region Script Pre-processing
# Test by Francis
import os as OS
#
print ( F"{OS.getcwd()=}" )
import os.path as Pathing
import sys as Environment
#
Directory_Current = Pathing.dirname ( Pathing.abspath ( __file__ ) )
Directory_Project = Pathing.dirname ( Directory_Current )
print ( F"{Directory_Project=}" )
Environment.path.append ( Directory_Project )
OS.chdir(Directory_Project)
#
print ( F"{OS.getcwd()=}" )
#endregion Script Pre-processing
#region Import
#region Reference
# import torch as Engine
# import cv2 as Vision
#endregion Reference
#region Self
# import Web_UI.Component.Frame_Main as Page
import Component.Frame_Main as Page
#endregion Self
#endregion Import
#region Method
def Execute_Application (IsSharing_In = False,Port_In=1234) :
Application = Page.Application ()
Application.Launch \
(
IsSharing_In = IsSharing_In ,
Port_In = Port_In ,
)
#endregion Method
#region Entry Point
if __name__ == F"__main__" :
# !未解决Base | Root识别为General Web UI这个Directory的问题
Execute_Application\
(
IsSharing_In = True,
)
else :
pass
#endregion Entry Point
-329
View File
@@ -1,329 +0,0 @@
{
"cells": [
{
"cell_type": "markdown",
"source": [
"# Project files deploying"
],
"metadata": {
"id": "EnzS36wUS1t_"
}
},
{
"cell_type": "code",
"source": [
"# Download it from GitHub\n",
"!git clone https://github.com/CartoonSegmentation/CartoonSegmentation"
],
"metadata": {
"id": "aCOSc120S9hu"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"%cd CartoonSegmentation\n",
"#\n",
"!ls -alh"
],
"metadata": {
"id": "86ual2npx6hl"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"# Requirements preparing"
],
"metadata": {
"id": "hb1fKCHAQckh"
}
},
{
"cell_type": "markdown",
"source": [
"## 1. Install Python libraries"
],
"metadata": {
"id": "HExYcdy-QhXx"
}
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "aIY9HB6ymuE3"
},
"outputs": [],
"source": [
"# Install MMCV related libraries via its official installer OpenMM, for better compatibility\n",
"!pip install -U openmim\n",
"!mim install mmcv mmdet mmengine"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "5C6R7zUVhzs_"
},
"outputs": [],
"source": [
"# Install PyTorch GPU version and its compatible TorchVision from PyTorch website official WHL format binary\n",
"!pip install -f https://download.pytorch.org/whl/torch_stable.html torch==2.1.0+cu118\n",
"!pip install -f https://download.pytorch.org/whl/torch_stable.html torchvision==0.16.0+cu118"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "Utnx-ct6m0rB"
},
"outputs": [],
"source": [
"# Install general libraries\n",
"!pip install -r requirements.txt"
]
},
{
"cell_type": "markdown",
"source": [
"## 2. Download related Models for PyTorch"
],
"metadata": {
"id": "4YBN52I3QoXd"
}
},
{
"cell_type": "code",
"source": [
"# Create Folder for Models\n",
"!mkdir models\n",
"\n",
"# Anime Instance Segmentation\n",
"!git clone https://huggingface.co/dreMaz/AnimeInstanceSegmentation models/AnimeInstanceSegmentation\n",
"\n",
"# # anime-seg (Anime Segmentation)\n",
"# !git clone https://huggingface.co/skytnt/anime-seg models/anime-seg\n",
"\n",
"# # LERES (Learning to Recover 3-Dimension Scene Shape from a Single Image)\n",
"# # ?Pending\n",
"# !curl https://cloudstor.aarnet.edu.au/plus/s/lTIJF4vrvHCAI31/download models/leres\n",
"\n",
"# For inpainting in Stabel Diffusion Web UI, wd-v1-4-swinv2-tagger-v2 (Waifu Diffusion 1.4 + Swin 2-Tagger 2) is required\n",
"!git clone https://huggingface.co/SmilingWolf/wd-v1-4-swinv2-tagger-v2 models/wd-v1-4-swinv2-tagger-v2"
],
"metadata": {
"id": "MNzt8ygXN0mj"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"## 3. Prepare local libraries"
],
"metadata": {
"id": "N2CiOI6AR9jE"
}
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "Sstr53RnqFK_"
},
"outputs": [],
"source": [
"!apt install build-essential libopencv-dev -y"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "LfN1gF-4pAS4"
},
"outputs": [],
"source": [
"!mkdir -p data/libs\n",
"#\n",
"!ls data/libs -alh"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "z-Dpj6q3qHCR"
},
"outputs": [],
"source": [
"!git clone https://github.com/AnimeIns/PyPatchMatch"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "ZP8j3N2mzEfX"
},
"outputs": [],
"source": [
"%cd PyPatchMatch\n",
"#\n",
"!ls -alh"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "yiKCQvinzLTS"
},
"outputs": [],
"source": [
"!mkdir release\n",
"\n",
"%cd release\n",
"#\n",
"!ls -alh"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "EYTaUSbCqJSn"
},
"outputs": [],
"source": [
"!cmake -DCMAKE_BUILD_TYPE=Release .."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "5wgblxbIzQt0"
},
"outputs": [],
"source": [
"!make\n",
"\n",
"# Check the status of generation of libpatchmatch_inpaint.so\n",
"!ls -alh"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "szNQU5mpzYxF"
},
"outputs": [],
"source": [
"# Back to the project directory\n",
"%cd ../..\n",
"#\n",
"!ls -alh"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "K8Rp1fK1zgYv"
},
"outputs": [],
"source": [
"!mv PyPatchMatch/release/libpatchmatch_inpaint.so data/libs\n",
"#\n",
"!ls data/libs -alh"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {
"id": "lxBue1AJzj11"
},
"outputs": [],
"source": [
"!rm -rf PyPatchMatch"
]
},
{
"cell_type": "markdown",
"source": [
"## 4. If it is required, prepare SDWUI (Stable Diffusion Web UI)"
],
"metadata": {
"id": "GfaHicthSE1X"
}
},
{
"cell_type": "code",
"source": [
"# Only configuration changes list here\n",
"\n",
"# Modify the Configuration to suit current API URL provided by SDWUI:\n",
"# 1. inpaint_type: default\n",
"# → inpaint_type: ldm\n",
"#\n",
"# 2. sd_img2img_url: http://127.0.0.1:7860/sdapi/v1/img2img\n",
"# → sd_img2img_url: <Your URL, e.g.: prototype://ipaddress:port>/sdapi/v1/img2img"
],
"metadata": {
"id": "_8dnKgBtV8li"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"# Web UI executing"
],
"metadata": {
"id": "f7aKYdblSXrB"
}
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "P-X_dNLeosu-"
},
"outputs": [],
"source": [
"!python Web_UI/Launcher.py"
]
}
],
"metadata": {
"accelerator": "GPU",
"colab": {
"provenance": [],
"collapsed_sections": [
"p3dgxQchVA4k"
],
"gpuType": "T4"
},
"kernelspec": {
"display_name": "Python 3",
"name": "python3"
},
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
File diff suppressed because one or more lines are too long