Skip to content

Commit

Permalink
v0.5.2 -- Bug fixes, new Preview Image node, etc minor features (chai…
Browse files Browse the repository at this point in the history
…NNer-org#50)

* Fix cuda issue in ONNX convert

* Add relative paths to image iteration (theflyingzamboni) (chaiNNer-org#46)

* Added Image Directory output to Load image

* Add relative pathing to Iterator Load Image and Save Image

* Lock DirectoryInput when connected

* Fixed validation bug

* Fixed minor relative path bug of no consequence

* Removed unused import

* Added 0.5.2 migration

* Updated dependency requirements and incremented version

* Split settings into its own context


Fix snapToGrid import

* Use env vars to kill upscaling during tiling

* Potential fix for checking if image file exists

* Change where extra data processing goes

* Automatic param/bin file detection on change

* Fix for consistent ncnn gpu index (will make it selectable in future)

* Fix position problem, update some packages, fix iterator file types

* eslint updates

* Linting changes

* Fix eslint cli not reading subdirs

* Fix prop sorting

* Attempt to fix iterator dropping on an edge

* disable auto-split killing as it crashes backend

* V0.5.2 dev (chaiNNer-org#48)

* Fixed supported extensions bug

* Reverted imread output to list to fix bug

* Fixed image support fix

* Fixed Typing bug preventing nodes from importing (chaiNNer-org#49)

* Better nvidia-smi check

* Fix casing issue and filetype double dot issue

* Just check linting on pre-commit rather than fixing

* Downgrade react-flow-renderer due to zIndex issue

* Add new image preview external node and maybe fix load image file exists check for real

* Fix iterator progress updates

* Fix new image preview on linux, remove old image preview on linux

* Replace original image show with new one

Co-authored-by: theflyingzamboni <[email protected]>
  • Loading branch information
joeyballentine and theflyingzamboni authored Apr 16, 2022
1 parent f7c04bb commit 2ba760b
Show file tree
Hide file tree
Showing 69 changed files with 2,012 additions and 1,136 deletions.
29 changes: 29 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module.exports = {
extends: [
'airbnb',
'plugin:react/jsx-runtime',
],
globals: {
MAIN_WINDOW_WEBPACK_ENTRY: true,
SPLASH_SCREEN_WEBPACK_ENTRY: true,
},
env: {
browser: true,
node: true,
},
parserOptions: {
ecmaVersion: 2020,
},
rules: {
'react/jsx-sort-props': ['error', {
callbacksLast: true,
shorthandFirst: true,
}],
'react/jsx-max-props-per-line': ['error', { maximum: 1, when: 'always' }],
'import/extensions': 'off',
'react/prop-types': 'off',
},
settings: {
'import/core-modules': ['electron'],
},
};
14 changes: 13 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"extends": "airbnb",
"extends": [
"airbnb",
"plugin:react/jsx-runtime"
],
"globals": {
"MAIN_WINDOW_WEBPACK_ENTRY": true,
"SPLASH_SCREEN_WEBPACK_ENTRY": true
Expand All @@ -10,5 +13,14 @@
},
"parserOptions": {
"ecmaVersion": 2020
},
"rules": {
"react/jsx-sort-props": [2, {
"callbacksLast": true,
"shorthandFirst": true
}],
"react/jsx-max-props-per-line": [2, { "maximum": 1, "when": "always" }],
"import/extensions": "off",
"react/prop-types": "off"
}
}
111 changes: 62 additions & 49 deletions backend/nodes/image_iterator_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from .node_factory import NodeFactory
from .properties.inputs import *
from .properties.outputs import *
from .utils.image_utils import get_available_image_formats

IMAGE_ITERATOR_DEFAULT_NODE_NAME = "Load Image (Iterator)"

Expand All @@ -26,15 +27,26 @@ def __init__(self):
self.description = ""
self.inputs = [IteratorInput()]
self.outputs = ImReadNode().get_outputs()

self.outputs.insert(
2, TextOutput("Relative Path")
) # Add relative path to outputs outside ImReadNode
self.icon = "MdSubdirectoryArrowRight"
self.sub = "Iteration"

self.type = "iteratorHelper"

def run(self, directory: str = "") -> any:
def run(self, directory: str = "", root_dir: str = "") -> any:
imread = ImReadNode()
return imread.run(directory)
imread_output = imread.run(directory)

# Get relative path from root directory passed by Iterator directory input
rel_path = os.path.relpath(imread_output[1], root_dir)

# Set ImRead directory output to root/base directory and insert relative path into outputs
imread_output[1] = root_dir
imread_output.insert(2, rel_path)

return imread_output


@NodeFactory.register("Image", "Image File Iterator")
Expand Down Expand Up @@ -67,7 +79,7 @@ async def run(
id="",
parent_executor=None,
percent=0,
) -> any:
) -> Any:
logger.info(f"Iterating over images in directory: {directory}")
logger.info(nodes)

Expand All @@ -84,59 +96,60 @@ async def run(
# Set this to false to actually allow processing to happen
nodes[k]["child"] = False

supported_filetypes = [
".png",
".jpg",
".jpeg",
] # TODO: Make a method to get these dynamically based on the installed deps
supported_filetypes = get_available_image_formats()

def walk_error_handler(exception_instance):
logger.warn(
f"Exception occurred during walk: {exception_instance} Continuing..."
)

just_image_files = []
for root, dirs, files in os.walk(
directory, topdown=False, onerror=walk_error_handler
directory, topdown=True, onerror=walk_error_handler
):
if parent_executor.should_stop_running():
return
file_len = len(files)
start_idx = math.ceil(float(percent) * file_len)
for idx, name in enumerate(files):
if parent_executor.should_stop_running():
return
if idx >= start_idx:
await queue.put(
{
"event": "iterator-progress-update",
"data": {
"percent": idx / file_len,
"iteratorId": id,
"running": child_nodes,
},
}
)
filepath = os.path.join(root, name)
base, ext = os.path.splitext(filepath)
if ext.lower() in supported_filetypes:
# Replace the input filepath with the filepath from the loop
nodes[img_path_node_id]["inputs"] = [filepath]
executor = Executor(
nodes,
loop,
queue,
external_cache.copy(),
parent_executor=parent_executor,
)
await executor.run()
await queue.put(
{
"event": "iterator-progress-update",
"data": {
"percent": (idx + 1) / file_len,
"iteratorId": id,
"running": None,
},
}
)

for name in files:
filepath = os.path.join(root, name)
base, ext = os.path.splitext(filepath)
if ext.lower() in supported_filetypes:
just_image_files.append(filepath)

file_len = len(just_image_files)
start_idx = math.ceil(float(percent) * file_len)
for idx, filepath in enumerate(just_image_files):
if parent_executor.should_stop_running():
return
if idx >= start_idx:
await queue.put(
{
"event": "iterator-progress-update",
"data": {
"percent": idx / file_len,
"iteratorId": id,
"running": child_nodes,
},
}
)
# Replace the input filepath with the filepath from the loop
nodes[img_path_node_id]["inputs"] = [filepath, directory]
executor = Executor(
nodes,
loop,
queue,
external_cache.copy(),
parent_executor=parent_executor,
)
await executor.run()
await queue.put(
{
"event": "iterator-progress-update",
"data": {
"percent": (idx + 1) / file_len,
"iteratorId": id,
"running": None,
},
}
)
return ""
Loading

0 comments on commit 2ba760b

Please sign in to comment.