Spaces:
Running on Zero
Running on Zero
Bundle TrustMark weights; verify watermark with a test embed at startup
Browse filesFiles changed (4)
- app.py+14-3
- trustmark_models/decoder_Q.ckptAdded+3
- trustmark_models/encoder_Q.ckptAdded+3
- trustmark_models/trustmark_Q.yamlAdded+85
65 unmodified lines6667686970717273747576777865 unmodified linespath = hf_hub_download(REPO, CKPT, token=os.environ.get("HF_TOKEN"))from hobby_image.inference import HobbyImagem = HobbyImage(path, device="cpu")for _ in range(3): # trustmark downloads its decoder on first init; retry transient failurestry:from hobby_image import watermark as WMWM._trustmark()_wm_ok = Truebreakexcept Exception:time.sleep(3)if _ZERO:try:65 unmodified lines66676869707172737475767778798081828384858687888965 unmodified linespath = hf_hub_download(REPO, CKPT, token=os.environ.get("HF_TOKEN"))from hobby_image.inference import HobbyImagem = HobbyImage(path, device="cpu")try: # pre-place the bundled TrustMark weights so no download is attemptedimport shutilimport trustmark as _tmpkgtdir = os.path.join(os.path.dirname(_tmpkg.__file__), "models")here = os.path.join(os.path.dirname(os.path.abspath(__file__)), "trustmark_models")for f in os.listdir(here):shutil.copy(os.path.join(here, f), os.path.join(tdir, f))except Exception:pass # fall through; the retry loop below may still download themfrom PIL import Imagefrom hobby_image import watermark as WMfor _ in range(3): # trustmark fetches any missing/invalid file on first inittry:WM.embed(Image.new("RGB", (256, 256), "gray")) # proves encoder weights really loaded_wm_ok = Truebreakexcept Exception:WM._tm = None # a half-initialised TrustMark would otherwise be cachedtime.sleep(3)if _ZERO:try:
123version https://git-lfs.github.com/spec/v1oid sha256:e3d9cea5406a26590735719f8f15cb10802b11852ae69047eaf4cf17214df781size 47652460123version https://git-lfs.github.com/spec/v1oid sha256:dc382c3f6b4fd568b27d6fbb763d6ffc2d2587126d84afe9d5ee95b4c5d99826size 1730207412345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485model: target: trustmark.model.TrustMark_Arch params: cover_key: "image" secret_key: "secret" secret_len: 100 resolution: 256 use_ema: False lr_scheduler: CosineAnnealingRestartCyclicLR
secret_encoder_config: target: trustmark.unet.Unet1 params: width: 32 ndown: 4 nmiddle: 1 activ: silu
secret_decoder_config: target: trustmark.unet.SecretDecoder params: arch: resnet50
discriminator_config: target: trustmark.munit.MsDCDisGP params: gp_weight: 10.0 num_scales: 1 norm: none
loss_config: target: trustmark.loss.ImageSecretLoss params: recon_type: ffl+yuv recon_weight: 1.5 perceptual_weight: 1.0 kl_weight: 0.0 secret_weight: 20.0 generator_weight: 0.5 discriminator_weight: 1.0 generator_update_freq: 2 max_image_weight_ratio: 27.5
noise_config: target: trustmark.utils.transformations2.TransformNet params: ramp: 10000 severity: high crop_mode: resized_crop gamma: false # this cause issue
data: target: trustmark.utils.imgcap_dataset.DataModuleFromConfig params: batch_size: 32 num_workers: 4 wrap: false use_worker_init_fn: true
lightning: callbacks: image_logger: target: trustmark.logger.ImageLogger params: batch_frequency: 5000 max_images: 4 increase_log_steps: False fixed_input: True # log the same image batch progress_bar: target: lightning.pytorch.callbacks.TQDMProgressBar params: refresh_rate: 100 checkpoint: target: lightning.pytorch.callbacks.ModelCheckpoint params: verbose: true filename: '{epoch:06}-{step:09}' every_n_train_steps: 10000
trainer: benchmark: True base_learning_rate: 4e-6 lr_mult: true accumulate_grad_batches: 1 max_epochs: 150app.py+14-3
trustmark_models/decoder_Q.ckptAdded+3
trustmark_models/encoder_Q.ckptAdded+3
trustmark_models/trustmark_Q.yamlAdded+85