Skip to content

Commit 632fb9b

Browse files
committed
[Fix]Fix the deprecation of np.float and fix ci configuration (open-mmlab#2451)
## Motivation 1. numpy from 1.24 deprecated the aliases np.object, np.bool, np.float, np.complex, np.str, and np.int https://numpy.org/devdocs/release/1.24.0-notes.html 2. timm needs to pytorch>=1.7, so ignore test timm in pytorch 1.5 and 1.6 3. Remove install pillow as it doesn't test torchvision < 0.5 ## Modification 1. np.float->np.float32 2. torch >= '1.7.0' -> matrix.torch != '1.5.1+cu101' && matrix.torch != '1.6.0+cu101' (as '1.10' < '1.7' 3. Remove install pillow
1 parent c0515a1 commit 632fb9b

File tree

2 files changed

+28
-32
lines changed

2 files changed

+28
-32
lines changed

.github/workflows/build.yml

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,13 @@ jobs:
7171
coverage xml
7272
coverage report -m
7373
# timm from v0.6.11 requires torch>=1.7
74-
if: ${{matrix.torch >= '1.7.0'}}
74+
if: ${{matrix.torch != '1.5.1' && matrix.torch != '1.6.0'}}
7575
- name: Skip timm unittests and generate coverage report
7676
run: |
7777
coverage run --branch --source mmseg -m pytest tests/ --ignore tests/test_models/test_backbones/test_timm_backbone.py
7878
coverage xml
7979
coverage report -m
80-
if: ${{matrix.torch < '1.7.0'}}
80+
if: ${{matrix.torch == '1.5.1' || matrix.torch == '1.6.0'}}
8181

8282
build_cuda101:
8383
runs-on: ubuntu-18.04
@@ -123,15 +123,13 @@ jobs:
123123
apt-get update && apt-get install -y libgl1-mesa-glx ffmpeg libsm6 libxext6 git ninja-build libglib2.0-0 libsm6 libxrender-dev libxext6 python${{matrix.python-version}}-dev
124124
apt-get clean
125125
rm -rf /var/lib/apt/lists/*
126-
- name: Install Pillow
127-
run: python -m pip install Pillow==6.2.2
128-
if: ${{matrix.torchvision < 0.5}}
129126
- name: Install PyTorch
130127
run: python -m pip install torch==${{matrix.torch}} torchvision==${{matrix.torchvision}} -f https://download.pytorch.org/whl/torch_stable.html
131128
- name: Install mmseg dependencies
132129
run: |
133130
python -V
134-
python -m pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cu101/${{matrix.torch_version}}/index.html
131+
python -m pip install -U openmim
132+
mim install mmcv-full
135133
python -m pip install -r requirements.txt
136134
python -c 'import mmcv; print(mmcv.__version__)'
137135
- name: Build and install
@@ -146,13 +144,13 @@ jobs:
146144
coverage xml
147145
coverage report -m
148146
# timm from v0.6.11 requires torch>=1.7
149-
if: ${{matrix.torch >= '1.7.0'}}
147+
if: ${{matrix.torch != '1.5.1+cu101' && matrix.torch != '1.6.0+cu101'}}
150148
- name: Skip timm unittests and generate coverage report
151149
run: |
152150
coverage run --branch --source mmseg -m pytest tests/ --ignore tests/test_models/test_backbones/test_timm_backbone.py
153151
coverage xml
154152
coverage report -m
155-
if: ${{matrix.torch < '1.7.0'}}
153+
if: ${{matrix.torch == '1.5.1+cu101' || matrix.torch == '1.6.0+cu101'}}
156154
- name: Upload coverage to Codecov
157155
uses: codecov/[email protected]
158156
with:
@@ -163,10 +161,12 @@ jobs:
163161
fail_ci_if_error: false
164162

165163
build_cuda102:
164+
env:
165+
LC_ALL: C.UTF-8
166+
LANG: C.UTF-8
166167
runs-on: ubuntu-18.04
167168
container:
168169
image: pytorch/pytorch:1.9.0-cuda10.2-cudnn7-devel
169-
170170
strategy:
171171
matrix:
172172
python-version: [3.6, 3.7, 3.8, 3.9]
@@ -175,7 +175,6 @@ jobs:
175175
- torch: 1.9.0+cu102
176176
torch_version: torch1.9
177177
torchvision: 0.10.0+cu102
178-
179178
steps:
180179
- uses: actions/checkout@v2
181180
- name: Set up Python ${{ matrix.python-version }}
@@ -191,15 +190,13 @@ jobs:
191190
apt-get update && apt-get install -y libgl1-mesa-glx ffmpeg libsm6 libxext6 git ninja-build libglib2.0-0 libsm6 libxrender-dev libxext6
192191
apt-get clean
193192
rm -rf /var/lib/apt/lists/*
194-
- name: Install Pillow
195-
run: python -m pip install Pillow==6.2.2
196-
if: ${{matrix.torchvision < 0.5}}
197193
- name: Install PyTorch
198194
run: python -m pip install torch==${{matrix.torch}} torchvision==${{matrix.torchvision}} -f https://download.pytorch.org/whl/torch_stable.html
199195
- name: Install mmseg dependencies
200196
run: |
201197
python -V
202-
python -m pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cu102/${{matrix.torch_version}}/index.html
198+
python -m pip install openmim
199+
mim install mmcv-full
203200
python -m pip install -r requirements.txt
204201
python -c 'import mmcv; print(mmcv.__version__)'
205202
- name: Build and install
@@ -256,15 +253,13 @@ jobs:
256253
run: python -m pip install torch==${{matrix.torch}} torchvision==${{matrix.torchvision}} -f https://download.pytorch.org/whl/torch_stable.html
257254
- name: Install system dependencies
258255
run: apt-get update && apt-get install -y ffmpeg libturbojpeg ninja-build
259-
- name: Install Pillow
260-
run: python -m pip install Pillow==6.2.2
261-
if: ${{matrix.torchvision < 0.5}}
262256
- name: Install PyTorch
263257
run: python -m pip install torch==${{matrix.torch}} torchvision==${{matrix.torchvision}} -f https://download.pytorch.org/whl/torch_stable.html
264258
- name: Install mmseg dependencies
265259
run: |
266260
python -V
267-
python -m pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cu116/${{matrix.torch_version}}/index.html
261+
python -m pip install openmim
262+
mim install mmcv-full
268263
python -m pip install -r requirements.txt
269264
python -c 'import mmcv; print(mmcv.__version__)'
270265
- name: Build and install
@@ -301,14 +296,15 @@ jobs:
301296
run: pip install torch==1.8.2+${{ matrix.platform }} torchvision==0.9.2+${{ matrix.platform }} -f https://download.pytorch.org/whl/lts/1.8/torch_lts.html
302297
- name: Install MMCV
303298
run: |
304-
pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cpu/torch1.8/index.html --only-binary mmcv-full
299+
pip install -U openmim
300+
mim install mmcv-full
305301
- name: Install unittest dependencies
306302
run: pip install -r requirements/tests.txt -r requirements/optional.txt
307303
- name: Build and install
308304
run: pip install -e .
309305
- name: Run unittests
310306
run: |
311-
python -m pip install 'timm<0.6.11'
307+
python -m pip install timm
312308
coverage run --branch --source mmseg -m pytest tests/
313309
- name: Generate coverage report
314310
run: |

tests/test_metrics.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def get_confusion_matrix(pred_label, label, num_classes, ignore_index):
3131
def legacy_mean_iou(results, gt_seg_maps, num_classes, ignore_index):
3232
num_imgs = len(results)
3333
assert len(gt_seg_maps) == num_imgs
34-
total_mat = np.zeros((num_classes, num_classes), dtype=np.float)
34+
total_mat = np.zeros((num_classes, num_classes), dtype=np.float32)
3535
for i in range(num_imgs):
3636
mat = get_confusion_matrix(
3737
results[i], gt_seg_maps[i], num_classes, ignore_index=ignore_index)
@@ -48,7 +48,7 @@ def legacy_mean_iou(results, gt_seg_maps, num_classes, ignore_index):
4848
def legacy_mean_dice(results, gt_seg_maps, num_classes, ignore_index):
4949
num_imgs = len(results)
5050
assert len(gt_seg_maps) == num_imgs
51-
total_mat = np.zeros((num_classes, num_classes), dtype=np.float)
51+
total_mat = np.zeros((num_classes, num_classes), dtype=np.float32)
5252
for i in range(num_imgs):
5353
mat = get_confusion_matrix(
5454
results[i], gt_seg_maps[i], num_classes, ignore_index=ignore_index)
@@ -69,7 +69,7 @@ def legacy_mean_fscore(results,
6969
beta=1):
7070
num_imgs = len(results)
7171
assert len(gt_seg_maps) == num_imgs
72-
total_mat = np.zeros((num_classes, num_classes), dtype=np.float)
72+
total_mat = np.zeros((num_classes, num_classes), dtype=np.float32)
7373
for i in range(num_imgs):
7474
mat = get_confusion_matrix(
7575
results[i], gt_seg_maps[i], num_classes, ignore_index=ignore_index)
@@ -100,7 +100,7 @@ def test_metrics():
100100
'IoU']
101101
all_acc_l, acc_l, iou_l = legacy_mean_iou(results, label, num_classes,
102102
ignore_index)
103-
assert all_acc == all_acc_l
103+
assert np.allclose(all_acc, all_acc_l)
104104
assert np.allclose(acc, acc_l)
105105
assert np.allclose(iou, iou_l)
106106
# Test the correctness of the implementation of mDice calculation.
@@ -110,7 +110,7 @@ def test_metrics():
110110
'Dice']
111111
all_acc_l, acc_l, dice_l = legacy_mean_dice(results, label, num_classes,
112112
ignore_index)
113-
assert all_acc == all_acc_l
113+
assert np.allclose(all_acc, all_acc_l)
114114
assert np.allclose(acc, acc_l)
115115
assert np.allclose(dice, dice_l)
116116
# Test the correctness of the implementation of mDice calculation.
@@ -120,7 +120,7 @@ def test_metrics():
120120
'Recall'], ret_metrics['Precision'], ret_metrics['Fscore']
121121
all_acc_l, recall_l, precision_l, fscore_l = legacy_mean_fscore(
122122
results, label, num_classes, ignore_index)
123-
assert all_acc == all_acc_l
123+
assert np.allclose(all_acc, all_acc_l)
124124
assert np.allclose(recall, recall_l)
125125
assert np.allclose(precision, precision_l)
126126
assert np.allclose(fscore, fscore_l)
@@ -135,7 +135,7 @@ def test_metrics():
135135
'aAcc'], ret_metrics['Acc'], ret_metrics['IoU'], ret_metrics[
136136
'Dice'], ret_metrics['Precision'], ret_metrics[
137137
'Recall'], ret_metrics['Fscore']
138-
assert all_acc == all_acc_l
138+
assert np.allclose(all_acc, all_acc_l)
139139
assert np.allclose(acc, acc_l)
140140
assert np.allclose(iou, iou_l)
141141
assert np.allclose(dice, dice_l)
@@ -228,7 +228,7 @@ def test_mean_iou():
228228
'IoU']
229229
all_acc_l, acc_l, iou_l = legacy_mean_iou(results, label, num_classes,
230230
ignore_index)
231-
assert all_acc == all_acc_l
231+
assert np.allclose(all_acc, all_acc_l)
232232
assert np.allclose(acc, acc_l)
233233
assert np.allclose(iou, iou_l)
234234

@@ -254,7 +254,7 @@ def test_mean_dice():
254254
'Dice']
255255
all_acc_l, acc_l, dice_l = legacy_mean_dice(results, label, num_classes,
256256
ignore_index)
257-
assert all_acc == all_acc_l
257+
assert np.allclose(all_acc, all_acc_l)
258258
assert np.allclose(acc, acc_l)
259259
assert np.allclose(iou, dice_l)
260260

@@ -280,7 +280,7 @@ def test_mean_fscore():
280280
'Recall'], ret_metrics['Precision'], ret_metrics['Fscore']
281281
all_acc_l, recall_l, precision_l, fscore_l = legacy_mean_fscore(
282282
results, label, num_classes, ignore_index)
283-
assert all_acc == all_acc_l
283+
assert np.allclose(all_acc, all_acc_l)
284284
assert np.allclose(recall, recall_l)
285285
assert np.allclose(precision, precision_l)
286286
assert np.allclose(fscore, fscore_l)
@@ -291,7 +291,7 @@ def test_mean_fscore():
291291
'Recall'], ret_metrics['Precision'], ret_metrics['Fscore']
292292
all_acc_l, recall_l, precision_l, fscore_l = legacy_mean_fscore(
293293
results, label, num_classes, ignore_index, beta=2)
294-
assert all_acc == all_acc_l
294+
assert np.allclose(all_acc, all_acc_l)
295295
assert np.allclose(recall, recall_l)
296296
assert np.allclose(precision, precision_l)
297297
assert np.allclose(fscore, fscore_l)
@@ -346,6 +346,6 @@ def save_arr(input_arrays: list, title: str, is_image: bool, dir: str):
346346
'Acc'], ret_metrics['IoU']
347347
all_acc_l, acc_l, iou_l = legacy_mean_iou(results, labels, num_classes,
348348
ignore_index)
349-
assert all_acc == all_acc_l
349+
assert np.allclose(all_acc, all_acc_l)
350350
assert np.allclose(acc, acc_l)
351351
assert np.allclose(iou, iou_l)

0 commit comments

Comments
 (0)