FeatureSqueezing#
- class scio.scores.FeatureSqueezing(*, act_norm=None, mode='raw', squeezers=?, dist_norm=1.0, aggregation='max')[source]#
Bases:
BaseScoreClassifFeature squeezing for classification.
- Parameters:
squeezers (
SqueezerLike | Iterable[SqueezerLike, ...]) –One or multiple “squeezers”. We define
type Squeezer = Callable[[Tensor], Tensor] type SqueezerLike = str | Squeezer
where callable squeezers should conserve the shape of their input. A squeezer of type
strdenotes one of the built-in squeezers:"bits:n"wherenis replaced with anint. This maps data onto an-bits discretized representation."median:s"weresis replaced with anint. Performs median pooling with sizes(or(s, s)). Works only for \(1\)D, \(2\)D or \(3\)D samples. For \(3\)D samples, operates per channel, with channel-first convention.
dist_norm (
float) – Order of the vector norm used to compute the distance between natural and squeezed softmax outputs. Defaults to1.0.aggregation (
AggrNameLike | float) – When several squeezers are used, how to aggregate their corresponding nonconformity scores. SeeAggrName. Defaults to"max".mode – See
BaseScoreClassif.act_norm – See
BaseScore.
References
[XEQ18]Weilin Xu, David Evans, and Yanjun Qi. Feature Squeezing: detecting adversarial examples in Deep Neural Networks. In Proceedings 2018 Network and Distributed System Security Symposium. 2018. URL: https://arxiv.org/pdf/1704.01155, doi:10.14722/ndss.2018.23198.
Hint
Below this point, the documentation is meant for development purposes only. Manual use of any listed member is highly discouraged. For usage, see Inferring with Confidence.
Useful methods defined here
bits_squeezing(inputs, *, n_bits)Squeeze
inputsinton_bitsrepresentation.Preprocessing to provide tuple of callable squeezers.
median_squeezing(inputs, *, size[, ...])Median pooling for batched samples (of max \(3\)D).
- static bits_squeezing(inputs, *, n_bits)[source]#
Squeeze
inputsinton_bitsrepresentation.- Parameters:
inputs (
Tensor) – The inputs to be squeezed inton_bitsrepresentation.n_bits (
int) – The number of bits used to encode \([0, 1)\) data. Must satisfy0 < n_bits < 32.
- Returns:
squeezed (
Tensor) –inputsrounded to the closest bin center, for bins of width1 / 2**n_bits.- Raises:
ValueError – If not
0 < n_bits < 32.
Note
Note that
1is rounded up to1 + 1 / 2**(n_bits + 1).