python类uint16()的实例源码

pascal3d.py 文件源码 项目:faster_rcnn_pytorch 作者: longcw 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def _load_selective_search_IJCV_roidb(self, gt_roidb):
        IJCV_path = os.path.abspath(os.path.join(self.cache_path, '..',
                                                 'selective_search_IJCV_data',
                                                 'voc_' + self._year))
        assert os.path.exists(IJCV_path), \
               'Selective search IJCV data not found at: {}'.format(IJCV_path)

        top_k = self.config['top_k']
        box_list = []
        for i in xrange(self.num_images):
            filename = os.path.join(IJCV_path, self.image_index[i] + '.mat')
            raw_data = sio.loadmat(filename)
            box_list.append((raw_data['boxes'][:top_k, :]-1).astype(np.uint16))

        return self.create_roidb_from_box_list(box_list, gt_roidb)

    # evaluate detection results
test_nested_layers.py 文件源码 项目:pytoshop 作者: mdboom 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def test_mixed_depth():
    from pytoshop.user.nested_layers import Group, Image

    img1 = np.empty((100, 80), dtype=np.uint8)
    img2 = np.empty((100, 80), dtype=np.uint16)

    layers = [
        Group(
            layers=[
                Image(channels={0: img1},
                      top=0, left=0, bottom=100, right=80),
                Image(channels=img2,
                      top=15, left=15),
            ])
    ]

    with pytest.raises(ValueError):
        nested_layers.nested_layers_to_psd(
            layers, enums.ColorMode.grayscale)
trainer_matches.py 文件源码 项目:Yugioh-bot 作者: will7200 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def read_captured_circles(self):
        img = cv2.cvtColor(self.query, cv2.COLOR_BGR2GRAY)
        img = cv2.medianBlur(img, 7)
        cimg = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)

        circles = cv2.HoughCircles(img, cv2.HOUGH_GRADIENT, 1, 30,
                                   param1=50, param2=30, minRadius=20, maxRadius=50)
        if circles is None:
            return
        circles = np.uint16(np.around(circles))
        for i in circles[0, :]:
            if i[1] < 400:
                continue
            self.circlePoints.append((i[0], i[1]))
        if self._debug:
            self.draw_circles(circles, cimg)
sealiondata.py 文件源码 项目:sealionengine 作者: gecrooks 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def load_train_image(self, train_id, scale=1, border=0, mask=False):
        """Return image as numpy array.

        Args:
            border (int): Add a black border of this width around image
            mask (bool): If true copy masks from corresponding dotted image

        Returns:
            uint8 numpy array
        """
        img = self._load_image('train', train_id, scale, border)
        if mask:
            # The masked areas are not uniformly black, presumable due to
            # jpeg compression artifacts
            MASK_MAX = 40
            dot_img = self.load_dotted_image(train_id, scale, border).astype(np.uint16).sum(axis=-1)
            img = np.copy(img)
            img[dot_img < MASK_MAX] = 0
        return img
cube.py 文件源码 项目:pytrip 作者: pytrip 项目源码 文件源码 阅读 44 收藏 0 点赞 0 评论 0
def set_data_type(self, type):
        """ Sets the data type for the TRiP98 header files.

        :param numpy.type type: numpy type, e.g. np.uint16
        """
        if type is np.int8 or type is np.uint8:
            self.data_type = "integer"
            self.num_bytes = 1
        elif type is np.int16 or type is np.uint16:
            self.data_type = "integer"
            self.num_bytes = 2
        elif type is np.int32 or type is np.uint32:
            self.data_type = "integer"
            self.num_bytes = 4
        elif type is np.float:
            self.data_type = "float"
            self.num_bytes = 4
        elif type is np.double:
            self.data_type = "double"
            self.num_bytes = 8

    # ######################  WRITING DICOM FILES #######################################
pascal3d.py 文件源码 项目:Automatic_Group_Photography_Enhancement 作者: Yuliang-Zou 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def _load_selective_search_IJCV_roidb(self, gt_roidb):
        IJCV_path = os.path.abspath(os.path.join(self.cache_path, '..',
                                                 'selective_search_IJCV_data',
                                                 'voc_' + self._year))
        assert os.path.exists(IJCV_path), \
               'Selective search IJCV data not found at: {}'.format(IJCV_path)

        top_k = self.config['top_k']
        box_list = []
        for i in xrange(self.num_images):
            filename = os.path.join(IJCV_path, self.image_index[i] + '.mat')
            raw_data = sio.loadmat(filename)
            box_list.append((raw_data['boxes'][:top_k, :]-1).astype(np.uint16))

        return self.create_roidb_from_box_list(box_list, gt_roidb)

    # evaluate detection results
