BlenderNeko / ComfyUI_Cutoff

cutoff implementation for ComfyUI
GNU General Public License v3.0
347 stars 21 forks source link

IndexError in CLIPSetRegion #4

Closed qwitriy closed 1 year ago

qwitriy commented 1 year ago

Hi! image

In the CLIPSetRegion if target_text value starts or ends with space, python throws error: IndexError: too many indices for array: array is 1-dimensional, but 2 were indexed

Traceback (most recent call last):
  File "C:\Users\user\Documents\ComfyUI\execution.py", line 182, in execute
    executed += recursive_execute(self.server, prompt, self.outputs, x, extra_data)
  File "C:\Users\user\Documents\ComfyUI\execution.py", line 58, in recursive_execute
    executed += recursive_execute(server, prompt, outputs, input_unique_id, extra_data)
  File "C:\Users\user\Documents\ComfyUI\execution.py", line 58, in recursive_execute
    executed += recursive_execute(server, prompt, outputs, input_unique_id, extra_data)
  File "C:\Users\user\Documents\ComfyUI\execution.py", line 58, in recursive_execute
    executed += recursive_execute(server, prompt, outputs, input_unique_id, extra_data)
  [Previous line repeated 4 more times]
  File "C:\Users\user\Documents\ComfyUI\execution.py", line 67, in recursive_execute
    outputs[unique_id] = getattr(obj, obj.FUNCTION)(**input_data_all)
  File "C:\Users\user\Documents\ComfyUI\custom_nodes\ComfyUI_Cutoff\cutoff.py", line 119, in add_clip_region
    target_tokens, _ = replace_embeddings(clip.tokenizer.end_token, target_tokens, emb_lookup)
  File "C:\Users\user\Documents\ComfyUI\custom_nodes\ComfyUI_Cutoff\cutoff.py", line 42, in replace_embeddings
    tokens = np.array(tokens)[:,1:-1].reshape(-1)
IndexError: too many indices for array: array is 1-dimensional, but 2 were indexed

I fixed it locally using strip() on target_text after this https://github.com/BlenderNeko/ComfyUI_Cutoff/blob/master/cutoff.py#L86 No sure if this quickfix in proper place.

BlenderNeko commented 1 year ago

Yeah that would probably be a smart thing to do for both region_text and target_text at the top of that function call. If you want you can put in a PR with the changes, or I'll push things once I get home.

qwitriy commented 1 year ago

Thank you. I made such edit. Please review.