Comments (2)
The "Load Image" node opens an image file here:
Line 1460 in 2de3b69
and I think we should close it using
img.close()
before leaving the function.This will release the handle of the file and allow other processes to access the image file. It's not critical but it feels better to do it, right?
P.S. I noticed this while trying to delete the image file in a later node. But this is not related to the issue since I have created special ImageLoader as well.
The problem with this is that the pillow Image.open function doesn't work like the normal with Open(file) as f:
The image isn't actually read until other operations are performed on it.
Also, Image appears to be self closing once it has loaded the data, Image.close() only applies when Image.open() has been called and no operations have been performed on the image per documentation.
https://pillow.readthedocs.io/en/stable/reference/Image.html
"This is a lazy operation; this function identifies the file, but the file remains open and the actual image data is not read from the file until you try to process the data (or call the [load() method]."
Closing the image to my understanding would prevent things like exif_transpose() or ImageSequence.Iterator(img) from working with the image.
So more appropriate if you want to free it from memory after use would be
if len(output_images) > 1 and img.format not in excluded_formats:
output_image = torch.cat(output_images, dim=0)
output_mask = torch.cat(output_masks, dim=0)
else:
output_image = output_images[0]
output_mask = output_masks[0]
del img
return (output_image, output_mask)
I suppose the image could be closed at the end of the node but that wouldn't appear to actually do anything, but then it's already been saved to input as soon as you load it into the LoadImage node even before workflow execution.
Also, the return from node_helpers.pillow, is the same as the return from img = Image.open(image_path), so any closing can be done inside the LoadImage node itself. It's just a passthrough helper that applies a try except to set flags if the pil function fails, it accepts any pil function for injection.
from comfyui.
Nice, del img
will work, saving a bit more resources.
from comfyui.
Related Issues (20)
- Feature: Send normal workflow.json (non-api) to API
- An error after update HOT 2
- node input/output not labeled
- Prompt randomizing feature stops working when prompt is passed as an input rather than in a widget
- Checkpoint name in logs
- When running K-sampler: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu! HOT 1
- Pixel space upscaling heavy on GPU and its too slow HOT 1
- Disable snap to middle when loading runs in history HOT 1
- Is it possible to merge the nodes "VAE Encode(for inpaint)" and "set latent noise mask"? HOT 3
- mask composite only accept positive value?
- doest find enter point
- AnimateDiff render is very slow suddenly after update
- --listen issue for local network HOT 1
- Websocket Help HOT 1
- Comfy Server HOT 2
- Fail to run two requests with the websocket API
- ComfyUI server started but the GUI appears to be broken HOT 1
- Suggestion: Red warning status when the node is not installed, you can keep the parameters HOT 2
- [Feature Request] Support for bundled LoRA/embedding files
- Is there a way to automate a workflow that includes ComfyUI? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from comfyui.