Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
g207004202
explainable-multimodal-classification
Commits
370a622c
Commit
370a622c
authored
May 11, 2021
by
Mao, Bojia
Browse files
add torchray example
parent
bbbeb235
Changes
1
Hide whitespace changes
Inline
Side-by-side
examples/TorchRay_MMBT_example.py
0 → 100644
View file @
370a622c
from
mmxai.interpretability.classification.torchray.extremal_perturbation.multimodal_extremal_perturbation
import
multi_extremal_perturbation
,
image2tensor
import
torch
from
PIL
import
Image
from
mmf.models.mmbt
import
MMBT
def
main
():
image_path
=
input
(
"enter your image path : "
)
text
=
input
(
"enter your text : "
)
model
=
MMBT
.
from_pretrained
(
"mmbt.hateful_memes.images"
)
model
.
to
(
torch
.
device
(
"cuda:0"
if
torch
.
cuda
.
is_available
()
else
"cpu"
))
image_tensor
=
image2tensor
(
image_path
)
mask_
,
hist_
,
output_tensor
,
txt_summary
,
text_explaination
=
multi_extremal_perturbation
(
model
,
image_tensor
,
image_path
,
text
,
0
,
# 0 non hateful 1 hateful
max_iter
=
50
,
areas
=
[
0.12
],
)
return
output_tensor
,
txt_summary
,
text_explaination
if
__name__
==
"__main__"
:
main
()
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment