-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP]Img plugin support #17
Open
tudorcebere
wants to merge
2
commits into
master
Choose a base branch
from
image_plugin
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,2 @@ | ||
from . import tutorial_01_tensorboard_mnist | ||
from . import tutorial_02_saliency_map |
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,2 @@ | ||
import os, sys; sys.path.append(os.path.dirname(os.path.realpath(__file__))) | ||
from . import mnist |
Binary file added
BIN
+7.55 MB
examples/tutorial_01_tensorboard_mnist/mnist/data/MNIST/processed/test.pt
Binary file not shown.
Binary file added
BIN
+45.3 MB
examples/tutorial_01_tensorboard_mnist/mnist/data/MNIST/processed/training.pt
Binary file not shown.
Binary file added
BIN
+7.48 MB
examples/tutorial_01_tensorboard_mnist/mnist/data/MNIST/raw/t10k-images-idx3-ubyte
Binary file not shown.
Binary file added
BIN
+1.57 MB
examples/tutorial_01_tensorboard_mnist/mnist/data/MNIST/raw/t10k-images-idx3-ubyte.gz
Binary file not shown.
Binary file added
BIN
+9.77 KB
examples/tutorial_01_tensorboard_mnist/mnist/data/MNIST/raw/t10k-labels-idx1-ubyte
Binary file not shown.
Binary file added
BIN
+4.44 KB
examples/tutorial_01_tensorboard_mnist/mnist/data/MNIST/raw/t10k-labels-idx1-ubyte.gz
Binary file not shown.
Binary file added
BIN
+44.9 MB
examples/tutorial_01_tensorboard_mnist/mnist/data/MNIST/raw/train-images-idx3-ubyte
Binary file not shown.
Binary file added
BIN
+9.45 MB
examples/tutorial_01_tensorboard_mnist/mnist/data/MNIST/raw/train-images-idx3-ubyte.gz
Binary file not shown.
Binary file added
BIN
+58.6 KB
examples/tutorial_01_tensorboard_mnist/mnist/data/MNIST/raw/train-labels-idx1-ubyte
Binary file not shown.
Binary file added
BIN
+28.2 KB
examples/tutorial_01_tensorboard_mnist/mnist/data/MNIST/raw/train-labels-idx1-ubyte.gz
Binary file not shown.
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
21 changes: 21 additions & 0 deletions
21
examples/tutorial_03_image_writer/image_writer_tutorial.py
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 @@ | ||
from pytorchxai.plugin.writer import TorchXAIWriter | ||
from PIL import Image | ||
from torchvision.transforms.functional import to_tensor | ||
import torchvision | ||
|
||
logdir = "./runs/image_data" | ||
image = Image.open("/home/tudor/Downloads/5df126b679d7570ad2044f3e.jpeg") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is /home/tudor an official pytorch path? |
||
size = 264 | ||
|
||
model = torchvision.models.vgg19(pretrained=True) | ||
transform = torchvision.transforms.Compose( | ||
[ | ||
torchvision.transforms.Resize((size, size)), | ||
torchvision.transforms.ToTensor(), | ||
torchvision.transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]), | ||
torchvision.transforms.Lambda(lambda x: x[None]), | ||
] | ||
) | ||
|
||
writer = TorchXAIWriter() | ||
writer.add_saliency(image=image, model=model, transform=transform) |
Empty file.
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,16 @@ | ||
import torch.utils.tensorboard as tb | ||
from pytorchxai.xai.saliency_map import SaliencyMap | ||
from torchvision.transforms import ToTensor | ||
|
||
|
||
class TorchXAIWriter(tb.SummaryWriter): | ||
def __init__(self, log_dir=None, comment="", purge_step=None, max_queue=10, flush_secs=120, | ||
filename_suffix=""): | ||
super().__init__(log_dir, comment, purge_step, max_queue, flush_secs, filename_suffix) | ||
|
||
def add_saliency(self, image, model, transform): | ||
self.add_image(tag="saliency_ref", img_tensor=ToTensor()(image)) | ||
image = transform(image) | ||
saliency_img = SaliencyMap.generate(image, model) | ||
|
||
self.add_image(tag="saliency_img", img_tensor=saliency_img) |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's with the binary files on git? are they necessary?