hid_relay_16.py 文件源码 项目:openag_brain 作者: OpenAgInitiative 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def read(self):

        readCmd = [0xD2, 0x0E, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x48, 0x49, 0x44,
                   0x43, 0x80, 0x02, 0x00, 0x00, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC,
                   0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC,
                   0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC,
                   0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC]

        readCmd_pack = self.pack_bytes(readCmd)
        # assert len(self.hid.write(self.ep_out_address, readCmd_pack, 100)) == len(readCmd_pack)
        self.hid.write(self.ep_out_address, readCmd_pack, 100)

        data_pack = self.hid.read(self.ep_in_address, self.packet_len, 100)

        np_arr8 = numpy.uint8([data_pack[2], data_pack[3]])

        arr16 = np_arr8.view('uint16')

        mask = arr16[0]

        return mask
sep_labels.py 文件源码 项目:rec-attend-public 作者: renmengye 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def get_separate_labels(label_img):
    # 64-bit encoding
    dtype = label_img.dtype
    if dtype == np.uint8:
        w = 8
    elif dtype == np.uint16:
        w = 16
    else:
        raise Exception('Unknown dtype: "{}"'.format(dtype))
    l64 = label_img.astype('uint64')
    # Single channel mapping
    if len(l64.shape) == 3:
        l64i = ((l64[:, :, 0] << 2 * w) + (l64[:, :, 1] << w) + l64[:, :, 2])
    else:
        l64i = l64
    colors = np.unique(l64i)
    segmentations = []
    colors_all = []
    for c in colors:
        if c != 0:
            segmentation = (l64i == c).astype('uint8')
            segmentations.append(segmentation)
            colors_all.append(c)
    return segmentations, colors_all
mxnet_backend.py 文件源码 项目:deep-learning-keras-projects 作者: jasmeetsb 项目源码 文件源码 阅读 55 收藏 0 点赞 0 评论 0
def _typename(t):
    if t == np.float16:
        return 'float16'
    elif t == np.float32:
        return 'float32'
    elif t == np.float64:
        return 'float64'
    elif t == np.uint8:
        return 'uint8'
    elif t == np.uint16:
        return 'uint16'
    elif t == np.int16:
        return 'int16'
    elif t == np.int32:
        return 'int32'
    elif t == np.int64:
        return 'int64'
    else:
        raise TypeError('unknown type')
json.py 文件源码 项目:incubator-airflow-old 作者: apache 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def default(self, obj):
        # convert dates and numpy objects in a json serializable format
        if isinstance(obj, datetime):
            return obj.strftime('%Y-%m-%dT%H:%M:%SZ')
        elif isinstance(obj, date):
            return obj.strftime('%Y-%m-%d')
        elif type(obj) in (np.int_, np.intc, np.intp, np.int8, np.int16,
                           np.int32, np.int64, np.uint8, np.uint16,
                           np.uint32, np.uint64):
            return int(obj)
        elif type(obj) in (np.bool_,):
            return bool(obj)
        elif type(obj) in (np.float_, np.float16, np.float32, np.float64,
                           np.complex_, np.complex64, np.complex128):
            return float(obj)

        # Let the base class default method raise the TypeError
        return json.JSONEncoder.default(self, obj)
sep_labels.py 文件源码 项目:cityscapes-api 作者: renmengye 项目源码 文件源码 阅读 42 收藏 0 点赞 0 评论 0
def get_separate_labels(label_img):
  # 64-bit encoding
  dtype = label_img.dtype
  if dtype == np.uint8:
    w = 8
  elif dtype == np.uint16:
    w = 16
  else:
    raise Exception('Unknown dtype: "{}"'.format(dtype))
  l64 = label_img.astype('uint64')
  # Single channel mapping
  if len(l64.shape) == 3:
    l64i = ((l64[:, :, 0] << 2 * w) + (l64[:, :, 1] << w) + l64[:, :, 2])
  else:
    l64i = l64
  colors = np.unique(l64i)
  segmentations = []
  colors_all = []
  for c in colors:
    if c != 0:
      segmentation = (l64i == c).astype('uint8')
      segmentations.append(segmentation)
      colors_all.append(c)
  return segmentations, colors_all
