Comments (4)
Here's an example of how to save an image:
Dream demo
prompt = 'ultra close-up color photo portrait of rainbow owl with deer horns in the woods'
count = 4
result = dream(
t5=t5, if_I=if_I, if_II=if_II, if_III=if_III,
prompt=[prompt]*count,
seed=42,
if_I_kwargs={
"guidance_scale": 7.0,
"sample_timestep_respacing": "smart100",
},
if_II_kwargs={
"guidance_scale": 4.0,
"sample_timestep_respacing": "smart50",
},
)
if_I.show(result['I'], size=3)
if_I.show(result['II'], size=6)
if_I.show(result['III'], size=14)
define a function named save_image()
def save_image(pil_images_list, save_path = "images", img_name = "generated_image"):
if not os.path.exists(save_path):
os.makedirs(save_path)
for i, img in enumerate(pil_images_list):
img = img.detach()
img.save("{}{}_{}.png".format(save_path, img_name, i))
call the save_image() function
pil_images_list = model_result["III"]
save_image(pil_images_list, save_path = "images", img_name = "generated_image")
from if.
Seems that the img doesn't have the attribute detach.
save_image(pil_images_list, save_path = "images", img_name = get_timestamped_filename())
File "create_deepfloyd_image.py", line 48, in save_image
img = img.detach()
File "${HOME}/miniconda3/envs/deepfloyd/lib/python3.8/site-packages/PIL/Image.py", line 529, in __getattr__
raise AttributeError(name)
AttributeError: detach
I'm going to try to figure this out, however let me know if you have any pointers : )
from if.
Figured it out : ) Should note that I resize the image ahead of time to 768x512 resolution. Sharing the main code (testing this now, will remove this stub once I triple check that it still works after removing seemingly unused imports and code lines):
from PIL import Image
from deepfloyd_if.modules import IFStageI, IFStageII, StableStageIII
from deepfloyd_if.modules.t5 import T5Embedder
from deepfloyd_if.pipelines import style_transfer
import argparse
import datetime
import os
def parse_args():
p = argparse.ArgumentParser(
description='Implements designated styles into an image',
formatter_class=argparse.RawDescriptionHelpFormatter
)
p.add_argument(
"-i",
"--input-file",
type=str,
required=True,
help="input file for blending",
)
p.add_argument(
"-t",
"--tag",
type=int,
required=True,
help="can loop over these, functions to set the random seed value (note: same random seed value and input image yield same results)",
)
return p.parse_args()
def get_timestamped_filename():
now = datetime.datetime.now()
timestamp = now.strftime('%Y%m%d%H%M%S')
filename = timestamp + '.png'
return filename
def save_image(pil_images_list, save_path = "images", img_name = "generated_image"):
if not os.path.exists(save_path):
os.makedirs(save_path)
print('pil_images_list')
print(pil_images_list)
print(type(pil_images_list))
counter = 0
for img in pil_images_list:
print(type(img))
print(img)
img.save("{}/{}_{}.png".format(save_path, img_name, counter))
counter += 1
def main():
args = parse_args()
device = 'cuda:0'
if_I = IFStageI('IF-I-XL-v1.0', device=device, hf_token=hf_token)
if_II = IFStageII('IF-II-L-v1.0', device=device, hf_token=hf_token)
t5 = T5Embedder(device="cpu")
result = style_transfer(
t5=t5, if_I=if_I, if_II=if_II,
support_pil_img=Image.open(args.input_file).convert('RGB'),
style_prompt=[
'in style of professional origami',
'in style of oil art, Tate modern',
'in style of plastic building bricks',
'in style of classic anime from 1990',
],
seed=args.tag,
if_I_kwargs={
"guidance_scale": 10.0,
"sample_timestep_respacing": "10,10,10,10,10,10,10,10,0,0",
'support_noise_less_qsample_steps': 5,
},
if_II_kwargs={
"guidance_scale": 4.0,
"sample_timestep_respacing": 'smart50',
"support_noise_less_qsample_steps": 5,
},
)
pil_images_list = result["II"]
# if_I.show(result['II'], 1, 20)
save_image(pil_images_list, save_path = "my_images", img_name = get_timestamped_filename())
print("doing next image ", args.tag)
if __name__ == "__main__":
main()
usage:
python3 style_transfer_if3.py -i <image-to-style> -t <random-seed-value>
from if.
save_path = "images", img_name = "generated_image"
Hi, klei22! I don't get it even after reading your code, is this a dream
demo?
from if.
Related Issues (20)
- How to download the model to local use? HOT 3
- How to Change Settings in Google Colab
- How to convert DeepFloyd model to onnx
- ImportError: cannot import name 'CLIPImageProcessor' from 'transformers'
- Null
- What is the FID-30K test subset? HOT 2
- Is the paper going to be released?
- Dedicated Inpainting Model
- Can only run locally? Can't you run on the server and ubuntu?
- Tensor error for basic example usage HOT 3
- Internal: unk is not defined HOT 3
- Error related to Transformers version when launching HOT 1
- There has a path bug in stage_III_sd_x4 file.
- Citation Information HOT 2
- Variance Scheduler HOT 2
- what is bs_scale for?
- ValueError: CLIPVisionModelWithProjection does not support `device_map='auto'`. To implement support, the model class needs to implement the `_no_split_modules` attribute. HOT 6
- OOM appears using DeepFloyd_IF (I use 32G video memory) HOT 3
- can the huggingface repository be un-gated?
- Fine Tuning
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 if.