You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I get an exception when using numpy arrays as images with the Image component. I get my image from opencv imread. I guess the problem is that it is trying to compare the arrays when deciding whether to render or not.
Traceback (most recent call last): File "/Users/tjtuom/Code/takomo/experiments/venv/lib/python3.9/site-packages/edifice/base_components.py", line 255, in _mouse_release self._mouse_clicked(ev) File "/Users/tjtuom/Code/takomo/experiments/venv/lib/python3.9/site-packages/edifice/base_components.py", line 260, in _mouse_clicked self._on_click(ev) File "/Users/tjtuom/Code/takomo/annotate/annote_edifice.py", line 56, in <lambda> *[Label(text=f, on_click=lambda ev, f=f: self.on_click(f)) for f in self.props.files] File "/Users/tjtuom/Code/takomo/annotate/annote_edifice.py", line 52, in on_click self.props.on_image_selected(f) File "/Users/tjtuom/Code/takomo/annotate/annote_edifice.py", line 117, in on_image_selected self.current_image = path.join(IMAGE_DIR, f) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/contextlib.py", line 124, in __exit__ next(self.gen) File "/Users/tjtuom/Code/takomo/experiments/venv/lib/python3.9/site-packages/edifice/_component.py", line 373, in render_changes self.set_state(**changes_context) File "/Users/tjtuom/Code/takomo/experiments/venv/lib/python3.9/site-packages/edifice/_component.py", line 408, in set_state raise e File "/Users/tjtuom/Code/takomo/experiments/venv/lib/python3.9/site-packages/edifice/_component.py", line 404, in set_state self._controller._request_rerender([self], kwargs) File "/Users/tjtuom/Code/takomo/experiments/venv/lib/python3.9/site-packages/edifice/app.py", line 178, in _request_rerender render_result = self._render_engine._request_rerender(components) File "/Users/tjtuom/Code/takomo/experiments/venv/lib/python3.9/site-packages/edifice/engine.py", line 431, in _request_rerender commands = self._gen_commands(widget_trees, render_context) File "/Users/tjtuom/Code/takomo/experiments/venv/lib/python3.9/site-packages/edifice/engine.py", line 413, in _gen_commands commands.extend(widget_tree.gen_qt_commands(render_context)) File "/Users/tjtuom/Code/takomo/experiments/venv/lib/python3.9/site-packages/edifice/engine.py", line 75, in gen_qt_commands rendered = child.gen_qt_commands(render_context) File "/Users/tjtuom/Code/takomo/experiments/venv/lib/python3.9/site-packages/edifice/engine.py", line 75, in gen_qt_commands rendered = child.gen_qt_commands(render_context) File "/Users/tjtuom/Code/takomo/experiments/venv/lib/python3.9/site-packages/edifice/engine.py", line 75, in gen_qt_commands rendered = child.gen_qt_commands(render_context) File "/Users/tjtuom/Code/takomo/experiments/venv/lib/python3.9/site-packages/edifice/engine.py", line 82, in gen_qt_commands new_props = PropsDict({k: v for k, v in self.component.props._items if k not in old_props or _try_neq(old_props[k], v)}) File "/Users/tjtuom/Code/takomo/experiments/venv/lib/python3.9/site-packages/edifice/engine.py", line 82, in <dictcomp> new_props = PropsDict({k: v for k, v in self.component.props._items if k not in old_props or _try_neq(old_props[k], v)}) ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
The text was updated successfully, but these errors were encountered:
So the problem is the or in new_props = PropsDict({k: v for k, v in self.component.props._items if k not in old_props or _try_neq(old_props[k], v)}). When comparing numpy arrays_try_neg returns another array instead of a boolean which causes the or operator to produce a value error.
>>> import numpy as np
>>> a = np.array([1, 2, 3])
>>> b = np.array([1,2, 3])
>>> a != b
array([False, False, False])
>>> a or b
Traceback (most recent call last):
File "", line 1, in
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
I solved it with: def _try_neq(a, b): try: if isinstance(a, np.ndarray) and isinstance(b, np.ndarray): return not np.array_equal(a, b) else: return a != b except: return a is not b
I get an exception when using numpy arrays as images with the Image component. I get my image from opencv imread. I guess the problem is that it is trying to compare the arrays when deciding whether to render or not.
Traceback (most recent call last): File "/Users/tjtuom/Code/takomo/experiments/venv/lib/python3.9/site-packages/edifice/base_components.py", line 255, in _mouse_release self._mouse_clicked(ev) File "/Users/tjtuom/Code/takomo/experiments/venv/lib/python3.9/site-packages/edifice/base_components.py", line 260, in _mouse_clicked self._on_click(ev) File "/Users/tjtuom/Code/takomo/annotate/annote_edifice.py", line 56, in <lambda> *[Label(text=f, on_click=lambda ev, f=f: self.on_click(f)) for f in self.props.files] File "/Users/tjtuom/Code/takomo/annotate/annote_edifice.py", line 52, in on_click self.props.on_image_selected(f) File "/Users/tjtuom/Code/takomo/annotate/annote_edifice.py", line 117, in on_image_selected self.current_image = path.join(IMAGE_DIR, f) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/contextlib.py", line 124, in __exit__ next(self.gen) File "/Users/tjtuom/Code/takomo/experiments/venv/lib/python3.9/site-packages/edifice/_component.py", line 373, in render_changes self.set_state(**changes_context) File "/Users/tjtuom/Code/takomo/experiments/venv/lib/python3.9/site-packages/edifice/_component.py", line 408, in set_state raise e File "/Users/tjtuom/Code/takomo/experiments/venv/lib/python3.9/site-packages/edifice/_component.py", line 404, in set_state self._controller._request_rerender([self], kwargs) File "/Users/tjtuom/Code/takomo/experiments/venv/lib/python3.9/site-packages/edifice/app.py", line 178, in _request_rerender render_result = self._render_engine._request_rerender(components) File "/Users/tjtuom/Code/takomo/experiments/venv/lib/python3.9/site-packages/edifice/engine.py", line 431, in _request_rerender commands = self._gen_commands(widget_trees, render_context) File "/Users/tjtuom/Code/takomo/experiments/venv/lib/python3.9/site-packages/edifice/engine.py", line 413, in _gen_commands commands.extend(widget_tree.gen_qt_commands(render_context)) File "/Users/tjtuom/Code/takomo/experiments/venv/lib/python3.9/site-packages/edifice/engine.py", line 75, in gen_qt_commands rendered = child.gen_qt_commands(render_context) File "/Users/tjtuom/Code/takomo/experiments/venv/lib/python3.9/site-packages/edifice/engine.py", line 75, in gen_qt_commands rendered = child.gen_qt_commands(render_context) File "/Users/tjtuom/Code/takomo/experiments/venv/lib/python3.9/site-packages/edifice/engine.py", line 75, in gen_qt_commands rendered = child.gen_qt_commands(render_context) File "/Users/tjtuom/Code/takomo/experiments/venv/lib/python3.9/site-packages/edifice/engine.py", line 82, in gen_qt_commands new_props = PropsDict({k: v for k, v in self.component.props._items if k not in old_props or _try_neq(old_props[k], v)}) File "/Users/tjtuom/Code/takomo/experiments/venv/lib/python3.9/site-packages/edifice/engine.py", line 82, in <dictcomp> new_props = PropsDict({k: v for k, v in self.component.props._items if k not in old_props or _try_neq(old_props[k], v)}) ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
The text was updated successfully, but these errors were encountered: