Comments (2)
You can replace clamp_
by torch.maximum
and torch.minimum
, which can do the element-wise comparison between tensors. The sample code might be like
transform_train = tv.transforms.Compose([
tv.transforms.RandomCrop(32, padding=4, fill=0, padding_mode='constant'),
tv.transforms.RandomHorizontalFlip(),
tv.transforms.ToTensor(),
tv.transforms.Normalize(), # normalize by mean and std
])
min_tensor = torch.full((1, 3, 32, 32), 0)
max_tensor = torch.full((1, 3, 32, 32), 255)
min_tensor = transform_train(min_tensor)
max_tensor = transform_train(max_tensor)
def clamp(inputs, max, min):
max = max.expand(inputs.shape[0], -1, -1, -1) # match the shape of max to be the same as which of inputs
min = min.expand(inputs.shape[0], -1, -1, -1)
return torch.maximum(torch.minimum(inputs, max), min)
# in fast_gradient_sign_untargeted.py
x = clamp(x, max_tensor, min_tensor)
The code snippet should fit in your needs.
from pytorch-adversarial-training.
Thanks for your reply. It solves my question.
from pytorch-adversarial-training.
Related Issues (8)
- The default value of alpha in cifar10 HOT 2
- Replication of the Result in Madry's Cifar10 Challenge HOT 18
- opt.step() in the train function will use the information from the generator HOT 1
- Could you share your pre-trained adv_trained checkpoint? HOT 2
- The result of standard training model in cifar-10 is lower than reported in the paper HOT 1
- Question about Test adv acc
- More information about the updated checkpoint of pgd trained Madry's model on cifar-10 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pytorch-adversarial-training.