how can i see the watermark that i implant?
jinganglang567 opened this issue · comments
if i want to know the image an watermark what i need to do
Hi, if I understood it correctly, do you mean you want to visualize the watermark?
For example, if you want to visualize init_latents_w_fft
, you can use this code snippet after line 88:
import matplotlib.pyplot as plt
def visualize_tensor(tensor, name='./tmp.png'):
channels = tensor.squeeze(0).cpu().numpy()
fig, axs = plt.subplots(1, 4, figsize=(12, 3))
for i, ax in enumerate(axs):
ax.imshow(channels[i], cmap='gray')
ax.set_title(f'Channel {i+1}')
ax.axis('off')
plt.savefig(name)
plt.show()
init_latents_w_fft = torch.fft.fftshift(torch.fft.fft2(init_latents_w), dim=(-1, -2)).real
visualize_tensor(init_latents_w_fft, name='./real.png')
init_latents_w_fft = torch.fft.fftshift(torch.fft.fft2(init_latents_w), dim=(-1, -2)).imag
visualize_tensor(init_latents_w_fft, name='./imag.png')
Let me know if you have any problem with running it!
doctor,sorry to bother you again, if i want to visualize the soure image and the image inject ,what should i do?
Hi, do you mean you want to visualize the original generated image and the watermarked image? You can save orig_image_no_w
and orig_image_w
accordingly. Meanwhile, if you are using wandb, the generated images are logged to the report automatically here.
Hi, I assume you set reference_model
as null? Can you try to modify this line to if i < args.max_num_log_image:
? This will log first max_num_log_image
images, which is 100 by default.
thank you,doctor, i will try
@YuxinWenRick sorry to bother you again doctor,when i change the code. it show this in the wanb
it didn't solve the problem,i run the "python run_tree_ring_watermark.py --run_name no_attack --w_channel 3 --w_pattern ring --start 0 --end 1000 --with_tracking --reference_model ViT-g-14 --reference_model_pretrain laion2b_s12b_b42k"
Hi @jinganglang567 , Im not sure what's going wrong here with wandb, but you may want to save them locally.
Can you try to add the following snippet of code to here?
import os
from PIL import Image
if not os.path.exists("non_watermarked_images"):
os.makedirs("non_watermarked_images")
if not os.path.exists("watermarked_images"):
os.makedirs("watermarked_images")
orig_image_no_w.save(f"non_watermarked_images/{i}.jpg")
orig_image_w.save(f"watermarked_images/{i}.jpg")
doctor i am setting the wandb offline model and then upload
I see. Did you try the solution I posted above by saving them not through wandb?
@YuxinWenRick thanks doctor i can see the image, but i have another question :
TPR@1%FPR 1.0
wandb: acc 1.0
wandb: auc 1.0
wandb: clip_score_mean 0.36833
wandb: clip_score_std 0.03077
wandb: w_clip_score_mean 0.37428
wandb: w_clip_score_std 0.04165
This is the output of the terminal
Can i train my own model? and why we need reference model
Hi, if I understood it correctly, do you mean you want to visualize the watermark?
For example, if you want to visualize
init_latents_w_fft
, you can use this code snippet after line 88:import matplotlib.pyplot as plt def visualize_tensor(tensor, name='./tmp.png'): channels = tensor.squeeze(0).cpu().numpy() fig, axs = plt.subplots(1, 4, figsize=(12, 3)) for i, ax in enumerate(axs): ax.imshow(channels[i], cmap='gray') ax.set_title(f'Channel {i+1}') ax.axis('off') plt.savefig(name) plt.show() init_latents_w_fft = torch.fft.fftshift(torch.fft.fft2(init_latents_w), dim=(-1, -2)).real visualize_tensor(init_latents_w_fft, name='./real.png') init_latents_w_fft = torch.fft.fftshift(torch.fft.fft2(init_latents_w), dim=(-1, -2)).imag visualize_tensor(init_latents_w_fft, name='./imag.png')
Let me know if you have any problem with running it!
sorry to bother you ,doctor. i want to know One is the initial watermark, and the other is the watermark extracted from the marked image. If I want to see the extracted watermark, what should I do
this is the real and imag
Hi @jinganglang567 , you can add the same script after line 125, but you want to visualize reversed_latents_w
instead of init_latents_w
.
import matplotlib.pyplot as plt
def visualize_tensor(tensor, name='./tmp.png'):
channels = tensor.squeeze(0).cpu().numpy()
fig, axs = plt.subplots(1, 4, figsize=(12, 3))
for i, ax in enumerate(axs):
ax.imshow(channels[i], cmap='gray')
ax.set_title(f'Channel {i+1}')
ax.axis('off')
plt.savefig(name)
plt.show()
init_latents_w_fft = torch.fft.fftshift(torch.fft.fft2(reversed_latents_w), dim=(-1, -2)).real
visualize_tensor(init_latents_w_fft, name='./real.png')
init_latents_w_fft = torch.fft.fftshift(torch.fft.fft2(reversed_latents_w), dim=(-1, -2)).imag
visualize_tensor(init_latents_w_fft, name='./imag.png')
@YuxinWenRick thank you doctor. it worked