create_ndvi_worldgrid.py 文件源码 项目:rastercube 作者: terrai 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def _real_mp_write_frac(frac_id, grid_w, grid_h, frac_ndates):
    # ignore the PEP 3118 buffer warning
    with warnings.catch_warnings():
        warnings.simplefilter('ignore', RuntimeWarning)
        s_ndvi = np.ctypeslib.as_array(_mp_ndvi)
        s_ndvi.shape = (grid_h, grid_w, frac_ndates)
        s_ndvi.dtype = np.int16
        s_qa = np.ctypeslib.as_array(_mp_qa)
        s_qa.shape = (grid_h, grid_w, frac_ndates)
        s_qa.dtype = np.uint16

    frac_num, frac_d = frac_id

    i_range, j_range = modgrid.get_cell_indices_in_tile(
        frac_num, tile_h, tile_v)
    frac_ndvi = s_ndvi[i_range[0]:i_range[1], j_range[0]:j_range[1], :]
    frac_qa = s_qa[i_range[0]:i_range[1], j_range[0]:j_range[1], :]

    ndvi_header.write_frac(frac_id, frac_ndvi)
    qa_header.write_frac(frac_id, frac_qa)
genotype_filters.py 文件源码 项目:varapp-backend-py 作者: varapp 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def scan_genotypes(self, genotypes, sub_ids=None, db=None):
        """Pass through all genotypes and return only the indices of those that pass the filter.
        :param genotypes: np.ndarray[uint64, dim=2]
        :rtype: np.ndarray[uint64]"""
        if self.shortcut:
            return np.zeros(0)
        N = len(genotypes)
        if sub_ids is not None:
            variant_ids = sub_ids
        elif self.val == 'x_linked' and db:
            variant_ids = genotypes_service(db).chrX
        else:
            variant_ids = np.asarray(range(1,N+1), dtype=np.uint64)
        active_idx = np.asarray(self.ss.active_idx, dtype=np.uint16)
        conditions = self.conditions_vector
        is_and = self.merge_op == AND
        if len(conditions) == 0:
            passing = variant_ids
        else:
            passing = self.parallel_apply_bitwise(genotypes, variant_ids, conditions, active_idx, is_and)
        return passing
genotype_filters.py 文件源码 项目:varapp-backend-py 作者: varapp 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def scan_genotypes_compound(self, genotypes, batches, parallel=True):
        """Scan the *genotypes* array for compounds. Variant ids are treated in batches,
           - one list of variant_ids per gene."""
        if self.shortcut:
            passing, sources, pairs = np.zeros(0), {}, []
        else:
            N = len(genotypes)
            active_idx = np.asarray(self.ss.active_idx, dtype=np.uint16)
            batches = list(batches.items())
            if parallel:
                passing, sources, pairs = self.parallel_batches(genotypes, batches, active_idx, N)
            else:
                passing, sources, pairs = self.process_batches(genotypes, batches, active_idx, N)
            passing = np.array(list(passing), dtype=np.uint64)
            passing.sort()
        return passing, sources, pairs
test_multiarray.py 文件源码 项目:krpcScripts 作者: jwvanderbeck 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def test_int(self):
        for st, ut, s in [(np.int8, np.uint8, 8),
                          (np.int16, np.uint16, 16),
                          (np.int32, np.uint32, 32),
                          (np.int64, np.uint64, 64)]:
            for i in range(1, s):
                assert_equal(hash(st(-2**i)), hash(-2**i),
                             err_msg="%r: -2**%d" % (st, i))
                assert_equal(hash(st(2**(i - 1))), hash(2**(i - 1)),
                             err_msg="%r: 2**%d" % (st, i - 1))
                assert_equal(hash(st(2**i - 1)), hash(2**i - 1),
                             err_msg="%r: 2**%d - 1" % (st, i))

                i = max(i - 1, 1)
                assert_equal(hash(ut(2**(i - 1))), hash(2**(i - 1)),
                             err_msg="%r: 2**%d" % (ut, i - 1))
                assert_equal(hash(ut(2**i - 1)), hash(2**i - 1),
                             err_msg="%r: 2**%d - 1" % (ut, i))
test_multiarray.py 文件源码 项目:krpcScripts 作者: jwvanderbeck 项目源码 文件源码 阅读 109 收藏 0 点赞 0 评论 0
def test_prod(self):
        ba = [1, 2, 10, 11, 6, 5, 4]
        ba2 = [[1, 2, 3, 4], [5, 6, 7, 9], [10, 3, 4, 5]]

        for ctype in [np.int16, np.uint16, np.int32, np.uint32,
                      np.float32, np.float64, np.complex64, np.complex128]:
            a = np.array(ba, ctype)
            a2 = np.array(ba2, ctype)
            if ctype in ['1', 'b']:
                self.assertRaises(ArithmeticError, a.prod)
                self.assertRaises(ArithmeticError, a2.prod, axis=1)
            else:
                assert_equal(a.prod(axis=0), 26400)
                assert_array_equal(a2.prod(axis=0),
                                   np.array([50, 36, 84, 180], ctype))
                assert_array_equal(a2.prod(axis=-1),
                                   np.array([24, 1890, 600], ctype))
