flaviagiammarino commited on
Commit
32494c0
1 Parent(s): b042253

update examples

Browse files
.idea/.gitignore ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ # Default ignored files
2
+ /shelf/
3
+ /workspace.xml
.idea/inspectionProfiles/Project_Default.xml ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <component name="InspectionProjectProfileManager">
2
+ <profile version="1.0">
3
+ <option name="myName" value="Project Default" />
4
+ <inspection_tool class="PyPackageRequirementsInspection" enabled="true" level="WARNING" enabled_by_default="true">
5
+ <option name="ignoredPackages">
6
+ <value>
7
+ <list size="64">
8
+ <item index="0" class="java.lang.String" itemvalue="pandas" />
9
+ <item index="1" class="java.lang.String" itemvalue="kaleido" />
10
+ <item index="2" class="java.lang.String" itemvalue="plotly" />
11
+ <item index="3" class="java.lang.String" itemvalue="numpy" />
12
+ <item index="4" class="java.lang.String" itemvalue="tensorflow_probability" />
13
+ <item index="5" class="java.lang.String" itemvalue="tensorflow_addons" />
14
+ <item index="6" class="java.lang.String" itemvalue="Jinja2" />
15
+ <item index="7" class="java.lang.String" itemvalue="scipy" />
16
+ <item index="8" class="java.lang.String" itemvalue="statsmodels" />
17
+ <item index="9" class="java.lang.String" itemvalue="pytz" />
18
+ <item index="10" class="java.lang.String" itemvalue="dash_core_components" />
19
+ <item index="11" class="java.lang.String" itemvalue="Werkzeug" />
20
+ <item index="12" class="java.lang.String" itemvalue="dash_html_components" />
21
+ <item index="13" class="java.lang.String" itemvalue="MarkupSafe" />
22
+ <item index="14" class="java.lang.String" itemvalue="dash" />
23
+ <item index="15" class="java.lang.String" itemvalue="flask" />
24
+ <item index="16" class="java.lang.String" itemvalue="itsdangerous" />
25
+ <item index="17" class="java.lang.String" itemvalue="click" />
26
+ <item index="18" class="java.lang.String" itemvalue="dash_renderer" />
27
+ <item index="19" class="java.lang.String" itemvalue="gunicorn" />
28
+ <item index="20" class="java.lang.String" itemvalue="tensorflow" />
29
+ <item index="21" class="java.lang.String" itemvalue="torch" />
30
+ <item index="22" class="java.lang.String" itemvalue="gensim" />
31
+ <item index="23" class="java.lang.String" itemvalue="torchtext" />
32
+ <item index="24" class="java.lang.String" itemvalue="nltk" />
33
+ <item index="25" class="java.lang.String" itemvalue="h5py" />
34
+ <item index="26" class="java.lang.String" itemvalue="progressbar2" />
35
+ <item index="27" class="java.lang.String" itemvalue="torchvision" />
36
+ <item index="28" class="java.lang.String" itemvalue="Pillow" />
37
+ <item index="29" class="java.lang.String" itemvalue="dash-renderer" />
38
+ <item index="30" class="java.lang.String" itemvalue="dash_table" />
39
+ <item index="31" class="java.lang.String" itemvalue="scikit-learn" />
40
+ <item index="32" class="java.lang.String" itemvalue="absl-py" />
41
+ <item index="33" class="java.lang.String" itemvalue="protobuf" />
42
+ <item index="34" class="java.lang.String" itemvalue="rsa" />
43
+ <item index="35" class="java.lang.String" itemvalue="tensorflow-estimator" />
44
+ <item index="36" class="java.lang.String" itemvalue="pycodestyle" />
45
+ <item index="37" class="java.lang.String" itemvalue="requests" />
46
+ <item index="38" class="java.lang.String" itemvalue="requests-oauthlib" />
47
+ <item index="39" class="java.lang.String" itemvalue="certifi" />
48
+ <item index="40" class="java.lang.String" itemvalue="oauthlib" />
49
+ <item index="41" class="java.lang.String" itemvalue="keras" />
50
+ <item index="42" class="java.lang.String" itemvalue="tomli" />
51
+ <item index="43" class="java.lang.String" itemvalue="urllib3" />
52
+ <item index="44" class="java.lang.String" itemvalue="pyparsing" />
53
+ <item index="45" class="java.lang.String" itemvalue="Markdown" />
54
+ <item index="46" class="java.lang.String" itemvalue="autopep8" />
55
+ <item index="47" class="java.lang.String" itemvalue="libclang" />
56
+ <item index="48" class="java.lang.String" itemvalue="tensorboard-data-server" />
57
+ <item index="49" class="java.lang.String" itemvalue="wrapt" />
58
+ <item index="50" class="java.lang.String" itemvalue="kiwisolver" />
59
+ <item index="51" class="java.lang.String" itemvalue="packaging" />
60
+ <item index="52" class="java.lang.String" itemvalue="tensorflow-io-gcs-filesystem" />
61
+ <item index="53" class="java.lang.String" itemvalue="fonttools" />
62
+ <item index="54" class="java.lang.String" itemvalue="termcolor" />
63
+ <item index="55" class="java.lang.String" itemvalue="flatbuffers" />
64
+ <item index="56" class="java.lang.String" itemvalue="tensorboard" />
65
+ <item index="57" class="java.lang.String" itemvalue="typing_extensions" />
66
+ <item index="58" class="java.lang.String" itemvalue="cachetools" />
67
+ <item index="59" class="java.lang.String" itemvalue="charset-normalizer" />
68
+ <item index="60" class="java.lang.String" itemvalue="grpcio" />
69
+ <item index="61" class="java.lang.String" itemvalue="google-auth" />
70
+ <item index="62" class="java.lang.String" itemvalue="idna" />
71
+ <item index="63" class="java.lang.String" itemvalue="matplotlib" />
72
+ </list>
73
+ </value>
74
+ </option>
75
+ </inspection_tool>
76
+ <inspection_tool class="PyPep8Inspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
77
+ <option name="ignoredErrors">
78
+ <list>
79
+ <option value="E101" />
80
+ </list>
81
+ </option>
82
+ </inspection_tool>
83
+ <inspection_tool class="PyTypeCheckerInspection" enabled="false" level="WARNING" enabled_by_default="false" />
84
+ </profile>
85
+ </component>
.idea/inspectionProfiles/profiles_settings.xml ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ <component name="InspectionProjectProfileManager">
2
+ <settings>
3
+ <option name="USE_PROJECT_PROFILE" value="false" />
4
+ <version value="1.0" />
5
+ </settings>
6
+ </component>
.idea/misc.xml ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8" project-jdk-type="Python SDK" />
4
+ <component name="PyPackaging">
5
+ <option name="earlyReleasesAsUpgrades" value="true" />
6
+ </component>
7
+ </project>
.idea/modules.xml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/pubmed-clip-vit-base-patch32.iml" filepath="$PROJECT_DIR$/.idea/pubmed-clip-vit-base-patch32.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
.idea/pubmed-clip-vit-base-patch32.iml ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="PYTHON_MODULE" version="4">
3
+ <component name="NewModuleRootManager">
4
+ <content url="file://$MODULE_DIR$" />
5
+ <orderEntry type="inheritedJdk" />
6
+ <orderEntry type="sourceFolder" forTests="false" />
7
+ </component>
8
+ <component name="PyDocumentationSettings">
9
+ <option name="format" value="PLAIN" />
10
+ <option name="myDocStringFormat" value="Plain" />
11
+ </component>
12
+ </module>
.idea/vcs.xml ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="" vcs="Git" />
5
+ </component>
6
+ </project>
scripts/flax_example.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import jax
2
+ import requests
3
+ from PIL import Image
4
+ import matplotlib.pyplot as plt
5
+
6
+ from transformers import CLIPProcessor, FlaxCLIPModel
7
+
8
+ model = FlaxCLIPModel.from_pretrained("flaviagiammarino/pubmed-clip-vit-base-patch32")
9
+ processor = CLIPProcessor.from_pretrained("flaviagiammarino/pubmed-clip-vit-base-patch32")
10
+
11
+ url = "https://d168r5mdg5gtkq.cloudfront.net/medpix/img/full/synpic9078.jpg"
12
+ image = Image.open(requests.get(url, stream=True).raw)
13
+ text = ["Chest X-Ray", "Brain MRI", "Abdominal CT Scan"]
14
+
15
+ inputs = processor(text=text, images=image, return_tensors="jax", padding=True)
16
+ probs = jax.nn.softmax(model(**inputs).logits_per_image, axis=-1).flatten()
17
+
18
+ plt.subplots()
19
+ plt.imshow(image)
20
+ plt.title("".join([x[0] + ": " + x[1] + "\n" for x in zip(text, [format(prob, ".4%") for prob in probs])]))
21
+ plt.axis("off")
22
+ plt.tight_layout()
23
+ plt.show()
scripts/pt_example.py CHANGED
@@ -12,7 +12,7 @@ image = Image.open(requests.get(url, stream=True).raw)
12
  text = ["Chest X-Ray", "Brain MRI", "Abdominal CT Scan"]
