1- import platform
2- from cellpose .models import CellposeModel
31import numpy as np
2+ import pytest
43
54
65#################### 2D Tests ####################
7- # def test_shape_2D_grayscale():
8- # img = np.zeros((224, 224))
9- # model = models.CellposeModel( )
10- # masks, _, _ = model .eval(img)
11- # assert masks.shape == (224, 224)
6+ @ pytest . mark . slow
7+ def test_shape_2D_grayscale ( cellposemodel_fixture_2D ):
8+ img = np . zeros (( 224 , 224 ) )
9+ masks , _ , _ = cellposemodel_fixture_2D .eval (img )
10+ assert masks .shape == (224 , 224 )
1211
1312
1413def test_shape_2D_chan_first_diam_resize (cellposemodel_fixture_2D ):
@@ -19,11 +18,11 @@ def test_shape_2D_chan_first_diam_resize(cellposemodel_fixture_2D):
1918 assert flows [2 ].shape == (224 , 224 ), 'cellprob shape mismatch'
2019
2120
22- # def test_shape_2D_chan_diam_resize():
23- # img = np.zeros((1, 224, 224))
24- # model = models.CellposeModel( )
25- # masks, _, _ = model .eval(img, diameter=50)
26- # assert masks.shape == (224, 224)
21+ @ pytest . mark . slow
22+ def test_shape_2D_chan_diam_resize ( cellposemodel_fixture_2D ):
23+ img = np . zeros (( 1 , 224 , 224 ) )
24+ masks , _ , _ = cellposemodel_fixture_2D .eval (img , diameter = 50 )
25+ assert masks .shape == (224 , 224 )
2726
2827
2928def test_shape_2D_chan_last (cellposemodel_fixture_2D ):
@@ -35,11 +34,11 @@ def test_shape_2D_chan_last(cellposemodel_fixture_2D):
3534
3635
3736
38- # def test_shape_2D_chan_specify():
39- # img = np.zeros((224, 224, 2))
40- # model = models.CellposeModel( )
41- # masks, _, _ = model .eval(img, channel_axis=-1)
42- # assert masks.shape == (224, 224)
37+ @ pytest . mark . slow
38+ def test_shape_2D_chan_specify ( cellposemodel_fixture_2D ):
39+ img = np . zeros (( 224 , 224 , 2 ) )
40+ masks , _ , _ = cellposemodel_fixture_2D .eval (img , channel_axis = - 1 )
41+ assert masks .shape == (224 , 224 )
4342
4443
4544def test_shape_2D_2chan_specify (cellposemodel_fixture_2D ):
@@ -63,36 +62,32 @@ def test_shape_stitch(cellposemodel_fixture_3D):
6362 assert flows [2 ].shape == (5 , 80 , 80 ), 'cellprob shape mismatch'
6463
6564
66- # def test_shape_3D():
67- # img = np.zeros((80, 80, 5, 1))
68- # use_gpu = torch.cuda.is_available()
69- # model = models.CellposeModel(gpu=use_gpu)
70- # masks, _, _ = model.eval(img, channel_axis=3, z_axis=2, do_3D=True)
71- # assert masks.shape == (5, 80, 80)
65+ @pytest .mark .slow
66+ def test_shape_3D (cellposemodel_fixture_3D ):
67+ img = np .zeros ((80 , 80 , 5 , 1 ))
68+ masks , _ , _ = cellposemodel_fixture_3D .eval (img , channel_axis = 3 , z_axis = 2 , do_3D = True )
69+ assert masks .shape == (5 , 80 , 80 )
7270
7371
74- # def test_shape_3D_1ch():
75- # img = np.zeros((5, 80, 80, 1))
76- # use_gpu = torch.cuda.is_available()
77- # model = models.CellposeModel(gpu=use_gpu)
78- # masks, _, _ = model.eval(img, channel_axis=3, z_axis=0, do_3D=True)
79- # assert masks.shape == (5, 80, 80)
72+ @pytest .mark .slow
73+ def test_shape_3D_1ch (cellposemodel_fixture_3D ):
74+ img = np .zeros ((5 , 80 , 80 , 1 ))
75+ masks , _ , _ = cellposemodel_fixture_3D .eval (img , channel_axis = 3 , z_axis = 0 , do_3D = True )
76+ assert masks .shape == (5 , 80 , 80 )
8077
8178
82- # def test_shape_3D_1ch_3ndim():
83- # img = np.zeros((5, 80, 80))
84- # use_gpu = torch.cuda.is_available()
85- # model = models.CellposeModel(gpu=use_gpu)
86- # masks, _, _ = model.eval(img, channel_axis=None, z_axis=0, do_3D=True)
87- # assert masks.shape == (5, 80, 80)
79+ @pytest .mark .slow
80+ def test_shape_3D_1ch_3ndim (cellposemodel_fixture_3D ):
81+ img = np .zeros ((5 , 80 , 80 ))
82+ masks , _ , _ = cellposemodel_fixture_3D .eval (img , channel_axis = None , z_axis = 0 , do_3D = True )
83+ assert masks .shape == (5 , 80 , 80 )
8884
8985
90- # def test_shape_3D_1ch_3ndim_diam():
91- # img = np.zeros((5, 80, 80))
92- # use_gpu = torch.cuda.is_available()
93- # model = models.CellposeModel(gpu=use_gpu)
94- # masks, _, _ = model.eval(img, channel_axis=None, diameter=50, z_axis=0, do_3D=True)
95- # assert masks.shape == (5, 80, 80)
86+ @pytest .mark .slow
87+ def test_shape_3D_1ch_3ndim_diam (cellposemodel_fixture_3D ):
88+ img = np .zeros ((5 , 80 , 80 ))
89+ masks , _ , _ = cellposemodel_fixture_3D .eval (img , channel_axis = None , diameter = 50 , z_axis = 0 , do_3D = True )
90+ assert masks .shape == (5 , 80 , 80 )
9691
9792
9893def test_shape_3D_2ch (cellposemodel_fixture_3D ):
@@ -104,18 +99,16 @@ def test_shape_3D_2ch(cellposemodel_fixture_3D):
10499 assert flows [2 ].shape == (4 , 80 , 80 ), 'cellprob shape mismatch'
105100
106101
107- # def test_shape_3D_rgb_diam():
108- # img = np.zeros((5, 80, 80, 3))
109- # use_gpu = torch.cuda.is_available()
110- # model = models.CellposeModel(gpu=use_gpu)
111- # masks, _, _ = model.eval(img, diameter=50, channels=[0, 0],
112- # channel_axis=3, z_axis=0, do_3D=True)
113- # assert masks.shape == (5, 80, 80)
102+ @pytest .mark .slow
103+ def test_shape_3D_rgb_diam (cellposemodel_fixture_3D ):
104+ img = np .zeros ((5 , 80 , 80 , 3 ))
105+ masks , _ , _ = cellposemodel_fixture_3D .eval (img , diameter = 50 , channels = [0 , 0 ],
106+ channel_axis = 3 , z_axis = 0 , do_3D = True )
107+ assert masks .shape == (5 , 80 , 80 )
114108
115- # def test_shape_3D_rgb():
116- # img = np.zeros((5, 80, 80, 3))
117- # use_gpu = torch.cuda.is_available()
118- # model = models.CellposeModel(gpu=use_gpu)
119- # masks, _, _ = model.eval(img, channels=[0, 0],
120- # channel_axis=3, z_axis=0, do_3D=True)
121- # assert masks.shape == (5, 80, 80)
109+ @pytest .mark .slow
110+ def test_shape_3D_rgb (cellposemodel_fixture_3D ):
111+ img = np .zeros ((5 , 80 , 80 , 3 ))
112+ masks , _ , _ = cellposemodel_fixture_3D .eval (img , channels = [0 , 0 ],
113+ channel_axis = 3 , z_axis = 0 , do_3D = True )
114+ assert masks .shape == (5 , 80 , 80 )
0 commit comments