Skip to Content
Deep Learning with PyTorch
book

Deep Learning with PyTorch

by Vishnu Subramanian
February 2018
Intermediate to advanced
262 pages
6h 59m
English
Packt Publishing
Content preview from Deep Learning with PyTorch

Extracting DenseNet features

It is quite similar to what we did for Inception, except we are not using register_forward_hook to extract features. The following code shows how the DenseNet features are extracted:

#For training datatrn_labels = []trn_features = []#code to store densenet features for train dataset.for d,la in train_loader:    o = my_densenet(Variable(d.cuda()))    o = o.view(o.size(0),-1)    trn_labels.extend(la)    trn_features.extend(o.cpu().data)#For validation dataval_labels = []val_features = []#Code to store densenet features for validation dataset. for d,la in val_loader:    o = my_densenet(Variable(d.cuda()))    o = o.view(o.size(0),-1)    val_labels.extend(la)    val_features.extend(o.cpu().data)

The preceding code is similar to what we have ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Deep Learning with PyTorch

Deep Learning with PyTorch

Eli Stevens, Thomas Viehmann, Luca Pietro Giovanni Antiga
Grokking Deep Learning

Grokking Deep Learning

Andrew W. Trask

Publisher Resources

ISBN: 9781788624336Supplemental Content