-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from v0xie/dev
New features - CFG Scheduler, CFG Interval, PAG Start/End Step, Fix T2I-0
- Loading branch information
Showing
8 changed files
with
760 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__pycache__/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+552 KB
images/xyz_grid-3192-1-A pointillist painting of a raccoon looking at the sea.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.28 MB
...48-1590472902-A photo of a lion and a grizzly bear and a tiger in the woods.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+648 KB
... pouring coffee from a cup into an overflowing carafe, 4K, directed by Wong.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import torch | ||
import matplotlib.pyplot as plt | ||
|
||
def plot_attention_map(attention_map: torch.Tensor, title, x_label="X", y_label="Y", save_path=None, plot_type="default"): | ||
""" Plots an attention map using matplotlib.pyplot | ||
Arguments: | ||
attention_map: Tensor - The attention map to plot. Shape: (H, W) | ||
title: str - The title of the plot | ||
x_label: str (optional) - The x-axis label | ||
y_label: str (optional) - The y-axis label | ||
save_path: str (optional) - The path to save the plot | ||
plot_type: str (optional) - The type of plot to create. Default is 'default'. | ||
Other option is 'num' which will plot the attention map with arbitrary colors. | ||
Returns: | ||
None | ||
""" | ||
|
||
# Convert attention map to numpy array | ||
attention_map = attention_map.detach().cpu().numpy() | ||
|
||
# Create figure and axis | ||
fig, ax = plt.subplots() | ||
|
||
# Plot the attention map | ||
if plot_type=='default': | ||
ax.imshow(attention_map, cmap='viridis', interpolation='nearest') | ||
elif plot_type == 'num': | ||
ax.imshow(attention_map, cmap='tab20c', interpolation='nearest') | ||
#for x in range(attention_map.shape[0]): | ||
# for y in range(attention_map.shape[1]): | ||
# fig.text(x, y, f"{attention_map[x, y]:.2f}", ha="center", va="center") | ||
elements = list(set(attention_map.flatten())) | ||
labels = [f"{x}" for x in elements] | ||
fig.legend(elements, labels, loc='lower left') | ||
|
||
# Set title and labels | ||
ax.set_title(title) | ||
ax.set_xlabel(x_label) | ||
ax.set_ylabel(y_label) | ||
|
||
# Save the plot if save_path is provided | ||
if save_path: | ||
plt.savefig(save_path) | ||
|
||
plt.close(fig) | ||
|
||
# Show the plot | ||
# plt.show() | ||
|
||
# Convert the plot to PIL image | ||
#image = Image.fromarray(np.uint8(fig.canvas.tostring_rgb())) | ||
|
||
#return image |
Oops, something went wrong.