mattyamonaca / layerdivider Goto Github PK
View Code? Open in Web Editor NEWA tool to divide a single illustration into a layered structure.
License: MIT License
A tool to divide a single illustration into a layered structure.
License: MIT License
申し訳ありませんが #15 で install_with_launcher.ps1 の使用法を説明し忘れました。
README.mdに install_with_launcher.ps1 使用法を追加する。
install_with_launcher.ps1 を使いたい人に使用方法を伝えられる。
特にないと思われます。
Downloading isnetis.onnx: 100% 176M/176M [00:00<00:00, 206MB/s]
sam_vit_h_4b8939.pth: 100% 2.39G/2.39G [00:33<00:00, 77.3MiB/s]
Running on local URL: http://xxxxxx:7860/
Running on public URL: https://xxxxxx.gradio.live/
This share link expires in 72 hours. For free permanent hosting and GPU upgrades (NEW!), check out Spaces: https://huggingface.co/spaces
Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/gradio/routes.py", line 337, in run_predict
output = await app.get_blocks().process_api(
File "/usr/local/lib/python3.10/dist-packages/gradio/blocks.py", line 1015, in process_api
result = await self.call_function(
File "/usr/local/lib/python3.10/dist-packages/gradio/blocks.py", line 833, in call_function
prediction = await anyio.to_thread.run_sync(
File "/usr/local/lib/python3.10/dist-packages/anyio/to_thread.py", line 33, in run_sync
return await get_asynclib().run_sync_in_worker_thread(
File "/usr/local/lib/python3.10/dist-packages/anyio/_backends/_asyncio.py", line 877, in run_sync_in_worker_thread
return await future
File "/usr/local/lib/python3.10/dist-packages/anyio/_backends/_asyncio.py", line 807, in run
result = context.run(func, *args)
File "/content/layerdivider/demo.py", line 36, in divide_layer
return self.segment_divide(input_image, loops, init_cluster, ciede_threshold, blur_size, layer_mode, h_split, v_split, n_cluster, alpha, th_rate, split_bg, area_th)
File "/content/layerdivider/demo.py", line 46, in segment_divide
masks = load_masks(output_dir)
File "/content/layerdivider/ldivider/ld_utils.py", line 77, in load_masks
with open(pkl_path, 'rb') as f:
FileNotFoundError: [Errno 2] No such file or directory: '/content/layerdivider/output/tmp/seg_layer/sorted_masks.pkl'
Google Colabでスクリプトを実行しましたが、次のエラーが発生しました
SEGMENT または PSD を作成できないようです
素晴らしいソフトをありがとうございます。
pytoshopのcodecs.pyでエラーが出ました。
原因は「NameError: name 'packbits' is not defined」とあるように「packbits」がなかったからです。
「codecs.py」でインポートエラーがスルーされていました。
pipでインストールするとエラーは解消されました。
私の環境固有のエラーか共通のエラーか不明ですが、取り急ぎ共有になります。
pip install packbits
実行時の出力全文
(layer) C:\Users\Creator\Desktop\layer\layerdivider>python launch.py share
Running on local URL: http://127.0.0.1:7860
Could not create share link, please check your internet connection.
C:\Users\Creator\anaconda3\envs\layer\lib\site-packages\sklearn\cluster\_kmeans.py:870: FutureWarning: The default value of `n_init` will change from 10 to 'auto' in 1.4. Set the value of `n_init` explicitly to suppress the warning
warnings.warn(
100%|██████████████████████████████████████████████████████████████████████████████████| 10/10 [00:12<00:00, 1.22s/it]
100%|██████████████████████████████████████████████████████████████████████████████████| 10/10 [00:12<00:00, 1.21s/it]
100%|████████████████████████████████████████████████████████████████████████████████████| 9/9 [00:10<00:00, 1.21s/it]
100%|████████████████████████████████████████████████████████████████████████████████████| 7/7 [00:05<00:00, 1.24it/s]
100%|████████████████████████████████████████████████████████████████████████████████████| 7/7 [00:02<00:00, 2.52it/s]
100%|████████████████████████████████████████████████████████████████████████████████████| 7/7 [00:02<00:00, 2.44it/s]
100%|████████████████████████████████████████████████████████████████████████████████████| 7/7 [00:02<00:00, 2.44it/s]
Traceback (most recent call last):
File "C:\Users\Creator\anaconda3\envs\layer\lib\site-packages\gradio\routes.py", line 337, in run_predict
output = await app.get_blocks().process_api(
File "C:\Users\Creator\anaconda3\envs\layer\lib\site-packages\gradio\blocks.py", line 1015, in process_api
result = await self.call_function(
File "C:\Users\Creator\anaconda3\envs\layer\lib\site-packages\gradio\blocks.py", line 833, in call_function
prediction = await anyio.to_thread.run_sync(
File "C:\Users\Creator\anaconda3\envs\layer\lib\site-packages\anyio\to_thread.py", line 31, in run_sync
return await get_asynclib().run_sync_in_worker_thread(
File "C:\Users\Creator\anaconda3\envs\layer\lib\site-packages\anyio\_backends\_asyncio.py", line 937, in run_sync_in_worker_thread
return await future
File "C:\Users\Creator\anaconda3\envs\layer\lib\site-packages\anyio\_backends\_asyncio.py", line 867, in run
result = context.run(func, *args)
File "C:\Users\Creator\Desktop\layer\layerdivider\launch.py", line 38, in divide_layer
filename = save_psd(
File "C:\Users\Creator\Desktop\layer\layerdivider\scripts\utils.py", line 52, in save_psd
psd.write(fd2)
File "C:\Users\Creator\anaconda3\envs\layer\lib\site-packages\pytoshop\core.py", line 281, in write
self.layer_and_mask_info.write(fd, self)
File "C:\Users\Creator\anaconda3\envs\layer\lib\site-packages\pytoshop\layers.py", line 1430, in write
self.layer_info.write(fd, header)
File "C:\Users\Creator\anaconda3\envs\layer\lib\site-packages\pytoshop\layers.py", line 1226, in write
layer.write_channel_data(fd, header)
File "C:\Users\Creator\anaconda3\envs\layer\lib\site-packages\pytoshop\layers.py", line 1120, in write_channel_data
lengths.append(data.write(fd, header, shape))
File "C:\Users\Creator\anaconda3\envs\layer\lib\site-packages\pytoshop\layers.py", line 602, in write
codecs.compress_image(
File "C:\Users\Creator\anaconda3\envs\layer\lib\site-packages\pytoshop\codecs.py", line 488, in compress_image
return compressors[compression](fd, image, depth, version)
File "C:\Users\Creator\anaconda3\envs\layer\lib\site-packages\pytoshop\codecs.py", line 331, in compress_rle
packed = packbits.encode(row)
NameError: name 'packbits' is not defined
(layerdivider) [wangxi@v100-2 layerdivider]$ python demo.py --share
Traceback (most recent call last):
File "/mnt/data1/wangxi/layerdivider/demo.py", line 6, in
from ldivider.ld_processor import get_base, get_normal_layer, get_composite_layer, get_seg_base
File "/mnt/data1/wangxi/layerdivider/ldivider/ld_processor.py", line 10, in
from ldivider.bg_remover import get_foreground
File "/mnt/data1/wangxi/layerdivider/ldivider/bg_remover.py", line 33, in
rmbg_model = rt.InferenceSession(model_path, providers=providers)
File "/home/wangxi/miniconda3/envs/layerdivider/lib/python3.10/site-packages/onnxruntime/capi/onnxruntime_inference_collection.py", line 419, in init
self._create_inference_session(providers, provider_options, disabled_optimizers)
File "/home/wangxi/miniconda3/envs/layerdivider/lib/python3.10/site-packages/onnxruntime/capi/onnxruntime_inference_collection.py", line 452, in _create_inference_session
sess = C.InferenceSession(session_options, self._model_path, True, self._read_config_from_model)
onnxruntime.capi.onnxruntime_pybind11_state.InvalidProtobuf: [ONNXRuntimeError] : 7 : INVALID_PROTOBUF : Load model from /mnt/data1/wangxi/.cache/huggingface/hub/models--skytnt--anime-seg/ failed:Protobuf parsing failed.
(layerdivider) [wangxi@v100-2 layerdivider]$ python demo.py --share
Traceback (most recent call last):
File "/mnt/data1/wangxi/layerdivider/demo.py", line 6, in
from ldivider.ld_processor import get_base, get_normal_layer, get_composite_layer, get_seg_base
File "/mnt/data1/wangxi/layerdivider/ldivider/ld_processor.py", line 10, in
from ldivider.bg_remover import get_foreground
File "/mnt/data1/wangxi/layerdivider/ldivider/bg_remover.py", line 33, in
rmbg_model = rt.InferenceSession(model_path, providers=providers)
File "/home/wangxi/miniconda3/envs/layerdivider/lib/python3.10/site-packages/onnxruntime/capi/onnxruntime_inference_collection.py", line 419, in init
self._create_inference_session(providers, provider_options, disabled_optimizers)
File "/home/wangxi/miniconda3/envs/layerdivider/lib/python3.10/site-packages/onnxruntime/capi/onnxruntime_inference_collection.py", line 452, in _create_inference_session
sess = C.InferenceSession(session_options, self._model_path, True, self._read_config_from_model)
onnxruntime.capi.onnxruntime_pybind11_state.InvalidProtobuf: [ONNXRuntimeError] : 7 : INVALID_PROTOBUF : Load model from /mnt/data1/wangxi/.cache/huggingface/hub/models--skytnt--anime-seg/ failed:Protobuf parsing failed.
Microsoft Visual C++ 14.0 is a precondition to install the pytoshop module .
i suggest to remind this in readme document.
if u have the same problem, u d better download this tool: Visual Studio 2022 build tool, and select c++ with default settings. u can easily find it on microsoft's web.
RuntimeError: /onnxruntime_src/onnxruntime/core/providers/cuda/cuda_call.cc:124 std::conditional_t<THRW, void, onnxruntime::common::Status> onnxruntime::CudaCall(ERRTYPE, const char*, const char*, ERRTYPE, const char*) [with ERRTYPE = cudaError; bool THRW = true; std::conditional_t<THRW, void, onnxruntime::common::Status> = void] /onnxruntime_src/onnxruntime/core/providers/cuda/cuda_call.cc:117 std::conditional_t<THRW, void, onnxruntime::common::Status> onnxruntime::CudaCall(ERRTYPE, const char*, const char*, ERRTYPE, const char*) [with ERRTYPE = cudaError; bool THRW = true; std::conditional_t<THRW, void, onnxruntime::common::Status> = void] CUDA failure 35: CUDA driver version is insufficient for CUDA runtime version ; GPU=0 ; hostname=20e9d393f524 ; expr=cudaSetDevice(info_.device_id);
I am having this WinError 127 even after following the instructions to download CUDA and cuDNN: https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.html#requirements
I have specifcally gotten these versions of the requirements:
However, like others, I am still facing the error 127, and I do not know how to fix it
Is it just for test?
ツール導入時にpytoshopのインストールで躓いている人が多いため、pytoolsへの乗り換えを行います。
May I ask how to add the host to visit through the LAN Ip address?
インストールの手順が自動化されている install.ps1 において、venv モジュールが python コマンドで実行されています。
しかしながら、python を複数バージョン入れている環境では
といった可能性が考えられます。
そういった環境ではinstall.ps1 がうまく動きません。
既存のインストール用のスクリプトとは別に、Python launcher 向けの自動インストール用のスクリプトを追加する。
Python launcher 向けの自動インストール用のスクリプトのプルリクエストを送りたいと思います。
!python demo.py share mistake
Downloading isnetis.onnx: 100% 176M/176M [00:01<00:00, 92.3MB/s]
Traceback (most recent call last):
File "/content/layerdivider/demo.py", line 6, in
from ldivider.ld_processor import get_base, get_normal_layer, get_composite_layer
File "/content/layerdivider/ldivider/ld_processor.py", line 10, in
from ldivider.bg_remover import get_foreground
File "/content/layerdivider/ldivider/bg_remover.py", line 34, in
rmbg_model = rt.InferenceSession(model_path, providers=providers)
File "/usr/local/lib/python3.10/dist-packages/onnxruntime/capi/onnxruntime_inference_collection.py", line 360, in init
self._create_inference_session(providers, provider_options, disabled_optimizers)
File "/usr/local/lib/python3.10/dist-packages/onnxruntime/capi/onnxruntime_inference_collection.py", line 408, in create_inference_session
sess.initialize_session(providers, provider_options, disabled_optimizers)
RuntimeError: /onnxruntime_src/onnxruntime/core/providers/cuda/cuda_call.cc:124 std::conditional_t<THRW, void, onnxruntime::common::Status> onnxruntime::CudaCall(ERRTYPE, const char*, const char*, ERRTYPE, const char*) [with ERRTYPE = cudaError; bool THRW = true; std::conditional_t<THRW, void, onnxruntime::common::Status> = void] /onnxruntime_src/onnxruntime/core/providers/cuda/cuda_call.cc:117 std::conditional_t<THRW, void, onnxruntime::common::Status> onnxruntime::CudaCall(ERRTYPE, const char*, const char*, ERRTYPE, const char*) [with ERRTYPE = cudaError; bool THRW = true; std::conditional_t<THRW, void, onnxruntime::common::Status> = void] CUDA failure 35: CUDA driver version is insufficient for CUDA runtime version ; GPU=0 ; hostname=45da94497a21 ; expr=cudaSetDevice(info.device_id);
Issue #17 の問題と同様のことが起こります。
例えば、
ディレクトリ構造が
C:
└ layerdivider
├ run_gui.py
├ venv
│ └ Scripts
│ └ activate.bat
└ launch.py
となっているときに、PowerShellで
cd C:\
.\layerdivider\run_gui.ps1
を実行すると、activate が見つからないというエラーが発生します。
run_gui.ps1 の先頭行に Set-Location $PSScriptRoot
を追加する。
どこから run_gui.py を実行しても layerdivider ディレクトリ直下の launch.py が実行されます。
前の挙動を利用している人がいる可能性があります。
I have had the great fortune of meeting someone who was able to get the standalone version of Layer Divider to work. However, the automatic1111 extension version of Layer Divider still does not work, according to him, he believes that Layer Divider should be updated for the current gradio version.
Keep in mind that this fix only works for the standalone webui version of Layer Divider, and not the automatic1111 extension version.
Apparently, there is another requirement other than Python 3.10.8 and Git, it is listed on this page: https://zenn.dev/mattyamonaca/articles/b3fec7a6edd722
The hidden prerequisite requirements:
FYI: I was using ONNX runtime 1.15, CUDA 11.8, cuDNN 8.5.0.96, Microsoft Visual Build Tools 2022
My issue was that I kept getting Winerror 127:
In order to fix this issue, fulfill the prerequisite requirements, and then follow these steps:
import pyximport
pyximport.install()
before the line
try:
from . import packbits # type: ignore
except ImportError:
pass
I run the demo, and open the webui, then upload image and run, but got error below:
Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/gradio/routes.py", line 337, in run_predict
output = await app.get_blocks().process_api(
File "/usr/local/lib/python3.10/dist-packages/gradio/blocks.py", line 1015, in process_api
result = await self.call_function(
File "/usr/local/lib/python3.10/dist-packages/gradio/blocks.py", line 833, in call_function
prediction = await anyio.to_thread.run_sync(
File "/usr/local/lib/python3.10/dist-packages/anyio/to_thread.py", line 31, in run_sync
return await get_asynclib().run_sync_in_worker_thread(
File "/usr/local/lib/python3.10/dist-packages/anyio/_backends/_asyncio.py", line 937, in run_sync_in_worker_thread
return await future
File "/usr/local/lib/python3.10/dist-packages/anyio/_backends/_asyncio.py", line 867, in run
result = context.run(func, *args)
File "/content/layerdivider/demo.py", line 36, in divide_layer
return self.segment_divide(input_image, loops, init_cluster, ciede_threshold, blur_size, layer_mode, h_split, v_split, n_cluster, alpha, th_rate, split_bg, area_th)
File "/content/layerdivider/demo.py", line 46, in segment_divide
masks = load_masks(output_dir)
File "/content/layerdivider/ldivider/ld_utils.py", line 77, in load_masks
with open(pkl_path, 'rb') as f:
FileNotFoundError: [Errno 2] No such file or directory: '/content/layerdivider/output/tmp/seg_layer/sorted_masks.pkl'
Where to find the sorted_masks.pkl?
I have tried installing the automatic1111 extension version of Layer Divider.
The first time I installed it, I managed to get the segment function to work:
However, I could not create a psd file with it:
And in the end, this error popped up:
Also, after I closed the webui and opened it again, segment function does not work anymore.
I find it is a very useful tool. But I dont know how to install it. Could you explain some steps for more
Running on local URL: http://127.0.0.1:7860
To create a public link, set share=True
in launch()
.
Task exception was never retrieved
future: <Task finished name='zuvuz58rdno_1' coro=<Queue.process_events() done, defined at D:\layerdivider-main\venv\lib\site-packages\gradio\queueing.py:324> exception=AssertionError('No event data')>
Traceback (most recent call last):
File "D:\layerdivider-main\venv\lib\site-packages\gradio\queueing.py", line 338, in process_events
response = await self.call_prediction(awake_events, batch)
File "D:\layerdivider-main\venv\lib\site-packages\gradio\queueing.py", line 298, in call_prediction
assert data is not None, "No event data"
AssertionError: No event data
Traceback (most recent call last):
File "D:\test\layerdivider\demo.py", line 5, in
from ldivider.ld_convertor import pil2cv, cv2pil, df2bgra
File "D:\test\layerdivider\ldivider\ld_convertor.py", line 1, in
import cv2
ModuleNotFoundError: No module named 'cv2'
What is the reason for this issue that pops up after opening a webpage and inputting images for local deployment
install.ps1 は layerdivider ディレクトリに venv ディレクトリを作成することを意図して作られたのだと思います。
しかしながら、PowerShell から 直接 install.ps1 を実行する場合、カレントディレクトリの場所に venv ディレクトリが作成されます。
これは意図とは異なる動作を引き起こす可能性があります。
例えば、PowerShell で
cd C:\
git clone https://github.com/mattyamonaca/layerdivider.git
.\layerdivider\install.ps1
とすると、ディレクトリは
C:\
├ layerdivider\
└ venv\
となってしまいます。
install.ps1 の先頭行にSet-Location $PSScriptRoot
を追加する。
install.ps1 を実行する方法にかかわらず同じディレクトリ構成になるので、利用者にとって分かりやすいと思います。
もともとの挙動を利用している人がいるかもしれません。
Traceback (most recent call last):
File "C:\layerdivider\layerdivider\demo.py", line 8, in
from ldivider.ld_segment import get_mask_generator, get_masks, show_anns
File "C:\layerdivider\layerdivider\ldivider\ld_segment.py", line 1, in
from segment_anything import sam_model_registry, SamAutomaticMaskGenerator, SamPredictor
File "C:\layerdivider\layerdivider\venv\lib\site-packages\segment_anything_init_.py", line 7, in
from .build_sam import (
File "C:\layerdivider\layerdivider\venv\lib\site-packages\segment_anything\build_sam.py", line 7, in
import torch
File "C:\layerdivider\layerdivider\venv\lib\site-packages\torch_init_.py", line 122, in
raise err
OSError: [WinError 127] 指定されたプロシージャが見つかりません。 Error loading "C:\layerdivider\layerdivider\venv\lib\site-packages\torch\lib\cublas64_11.dll" or one of its dependencies.
続行するには、Enter キーを押してください...:
I've reinstalled it many times, but no improvement.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.