예제 #1
0
 def test_read_values_float(self, mock_dat):
     
     img2_data = self.img1_data[2:,1:,:]
     
     # mocks
     df = [self.img1_data.astype(float).flatten().ravel().tolist(),
           img2_data.astype(float).flatten().ravel().tolist()]
     
     mock_dat.return_value.ParseFromString.return_value = ""
     type(mock_dat.return_value).data = PropertyMock(return_value='')
     type(mock_dat.return_value).float_data = PropertyMock(side_effect=df)
     type(mock_dat.return_value).channels = PropertyMock(side_effect=[4, 2])
     type(mock_dat.return_value).height = PropertyMock(side_effect=[2, 1])
     type(mock_dat.return_value).width = PropertyMock(side_effect=[3, 3])
     
     v = r.read_values(self.path_lmdb, float)
     
     assert_equal(len(v), 2, "Unexpected no. of elements.")
     
     x, _ = v[0]
     for ch in range(4):
         for row in range(2):
             for col in range(3):
                 assert_equal(x[ch, row, col], self.img1_data[ch, row, col])
     
     x, _ = v[1]
     
     for ch in range(2):
         for row in range(1):
             for col in range(3):
                 assert_equal(x[ch, row, col], img2_data[ch, row, col])
예제 #2
0
    def test_read_values_pixels_with_labels_uint8(self, mock_dat):
        
        # mocks
        dstr = ['\x01\x04\x07\n\r\x10\x13\x16\x02\x05\x08\x0b\x0e\x11\x14\x17\x03\x06\t\x0c\x0f\x12\x15\x18',
                '\x10\x16\x11\x17\x12\x18']
        
        mock_dat.return_value.ParseFromString.return_value = ""
        type(mock_dat.return_value).data = PropertyMock(side_effect=dstr)
        type(mock_dat.return_value).channels = PropertyMock(side_effect=[3, 3])
        type(mock_dat.return_value).height = PropertyMock(side_effect=[4, 2])
        type(mock_dat.return_value).width = PropertyMock(side_effect=[2, 1])
        type(mock_dat.return_value).label = PropertyMock(side_effect=[1, 0])
        
        v = r.read_values(self.path_lmdb, np.uint8)
        
        assert_equal(len(v), 2)
        
        x, l = v[0]
        for ch in range(3):
            for row in range(4):
                for col in range(2):
                    assert_equal(x[ch, row, col], self.img1_data[row, col, ch])

        assert_equal(l, 1, "Unexpected 1st label")
        
        x, l = v[1]
        img2_data = self.img1_data[2:,1:,:]
        
        for ch in range(3):
            for row in range(2):
                for col in range(1):
                    assert_equal(x[ch, row, col], img2_data[row, col, ch])
                    
        assert_equal(l, 0, "Unexpected 2nd label")