Giter Site home page Giter Site logo

Comments (5)

ain-soph avatar ain-soph commented on August 14, 2024 1
  • train_mode == 'batch' won't modify dataset, it's attaching the trigger on demand during get_data by calling add_mark method
    Related codes:

    case 'batch':
    loader = self.dataset.get_dataloader(
    'train', batch_size=self.dataset.batch_size)
    return self.model._train(epochs, loader_train=loader,
    get_data_fn=self.get_data,
    **kwargs)
    case 'dataset':
    mix_dataset = torch.utils.data.ConcatDataset([self.dataset.loader['train'].dataset,
    self.poison_set])
    loader = self.dataset.get_dataloader('train', dataset=mix_dataset)
    return self.model._train(epochs, loader_train=loader, **kwargs)
    case 'loss':
    if 'loss_fn' in kwargs.keys():
    kwargs['loss_fn'] = functools.partial(self.loss_weighted, loss_fn=kwargs['loss_fn'])
    else:
    kwargs['loss_fn'] = self.loss_weighted
    return self.model._train(epochs, **kwargs)
    case _:
    raise NotImplementedError(f'{self.train_mode=}')

  • When train_mode == 'batch', calling add_mark(_input) (where _input is the clean batch image) shall return the entire image with the trigger.

    If you want to access the trigger image only, you need to view attack.mark.mark, which is a [4, H, W] tensor and the last channel is the transparency following RGBA color channel standard.
    Related docs: https://ain-soph.github.io/trojanzoo/trojanvision/marks.html#trojanvision.marks.Watermark

    You also mentioned calling add_mark will only return image contain the trigger. I'm confused why it is the case. Please show a brief snippet and its running results. A possible reason might be your trigger size is 32*32, which is the same as image size and it overwrites all pixels.

  • When train_mode == 'dataset', there will be a new property called poison_set.
    Related codes:

    self.poison_set = self.get_poison_dataset()

    Related docs:
    https://ain-soph.github.io/trojanzoo/trojanvision/attacks/index.html#trojanvision.attacks.BackdoorAttack

image

from trojanzoo.

ain-soph avatar ain-soph commented on August 14, 2024 1

Btw, just a trick, using torchvision.utils.save_image(backdoored_img, "trigger_img.jpg") is easier than plt.imsave("trigger_img.jpg", backdoored_img.cpu().numpy())

https://pytorch.org/vision/stable/generated/torchvision.utils.save_image.html?highlight=save_#torchvision.utils.save_image

from trojanzoo.

ain-soph avatar ain-soph commented on August 14, 2024 1

This doesn't seem to be a trigger either. I think plt.imsave requires HWC rather than CHW order (not sure, never use it).
So you might only output 3-pixel width somehow.

from trojanzoo.

pheobyy avatar pheobyy commented on August 14, 2024

Thank you for your quick response! :)

I tried it again with train_mode == 'dataset' and it worked

For train_mode == 'batch' :
I tried using torchvision.utils.save_image(backdoored_img, "trigger_img.jpg") instead of plt.imsave and everything worked fine! The "trigger_img" contained the images with the trigger attached.
So the issue seems to be only related to plt.imsave.
This is how "trigger_img" looks like if I use plt.imsave :
trigger_img

from trojanzoo.

ain-soph avatar ain-soph commented on August 14, 2024

I guess your problem has been solved in previous discussion. I'll close this issue. Feel free to re-open if there is still any problem related to this issue.

from trojanzoo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.