-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bac18b1
commit 504adbe
Showing
2 changed files
with
22 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import torch | ||
from torchvision.models import resnet50 | ||
|
||
from torch_featurelayer import FeatureLayers | ||
|
||
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') | ||
|
||
# Load a pretrained ResNet-50 model | ||
model = resnet50(weights='DEFAULT').eval().to(device) | ||
|
||
# Hook onto layers ['layer1', 'layer2', 'layer3', 'layer4'] of the model | ||
layer_paths = ['layer1', 'layer2', 'layer3', 'layer4'] | ||
hooked_model = FeatureLayers(model, layer_paths) | ||
|
||
# Forward pass an input tensor through the model | ||
x = torch.randn(1, 3, 224, 224).to(device) | ||
feature_outputs, output = hooked_model(x) | ||
|
||
# Print the output shapes | ||
for layer_path, feature_output in feature_outputs.items(): | ||
print(f'{layer_path} output shape: {feature_output.shape}') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters