Comments (3)
@githubarooski I have a colab notebook for this project in the root of the github repository.
It isn't yet public/stable.
This code uses a feature of python called "generators" which are indeed a bit tough to wrap your head around. Aside from that; a lot of this code is very "reasearch-y" because that was its original intended audience. I've done my best to strike a balance between the strange realm of research where single-letter variables are encouraged and the software engineering realm I'm used to; but I'll admit it isn't perfect.
from clip-guided-diffusion.
@githubarooski Good question! that functionality got refactored a bit recently because I implemented multiple text prompts and image prompts. It is now called clean_and_combine_prompts
and works on a list of prompts. If you just have one you can just wrap it in a list [my_prompt]
Since the code still isn't stable here and it sounds like you wanna use the original notebooks as well; perhaps you can just copy-paste this into a notebook?
ALPHANUMERIC_REGEX = r"[^\w\s]"
def alphanumeric_filter(s: str) -> str:
return re.sub(ALPHANUMERIC_REGEX, "", s).replace(" ", "_")
def clean_and_combine_prompts(base_path, txts, batch_idx, max_length=255) -> str:
clean_txt = "_".join([alphanumeric_filter(txt) for txt in txts])[:max_length]
return os.path.join(base_path, clean_txt, f"{batch_idx:02}")
You may also just want the log_image
method; which I use to create a directory with the prompt as a name, and a subdirectory for each batch in batch_size. Then an image is saved in both ./current.png
and the output directory.
def log_image(image: th.Tensor, base_path: str, txts: list, current_step: int, batch_idx: int) -> str:
dirname = clean_and_combine_prompts(base_path, txts, batch_idx)
os.makedirs(dirname, exist_ok=True)
stem = f"{current_step:04}"
filename = os.path.join(dirname, f'{stem}.png')
pil_image = tvf.to_pil_image(image.add(1).div(2).clamp(0, 1))
pil_image.save(os.path.join(os.getcwd(), f'current.png'))
pil_image.save(filename)
return str(filename)
You can call it as such in Katherine's code (pseudocode)
prefix_path = "/content/outputs"
current_timestep = diffusion.num_timesteps - 1
for i, sample in enumerate(samples):
current_timestep -= 1
if i % save_frequency == 0 or current_timestep == -1:
for j, img in enumerate(sample["pred_xstart"]):
log_image(img, prefix_path, prompts, step, j)
from clip-guided-diffusion.
Thanks for the response. This looks like similar features I'm working to integrate. It's very slow going because my python is entry level. Are you planning to publish a colab with your helper utilities?
from clip-guided-diffusion.
Related Issues (16)
- TypeError got an unexpected keyword argument 'custom_classes' HOT 9
- image_prompts is mistakenly set to text prompts HOT 1
- GIFs are pixelated
- Multi GPU Support HOT 5
- Missing attribution for quick diffusion HOT 1
- Shouldn't it be "pil_img" instead of "input"? HOT 6
- Use K. Crowson's denoising model to save VRAM, improve generations HOT 1
- Issue #20 still not working.
- Please help me with this HOT 1
- Tensor is not a torch image
- What's the meaning of this equation in cond_fn (from cgd.py) HOT 2
- Noisy outputs HOT 1
- Link to original works
- Batch Size Greater than 1 Not Supported
- AMD Pytorch ROCM support
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 clip-guided-diffusion.