fix individual images
This commit is contained in:
parent
798e6ac5a3
commit
f0c4fc7350
4
README.md
vendored
4
README.md
vendored
|
@ -62,7 +62,7 @@ display(image)
|
||||||
Credit to [@hardmaru](https://twitter.com/hardmaru) for the [example](https://twitter.com/hardmaru/status/1544354119527596034)
|
Credit to [@hardmaru](https://twitter.com/hardmaru) for the [example](https://twitter.com/hardmaru/status/1544354119527596034)
|
||||||
|
|
||||||
|
|
||||||
<!-- ### Saving Individual Images
|
### Saving Individual Images
|
||||||
The images can also be generated as a `FloatTensor` in case you want to process them manually.
|
The images can also be generated as a `FloatTensor` in case you want to process them manually.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
|
@ -85,7 +85,7 @@ Then image $i$ can be coverted to a PIL.Image and saved
|
||||||
```python
|
```python
|
||||||
image = Image.fromarray(images[i])
|
image = Image.fromarray(images[i])
|
||||||
image.save('image_{}.png'.format(i))
|
image.save('image_{}.png'.format(i))
|
||||||
``` -->
|
```
|
||||||
|
|
||||||
### Progressive Outputs
|
### Progressive Outputs
|
||||||
|
|
||||||
|
|
|
@ -171,7 +171,7 @@ class MinDalle:
|
||||||
return images
|
return images
|
||||||
|
|
||||||
|
|
||||||
def generate_image_stream(
|
def generate_raw_image_stream(
|
||||||
self,
|
self,
|
||||||
text: str,
|
text: str,
|
||||||
seed: int,
|
seed: int,
|
||||||
|
@ -182,7 +182,7 @@ class MinDalle:
|
||||||
top_k: int = 256,
|
top_k: int = 256,
|
||||||
supercondition_factor: int = 16,
|
supercondition_factor: int = 16,
|
||||||
is_verbose: bool = False
|
is_verbose: bool = False
|
||||||
) -> Iterator[Image.Image]:
|
) -> Iterator[FloatTensor]:
|
||||||
image_count = grid_size ** 2
|
image_count = grid_size ** 2
|
||||||
if is_verbose: print("tokenizing text")
|
if is_verbose: print("tokenizing text")
|
||||||
tokens = self.tokenizer.tokenize(text, is_verbose=is_verbose)
|
tokens = self.tokenizer.tokenize(text, is_verbose=is_verbose)
|
||||||
|
@ -249,84 +249,40 @@ class MinDalle:
|
||||||
|
|
||||||
with torch.cuda.amp.autocast(dtype=torch.float32):
|
with torch.cuda.amp.autocast(dtype=torch.float32):
|
||||||
if ((i + 1) % 32 == 0 and progressive_outputs) or i + 1 == 256:
|
if ((i + 1) % 32 == 0 and progressive_outputs) or i + 1 == 256:
|
||||||
image = self.image_grid_from_tokens(
|
yield self.image_grid_from_tokens(
|
||||||
image_tokens=image_tokens[1:].T,
|
image_tokens=image_tokens[1:].T,
|
||||||
is_seamless=is_seamless,
|
is_seamless=is_seamless,
|
||||||
is_verbose=is_verbose
|
is_verbose=is_verbose
|
||||||
)
|
)
|
||||||
image = image.to(torch.uint8).to('cpu').numpy()
|
|
||||||
yield Image.fromarray(image)
|
def generate_image_stream(self, *args, **kwargs) -> Iterator[Image.Image]:
|
||||||
|
image_stream = self.generate_raw_image_stream(*args, **kwargs)
|
||||||
|
for image in image_stream:
|
||||||
|
image = image.to(torch.uint8).to('cpu').numpy()
|
||||||
|
yield Image.fromarray(image)
|
||||||
|
|
||||||
|
|
||||||
def generate_image(
|
def generate_images_stream(self, *args, **kwargs) -> Iterator[FloatTensor]:
|
||||||
self,
|
image_stream = self.generate_raw_image_stream(*args, **kwargs)
|
||||||
text: str,
|
for image in image_stream:
|
||||||
seed: int = -1,
|
grid_size = kwargs['grid_size']
|
||||||
grid_size: int = 1,
|
image = image.view([grid_size * 256, grid_size, 256, 3])
|
||||||
temperature: float = 1,
|
image = image.transpose(1, 0)
|
||||||
top_k: int = 1024,
|
image = image.reshape([grid_size ** 2, 2 ** 8, 2 ** 8, 3])
|
||||||
supercondition_factor: int = 16,
|
yield image
|
||||||
is_verbose: bool = False
|
|
||||||
) -> Image.Image:
|
|
||||||
|
def generate_image(self, *args, **kwargs) -> Image.Image:
|
||||||
image_stream = self.generate_image_stream(
|
image_stream = self.generate_image_stream(
|
||||||
text=text,
|
*args, **kwargs,
|
||||||
seed=seed,
|
progressive_outputs=False
|
||||||
grid_size=grid_size,
|
|
||||||
progressive_outputs=False,
|
|
||||||
temperature=temperature,
|
|
||||||
top_k=top_k,
|
|
||||||
supercondition_factor=supercondition_factor,
|
|
||||||
is_verbose=is_verbose
|
|
||||||
)
|
)
|
||||||
return next(image_stream)
|
return next(image_stream)
|
||||||
|
|
||||||
|
|
||||||
# def images_from_image(image: Image.Image) -> FloatTensor:
|
def generate_images(self, *args, **kwargs) -> Image.Image:
|
||||||
# pass
|
images_stream = self.generate_images_stream(
|
||||||
|
*args, **kwargs,
|
||||||
# def generate_images_stream(
|
progressive_outputs=False
|
||||||
# self,
|
)
|
||||||
# text: str,
|
return next(images_stream)
|
||||||
# seed: int,
|
|
||||||
# grid_size: int,
|
|
||||||
# progressive_outputs: bool = False,
|
|
||||||
# temperature: float = 1,
|
|
||||||
# top_k: int = 256,
|
|
||||||
# supercondition_factor: int = 16,
|
|
||||||
# is_verbose: bool = False
|
|
||||||
# ) -> Iterator[FloatTensor]:
|
|
||||||
# image_stream = self.generate_image_stream(
|
|
||||||
# text=text,
|
|
||||||
# seed=seed,
|
|
||||||
# image_count=grid_size ** 2,
|
|
||||||
# progressive_outputs=progressive_outputs,
|
|
||||||
# is_seamless=False,
|
|
||||||
# temperature=temperature,
|
|
||||||
# top_k=top_k,
|
|
||||||
# supercondition_factor=supercondition_factor,
|
|
||||||
# is_verbose=is_verbose
|
|
||||||
# )
|
|
||||||
# for image in image_stream:
|
|
||||||
# yield self.images_from_image(image)
|
|
||||||
|
|
||||||
# def generate_images(
|
|
||||||
# self,
|
|
||||||
# text: str,
|
|
||||||
# seed: int = -1,
|
|
||||||
# image_count: int = 1,
|
|
||||||
# temperature: float = 1,
|
|
||||||
# top_k: int = 1024,
|
|
||||||
# supercondition_factor: int = 16,
|
|
||||||
# is_verbose: bool = False
|
|
||||||
# ) -> FloatTensor:
|
|
||||||
# images_stream = self.generate_images_stream(
|
|
||||||
# text=text,
|
|
||||||
# seed=seed,
|
|
||||||
# image_count=image_count,
|
|
||||||
# temperature=temperature,
|
|
||||||
# progressive_outputs=False,
|
|
||||||
# top_k=top_k,
|
|
||||||
# supercondition_factor=supercondition_factor,
|
|
||||||
# is_verbose=is_verbose
|
|
||||||
# )
|
|
||||||
# return next(images_stream)
|
|
|
@ -20,6 +20,7 @@ class ReplicatePredictor(BasePredictor):
|
||||||
text: str = Input(default='Dali painting of WALL·E'),
|
text: str = Input(default='Dali painting of WALL·E'),
|
||||||
save_as_png: bool = Input(default=False),
|
save_as_png: bool = Input(default=False),
|
||||||
progressive_outputs: bool = Input(default=True),
|
progressive_outputs: bool = Input(default=True),
|
||||||
|
seamless: bool = Input(default=False),
|
||||||
grid_size: int = Input(ge=1, le=9, default=5),
|
grid_size: int = Input(ge=1, le=9, default=5),
|
||||||
temperature: str = Input(
|
temperature: str = Input(
|
||||||
choices=(
|
choices=(
|
||||||
|
@ -45,6 +46,7 @@ class ReplicatePredictor(BasePredictor):
|
||||||
seed = -1,
|
seed = -1,
|
||||||
grid_size = grid_size,
|
grid_size = grid_size,
|
||||||
progressive_outputs = progressive_outputs,
|
progressive_outputs = progressive_outputs,
|
||||||
|
is_seamless=seamless,
|
||||||
temperature = eval(temperature),
|
temperature = eval(temperature),
|
||||||
supercondition_factor = float(supercondition_factor),
|
supercondition_factor = float(supercondition_factor),
|
||||||
top_k = top_k,
|
top_k = top_k,
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -5,7 +5,7 @@ setuptools.setup(
|
||||||
name='min-dalle',
|
name='min-dalle',
|
||||||
description = 'min(DALL·E)',
|
description = 'min(DALL·E)',
|
||||||
# long_description=(Path(__file__).parent / "README.rst").read_text(),
|
# long_description=(Path(__file__).parent / "README.rst").read_text(),
|
||||||
version='0.3.15',
|
version='0.3.16',
|
||||||
author='Brett Kuprel',
|
author='Brett Kuprel',
|
||||||
author_email='brkuprel@gmail.com',
|
author_email='brkuprel@gmail.com',
|
||||||
url='https://github.com/kuprel/min-dalle',
|
url='https://github.com/kuprel/min-dalle',
|
||||||
|
|
|
@ -101,7 +101,7 @@ def generate():
|
||||||
label_image.update()
|
label_image.update()
|
||||||
|
|
||||||
def save():
|
def save():
|
||||||
final_image.save('out.png')
|
final_image.save('generated/out.png')
|
||||||
|
|
||||||
frm = ttk.Frame(root, padding=16)
|
frm = ttk.Frame(root, padding=16)
|
||||||
frm.grid()
|
frm.grid()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user