13
 
14
  inputs = processor(text=text, images=image, return_tensors="pt", padding=True)
15
- probs = model(**inputs).logits_per_image.softmax(dim=1).detach().numpy().flatten()
16
 
17
  plt.subplots()
18
  plt.imshow(image)
 
12
  text = ["Chest X-Ray", "Brain MRI", "Abdominal CT Scan"]
13
 
14
  inputs = processor(text=text, images=image, return_tensors="pt", padding=True)
15
+ probs = model(**inputs).logits_per_image.softmax(dim=1).squeeze()
16
 
17
  plt.subplots()
18
  plt.imshow(image)
scripts/tf_example.py CHANGED
@@ -13,7 +13,7 @@ image = Image.open(requests.get(url, stream=True).raw)
13
  text = ["Chest X-Ray", "Brain MRI", "Abdominal CT Scan"]
14
 
15
  inputs = processor(text=text, images=image, return_tensors="tf", padding=True)
16
- probs = tf.nn.softmax(model(**inputs).logits_per_image, axis=-1).numpy().flatten()
17
 
18
  plt.subplots()
19
  plt.imshow(image)
 
13
  text = ["Chest X-Ray", "Brain MRI", "Abdominal CT Scan"]
14
 
15
  inputs = processor(text=text, images=image, return_tensors="tf", padding=True)
16
+ probs = tf.squeeze(tf.nn.softmax(model(**inputs).logits_per_image, axis=-1))
17
 
18
  plt.subplots()
19
  plt.imshow(image)