test_half.py 文件源码 项目:krpcScripts 作者: jwvanderbeck 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def test_half_values(self):
        """Confirms a small number of known half values"""
        a = np.array([1.0, -1.0,
                      2.0, -2.0,
                      0.0999755859375, 0.333251953125,  # 1/10, 1/3
                      65504, -65504,           # Maximum magnitude
                      2.0**(-14), -2.0**(-14),  # Minimum normal
                      2.0**(-24), -2.0**(-24),  # Minimum subnormal
                      0, -1/1e1000,            # Signed zeros
                      np.inf, -np.inf])
        b = np.array([0x3c00, 0xbc00,
                      0x4000, 0xc000,
                      0x2e66, 0x3555,
                      0x7bff, 0xfbff,
                      0x0400, 0x8400,
                      0x0001, 0x8001,
                      0x0000, 0x8000,
                      0x7c00, 0xfc00], dtype=uint16)
        b.dtype = float16
        assert_equal(a, b)
test_half.py 文件源码 项目:krpcScripts 作者: jwvanderbeck 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def test_spacing_nextafter(self):
        """Test np.spacing and np.nextafter"""
        # All non-negative finite #'s
        a = np.arange(0x7c00, dtype=uint16)
        hinf = np.array((np.inf,), dtype=float16)
        a_f16 = a.view(dtype=float16)

        assert_equal(np.spacing(a_f16[:-1]), a_f16[1:]-a_f16[:-1])

        assert_equal(np.nextafter(a_f16[:-1], hinf), a_f16[1:])
        assert_equal(np.nextafter(a_f16[0], -hinf), -a_f16[1])
        assert_equal(np.nextafter(a_f16[1:], -hinf), a_f16[:-1])

        # switch to negatives
        a |= 0x8000

        assert_equal(np.spacing(a_f16[0]), np.spacing(a_f16[1]))
        assert_equal(np.spacing(a_f16[1:]), a_f16[:-1]-a_f16[1:])

        assert_equal(np.nextafter(a_f16[0], hinf), -a_f16[1])
        assert_equal(np.nextafter(a_f16[1:], hinf), a_f16[:-1])
        assert_equal(np.nextafter(a_f16[:-1], -hinf), a_f16[1:])
test_function_base.py 文件源码 项目:krpcScripts 作者: jwvanderbeck 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def test_basic(self):
        ba = [1, 2, 10, 11, 6, 5, 4]
        ba2 = [[1, 2, 3, 4], [5, 6, 7, 9], [10, 3, 4, 5]]
        for ctype in [np.int16, np.uint16, np.int32, np.uint32,
                      np.float32, np.float64, np.complex64, np.complex128]:
            a = np.array(ba, ctype)
            a2 = np.array(ba2, ctype)
            if ctype in ['1', 'b']:
                self.assertRaises(ArithmeticError, np.prod, a)
                self.assertRaises(ArithmeticError, np.prod, a2, 1)
            else:
                assert_equal(a.prod(axis=0), 26400)
                assert_array_equal(a2.prod(axis=0),
                                   np.array([50, 36, 84, 180], ctype))
                assert_array_equal(a2.prod(axis=-1),
                                   np.array([24, 1890, 600], ctype))
test_function_base.py 文件源码 项目:krpcScripts 作者: jwvanderbeck 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def test_basic(self):
        ba = [1, 2, 10, 11, 6, 5, 4]
        ba2 = [[1, 2, 3, 4], [5, 6, 7, 9], [10, 3, 4, 5]]
        for ctype in [np.int16, np.uint16, np.int32, np.uint32,
                      np.float32, np.float64, np.complex64, np.complex128]:
            a = np.array(ba, ctype)
            a2 = np.array(ba2, ctype)
            if ctype in ['1', 'b']:
                self.assertRaises(ArithmeticError, np.cumprod, a)
                self.assertRaises(ArithmeticError, np.cumprod, a2, 1)
                self.assertRaises(ArithmeticError, np.cumprod, a)
            else:
                assert_array_equal(np.cumprod(a, axis=-1),
                                   np.array([1, 2, 20, 220,
                                             1320, 6600, 26400], ctype))
                assert_array_equal(np.cumprod(a2, axis=0),
                                   np.array([[1, 2, 3, 4],
                                             [5, 12, 21, 36],
                                             [50, 36, 84, 180]], ctype))
                assert_array_equal(np.cumprod(a2, axis=-1),
                                   np.array([[1, 2, 6, 24],
                                             [5, 30, 210, 1890],
                                             [10, 30, 120, 600]], ctype))


问题


面经


文章

微信
公众号

扫码关注公众号