Spaces:
Build error
Build error
Commit
·
31cf632
1
Parent(s):
918d78a
updated app
Browse files
app.py
CHANGED
|
@@ -158,7 +158,6 @@ elif modelName=="parseq":
|
|
| 158 |
converter = TokenLabelConverter(opt)
|
| 159 |
modelCopy = copy.deepcopy(model)
|
| 160 |
|
| 161 |
-
""" evaluation """
|
| 162 |
scoring_singlechar = STRScore(opt=opt, converter=converter, device=device, enableSingleCharAttrAve=True, model=modelCopy)
|
| 163 |
super_pixel_model_singlechar = torch.nn.Sequential(
|
| 164 |
# super_pixler,
|
|
@@ -191,6 +190,17 @@ if opt.blackbg:
|
|
| 191 |
# x = st.slider('Select a value')
|
| 192 |
# st.write(x, 'squared is', x * x)
|
| 193 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 194 |
### Acquire pixelwise attributions and replace them with ranked numbers averaged
|
| 195 |
### across segmentation with the largest contribution having the largest number
|
| 196 |
### and the smallest set to 1, which is the minimum number.
|
|
|
|
| 158 |
converter = TokenLabelConverter(opt)
|
| 159 |
modelCopy = copy.deepcopy(model)
|
| 160 |
|
|
|
|
| 161 |
scoring_singlechar = STRScore(opt=opt, converter=converter, device=device, enableSingleCharAttrAve=True, model=modelCopy)
|
| 162 |
super_pixel_model_singlechar = torch.nn.Sequential(
|
| 163 |
# super_pixler,
|
|
|
|
| 190 |
# x = st.slider('Select a value')
|
| 191 |
# st.write(x, 'squared is', x * x)
|
| 192 |
|
| 193 |
+
### Returns the mean for each segmentation having shape as the same as the input
|
| 194 |
+
### This function can only one attribution image at a time
|
| 195 |
+
def averageSegmentsOut(attr, segments):
|
| 196 |
+
averagedInput = torch.clone(attr)
|
| 197 |
+
sortedDict = {}
|
| 198 |
+
for x in np.unique(segments):
|
| 199 |
+
segmentMean = torch.mean(attr[segments == x][:])
|
| 200 |
+
sortedDict[x] = float(segmentMean.detach().cpu().numpy())
|
| 201 |
+
averagedInput[segments == x] = segmentMean
|
| 202 |
+
return averagedInput, sortedDict
|
| 203 |
+
|
| 204 |
### Acquire pixelwise attributions and replace them with ranked numbers averaged
|
| 205 |
### across segmentation with the largest contribution having the largest number
|
| 206 |
### and the smallest set to 1, which is the minimum number.
|