Feature Extraction
Transformers
PyTorch
bbsnet
custom_code
thinh-huynh-re commited on
Commit
32d1220
·
1 Parent(s): 917689e

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +55 -1
README.md CHANGED
@@ -40,7 +40,61 @@ datasets:
40
 
41
  <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
42
 
43
- [More Information Needed]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
 
45
  ### Downstream Use [optional]
46
 
 
40
 
41
  <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
42
 
43
+ ```python
44
+ import numpy as np
45
+ from datasets import load_dataset
46
+ from matplotlib import cm
47
+ from PIL import Image
48
+ from transformers import AutoImageProcessor, AutoModel
49
+
50
+ model = AutoModel.from_pretrained("RGBD-SOD/bbsnet", trust_remote_code=True)
51
+ image_processor = AutoImageProcessor.from_pretrained(
52
+ "RGBD-SOD/bbsnet", trust_remote_code=True
53
+ )
54
+ dataset = load_dataset("RGBD-SOD/test", "v1", split="train", cache_dir="data")
55
+
56
+ index = 0
57
+
58
+ """
59
+ Get a specific sample from the dataset
60
+
61
+ sample = {
62
+ 'depth': <PIL.PngImagePlugin.PngImageFile image mode=L size=640x360>,
63
+ 'rgb': <PIL.PngImagePlugin.PngImageFile image mode=RGB size=640x360>,
64
+ 'gt': <PIL.PngImagePlugin.PngImageFile image mode=L size=640x360>,
65
+ 'name': 'COME_Train_5'
66
+ }
67
+ """
68
+ sample = dataset[index]
69
+
70
+
71
+ """
72
+ preprocessed_sample = {
73
+ 'rgb': tensor([[[[-0.8507, ....0365]]]]),
74
+ 'gt': tensor([[[[0., 0., 0...., 0.]]]]),
75
+ 'depth': tensor([[[[0.9529, 0....3490]]]])
76
+ }
77
+ """
78
+ preprocessed_sample = image_processor.preprocess(sample)
79
+
80
+ """
81
+ output = {
82
+ 'logits': tensor([[[[-5.1966, ...ackward0>)
83
+ }
84
+ """
85
+ output = model(preprocessed_sample["rgb"], preprocessed_sample["depth"])
86
+
87
+ postprocessed_sample: np.ndarray = image_processor.postprocess(
88
+ output["logits"], [sample["gt"].size[1], sample["gt"].size[0]]
89
+ )
90
+ prediction = Image.fromarray(np.uint8(cm.gist_earth(postprocessed_sample) * 255))
91
+
92
+ """
93
+ Show the predicted salient map and the corresponding ground-truth(GT)
94
+ """
95
+ prediction.show()
96
+ sample["gt"].show()
97
+ ```
98
 
99
  ### Downstream Use [optional]
100