Giter Site home page Giter Site logo

layerdivider's Introduction

Top Langs github stats

trophy

layerdivider's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

layerdivider's Issues

install_with_launcher.ps1 の使用法をREADME.mdに追加

問題

申し訳ありませんが #15 で install_with_launcher.ps1 の使用法を説明し忘れました。

提案

README.mdに install_with_launcher.ps1 使用法を追加する。

メリット

install_with_launcher.ps1 を使いたい人に使用方法を伝えられる。

デメリット

特にないと思われます。

google colab error

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 を作成できないようです

「NameError: name 'packbits' is not defined」で落ちました。

素晴らしいソフトをありがとうございます。

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

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.
(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.

To install, Microsoft Visual C++ 14.0 is required

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.

Didn't I come at the right time? Why the COLAB version didn't work?

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);

pyコマンド使用者向けインストールスクリプトを追加

問題

インストールの手順が自動化されている install.ps1 において、venv モジュールが python コマンドで実行されています。
しかしながら、python を複数バージョン入れている環境では

  • python3.10 以外の python にパスが通っている
  • python コマンドにパスを通さず py コマンド (Python launcher) を使用している

といった可能性が考えられます。
そういった環境ではinstall.ps1 がうまく動きません。

提案

既存のインストール用のスクリプトとは別に、Python launcher 向けの自動インストール用のスクリプトを追加する。

メリット

  • py コマンドのみパスを通している人も楽にインストールできるようになります。
  • py コマンドを使用しているためインストール時に作成される venv 仮想環境の Python のマイナーバージョンを固定できます。

デメリット

  • 管理しなければいけないファイルが増えてしまいます。

プルリクエスト

Python launcher 向けの自動インストール用のスクリプトのプルリクエストを送りたいと思います。

Google Colab can't run

!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);

いつでも layerdivider ディレクトリ直下の launch.py を実行するようにする

問題

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 が実行されます。

デメリット

前の挙動を利用している人がいる可能性があります。

Found a fix for Winerror 127

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:

  1. Onnx runtime, CUDA and cuDNN, your CUDA and cuDNN must match up with your Onnx runtime version, and the table can be found here: https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.html#requirements
  2. Installing Microsoft C++ BuildTools, you must download visual studio build tools with "Desktop development with C++" ticked:
    image
    image
  3. Copy your cublas64_11.dll from your NVIDIA GPU Computing Toolkit which you gotten from downloading CUDA in step 1 into your layer divider folder, here is an example of where to copy and paste it to: C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6\bin\cublas64_11.dll to layerdivider\venv\lib\site-packages\torch\lib\cublas64_11.dll

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:
image

In order to fix this issue, fulfill the prerequisite requirements, and then follow these steps:

  1. delete the venv folder which is found inside your layer divider folder
  2. open your command prompt or powershell inside your layer divider folder
  3. python -m venv venv
  4. venv\scripts\activate
  5. pip install -r requirements.txt
  6. pip install opencv-python pycocotools matplotlib onnxruntime onnx
  7. pip install torch==2.0.1+cu118 torchvision==0.15.2+cu118 --extra-index-url https://download.pytorch.org/whl/cu118
  8. pip install cython packbits onnx onnxruntime-gpu opencv-python numpy Pillow scikit-learn psd-tools requests
  9. pip uninstall gradio
  10. pip install gradio==3.39.0
  11. pip uninstall pytoshop
  12. pip install pytoshop --no-cache-dir
  13. close your command prompt or powershell
  14. open .\venv\Lib\site-packages\pytoshop\codecs.py file in txt editor
  15. add the following:

import pyximport
pyximport.install()

before the line

try:
from . import packbits # type: ignore
except ImportError:
pass

It should look like this:
image

  1. Now you can launch your run_gui.ps1

Encounter error when run demo on the colab

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?

divide_folder( ) missing 1 required positional argument: "mode"

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:
image

However, I could not create a psd file with it:
image

And in the end, this error popped up:
image

Also, after I closed the webui and opened it again, segment function does not work anymore.

How to install it

I find it is a very useful tool. But I dont know how to install it. Could you explain some steps for more

When I run_gui into the local site and click on Create PSD, it shows the following error message

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

cv2??

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'

いつでもlayerdivider ディレクトリの直下に venv ディレクトリを作成するようにする

問題

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 を実行する方法にかかわらず同じディレクトリ構成になるので、利用者にとって分かりやすいと思います。

デメリット

もともとの挙動を利用している人がいるかもしれません。

Local run_gui.ps1 OSError: [WinError 127]

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.