Python numpy.bool() Examples
The following are 30
code examples of numpy.bool().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
numpy
, or try the search function
.
Example #1
Source File: gimage_tests.py From radiometric_normalization with Apache License 2.0 | 6 votes |
def test_save_with_compress(self): output_file = 'test_save_with_compress.tif' test_band = numpy.array([[5, 2, 2], [1, 6, 8]], dtype=numpy.uint16) test_alpha = numpy.array([[0, 0, 0], [1, 1, 1]], dtype=numpy.bool) test_gimage = gimage.GImage([test_band, test_band, test_band], test_alpha, self.metadata) gimage.save(test_gimage, output_file, compress=True) result_gimg = gimage.load(output_file) numpy.testing.assert_array_equal(result_gimg.bands[0], test_band) numpy.testing.assert_array_equal(result_gimg.bands[1], test_band) numpy.testing.assert_array_equal(result_gimg.bands[2], test_band) numpy.testing.assert_array_equal(result_gimg.alpha, test_alpha) self.assertEqual(result_gimg.metadata, self.metadata) os.unlink(output_file)
Example #2
Source File: tf_example_decoder_test.py From DOTA_models with Apache License 2.0 | 6 votes |
def testDecodeObjectIsCrowd(self): image_tensor = np.random.randint(255, size=(4, 5, 3)).astype(np.uint8) encoded_jpeg = self._EncodeImage(image_tensor) object_is_crowd = [0, 1] example = tf.train.Example(features=tf.train.Features(feature={ 'image/encoded': self._BytesFeature(encoded_jpeg), 'image/format': self._BytesFeature('jpeg'), 'image/object/is_crowd': self._Int64Feature(object_is_crowd), })).SerializeToString() example_decoder = tf_example_decoder.TfExampleDecoder() tensor_dict = example_decoder.decode(tf.convert_to_tensor(example)) self.assertAllEqual((tensor_dict[ fields.InputDataFields.groundtruth_is_crowd].get_shape().as_list()), [None]) with self.test_session() as sess: tensor_dict = sess.run(tensor_dict) self.assertAllEqual([bool(item) for item in object_is_crowd], tensor_dict[ fields.InputDataFields.groundtruth_is_crowd])
Example #3
Source File: tf_example_decoder_test.py From DOTA_models with Apache License 2.0 | 6 votes |
def testDecodeObjectDifficult(self): image_tensor = np.random.randint(255, size=(4, 5, 3)).astype(np.uint8) encoded_jpeg = self._EncodeImage(image_tensor) object_difficult = [0, 1] example = tf.train.Example(features=tf.train.Features(feature={ 'image/encoded': self._BytesFeature(encoded_jpeg), 'image/format': self._BytesFeature('jpeg'), 'image/object/difficult': self._Int64Feature(object_difficult), })).SerializeToString() example_decoder = tf_example_decoder.TfExampleDecoder() tensor_dict = example_decoder.decode(tf.convert_to_tensor(example)) self.assertAllEqual((tensor_dict[ fields.InputDataFields.groundtruth_difficult].get_shape().as_list()), [None]) with self.test_session() as sess: tensor_dict = sess.run(tensor_dict) self.assertAllEqual([bool(item) for item in object_difficult], tensor_dict[ fields.InputDataFields.groundtruth_difficult])
Example #4
Source File: core.py From neuropythy with GNU Affero General Public License v3.0 | 6 votes |
def dataframe_select(df, *cols, **filters): ''' dataframe_select(df, k1=v1, k2=v2...) yields df after selecting all the columns in which the given keys (k1, k2, etc.) have been selected such that the associated columns in the dataframe contain only the rows whose cells match the given values. dataframe_select(df, col1, col2...) selects the given columns. dataframe_select(df, col1, col2..., k1=v1, k2=v2...) selects both. If a value is a tuple/list of 2 elements, then it is considered a range where cells must fall between the values. If value is a tuple/list of more than 2 elements or is a set of any length then it is a list of values, any one of which can match the cell. ''' ii = np.ones(len(df), dtype='bool') for (k,v) in six.iteritems(filters): vals = df[k].values if pimms.is_set(v): jj = np.isin(vals, list(v)) elif pimms.is_vector(v) and len(v) == 2: jj = (v[0] <= vals) & (vals < v[1]) elif pimms.is_vector(v): jj = np.isin(vals, list(v)) else: jj = (vals == v) ii = np.logical_and(ii, jj) if len(ii) != np.sum(ii): df = df.loc[ii] if len(cols) > 0: df = df[list(cols)] return df
Example #5
Source File: dqn_utils.py From cs294-112_hws with MIT License | 6 votes |
def store_effect(self, idx, action, reward, done): """Store effects of action taken after obeserving frame stored at index idx. The reason `store_frame` and `store_effect` is broken up into two functions is so that once can call `encode_recent_observation` in between. Paramters --------- idx: int Index in buffer of recently observed frame (returned by `store_frame`). action: int Action that was performed upon observing this frame. reward: float Reward that was received when the actions was performed. done: bool True if episode was finished after performing that action. """ self.action[idx] = action self.reward[idx] = reward self.done[idx] = done
Example #6
Source File: test_scipy_hungarian.py From QCElemental with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_linear_sum_assignment_input_validation(): assert_raises(ValueError, linear_sum_assignment, [1, 2, 3]) C = [[1, 2, 3], [4, 5, 6]] assert_array_equal(linear_sum_assignment(C), linear_sum_assignment(np.asarray(C))) # assert_array_equal(linear_sum_assignment(C), # linear_sum_assignment(matrix(C))) I = np.identity(3) assert_array_equal(linear_sum_assignment(I.astype(np.bool)), linear_sum_assignment(I)) assert_raises(ValueError, linear_sum_assignment, I.astype(str)) I[0][0] = np.nan assert_raises(ValueError, linear_sum_assignment, I) I = np.identity(3) I[1][1] = np.inf assert_raises(ValueError, linear_sum_assignment, I)
Example #7
Source File: buffer.py From lirpg with MIT License | 6 votes |
def put(self, enc_obs, actions, rewards, mus, dones, masks): # enc_obs [nenv, (nsteps + nstack), nh, nw, nc] # actions, rewards, dones [nenv, nsteps] # mus [nenv, nsteps, nact] if self.enc_obs is None: self.enc_obs = np.empty([self.size] + list(enc_obs.shape), dtype=np.uint8) self.actions = np.empty([self.size] + list(actions.shape), dtype=np.int32) self.rewards = np.empty([self.size] + list(rewards.shape), dtype=np.float32) self.mus = np.empty([self.size] + list(mus.shape), dtype=np.float32) self.dones = np.empty([self.size] + list(dones.shape), dtype=np.bool) self.masks = np.empty([self.size] + list(masks.shape), dtype=np.bool) self.enc_obs[self.next_idx] = enc_obs self.actions[self.next_idx] = actions self.rewards[self.next_idx] = rewards self.mus[self.next_idx] = mus self.dones[self.next_idx] = dones self.masks[self.next_idx] = masks self.next_idx = (self.next_idx + 1) % self.size self.num_in_buffer = min(self.size, self.num_in_buffer + 1)
Example #8
Source File: buffer.py From HardRLWithYoutube with MIT License | 6 votes |
def put(self, enc_obs, actions, rewards, mus, dones, masks): # enc_obs [nenv, (nsteps + nstack), nh, nw, nc] # actions, rewards, dones [nenv, nsteps] # mus [nenv, nsteps, nact] if self.enc_obs is None: self.enc_obs = np.empty([self.size] + list(enc_obs.shape), dtype=np.uint8) self.actions = np.empty([self.size] + list(actions.shape), dtype=np.int32) self.rewards = np.empty([self.size] + list(rewards.shape), dtype=np.float32) self.mus = np.empty([self.size] + list(mus.shape), dtype=np.float32) self.dones = np.empty([self.size] + list(dones.shape), dtype=np.bool) self.masks = np.empty([self.size] + list(masks.shape), dtype=np.bool) self.enc_obs[self.next_idx] = enc_obs self.actions[self.next_idx] = actions self.rewards[self.next_idx] = rewards self.mus[self.next_idx] = mus self.dones[self.next_idx] = dones self.masks[self.next_idx] = masks self.next_idx = (self.next_idx + 1) % self.size self.num_in_buffer = min(self.size, self.num_in_buffer + 1)
Example #9
Source File: utils.py From py360convert with MIT License | 6 votes |
def equirect_facetype(h, w): ''' 0F 1R 2B 3L 4U 5D ''' tp = np.roll(np.arange(4).repeat(w // 4)[None, :].repeat(h, 0), 3 * w // 8, 1) # Prepare ceil mask mask = np.zeros((h, w // 4), np.bool) idx = np.linspace(-np.pi, np.pi, w // 4) / 4 idx = h // 2 - np.round(np.arctan(np.cos(idx)) * h / np.pi).astype(int) for i, j in enumerate(idx): mask[:j, i] = 1 mask = np.roll(np.concatenate([mask] * 4, 1), 3 * w // 8, 1) tp[mask] = 4 tp[np.flip(mask, 0)] = 5 return tp.astype(np.int32)
Example #10
Source File: ModelingCloth.py From Modeling-Cloth with MIT License | 6 votes |
def get_poly_centers(ob, type=np.float32, mesh=None): mod = False m_count = len(ob.modifiers) if m_count > 0: show = np.zeros(m_count, dtype=np.bool) ren_set = np.copy(show) ob.modifiers.foreach_get('show_render', show) ob.modifiers.foreach_set('show_render', ren_set) mod = True p_count = len(mesh.polygons) center = np.zeros(p_count * 3, dtype=type) mesh.polygons.foreach_get('center', center) center.shape = (p_count, 3) if mod: ob.modifiers.foreach_set('show_render', show) return center
Example #11
Source File: ModelingCloth.py From Modeling-Cloth with MIT License | 6 votes |
def get_poly_normals(ob, type=np.float32, mesh=None): mod = False m_count = len(ob.modifiers) if m_count > 0: show = np.zeros(m_count, dtype=np.bool) ren_set = np.copy(show) ob.modifiers.foreach_get('show_render', show) ob.modifiers.foreach_set('show_render', ren_set) mod = True p_count = len(mesh.polygons) normal = np.zeros(p_count * 3, dtype=type) mesh.polygons.foreach_get('normal', normal) normal.shape = (p_count, 3) if mod: ob.modifiers.foreach_set('show_render', show) return normal
Example #12
Source File: ModelingCloth.py From Modeling-Cloth with MIT License | 6 votes |
def get_v_normals(ob, arr, mesh): """Since we're reading from a shape key we have to use a proxy mesh.""" mod = False m_count = len(ob.modifiers) if m_count > 0: show = np.zeros(m_count, dtype=np.bool) ren_set = np.copy(show) ob.modifiers.foreach_get('show_render', show) ob.modifiers.foreach_set('show_render', ren_set) mod = True #v_count = len(mesh.vertices) #normal = np.zeros(v_count * 3)#, dtype=type) mesh.vertices.foreach_get('normal', arr.ravel()) #normal.shape = (v_count, 3) if mod: ob.modifiers.foreach_set('show_render', show)
Example #13
Source File: ModelingCloth.py From Modeling-Cloth with MIT License | 6 votes |
def triangle_bounds_check(tri_co, co_min, co_max, idxer, fudge): """Returns a bool aray indexing the triangles that intersect the bounds of the object""" # min check cull step 1 tri_min = np.min(tri_co, axis=1) - fudge check_min = co_max > tri_min in_min = np.all(check_min, axis=1) # max check cull step 2 idx = idxer[in_min] tri_max = np.max(tri_co[in_min], axis=1) + fudge check_max = tri_max > co_min in_max = np.all(check_max, axis=1) in_min[idx[~in_max]] = False return in_min, tri_min[in_min], tri_max[in_max] # can reuse the min and max
Example #14
Source File: UVShape.py From Modeling-Cloth with MIT License | 6 votes |
def basic_unwrap(): ob = bpy.context.object mode = ob.mode data = ob.data key = ob.active_shape_key_index bpy.ops.object.mode_set(mode='OBJECT') layers = [i.name for i in ob.data.uv_layers] if "UV_Shape_key" not in layers: bpy.ops.mesh.uv_texture_add() ob.data.uv_layers[len(ob.data.uv_layers) - 1].name = 'UV_Shape_key' ob.data.uv_layers.active_index = len(ob.data.uv_layers) - 1 ob.active_shape_key_index = 0 data.vertices.foreach_set('select', np.ones(len(data.vertices), dtype=np.bool)) bpy.ops.object.mode_set(mode='EDIT') bpy.ops.uv.unwrap(method='ANGLE_BASED', margin=0.0635838) bpy.ops.object.mode_set(mode=mode) ob.active_shape_key_index = key
Example #15
Source File: leike_ensslin_2019.py From dustmaps with GNU General Public License v2.0 | 6 votes |
def fetch(clobber=False): """ Downloads the 3D dust map of Leike & Ensslin (2019). Args: clobber (Optional[bool]): If ``True``, any existing file will be overwritten, even if it appears to match. If ``False`` (the default), ``fetch()`` will attempt to determine if the dataset already exists. This determination is not 100\% robust against data corruption. """ dest_dir = fname_pattern = os.path.join(data_dir(), 'leike_ensslin_2019') fname = os.path.join(dest_dir, 'simple_cube.h5') # Check if the FITS table already exists md5sum = 'f54e01c253453117e3770575bed35078' if (not clobber) and fetch_utils.check_md5sum(fname, md5sum): print('File appears to exist already. Call `fetch(clobber=True)` ' 'to force overwriting of existing file.') return # Download from the server url = 'https://zenodo.org/record/2577337/files/simple_cube.h5?download=1' fetch_utils.download_and_verify(url, md5sum, fname)
Example #16
Source File: transformation_tests.py From radiometric_normalization with Apache License 2.0 | 6 votes |
def test_generate_linear_relationship(self): test_candidate = numpy.array( [[1, 2, 3, 4], [1, 3, 4, 4]]) test_reference = numpy.array( [[2, 4, 4, 3], [2, 6, 8, 8]]) test_pifs = numpy.array([[1, 1, 0, 0], [0, 0, 1, 1]], dtype=numpy.bool) transform = transformation.generate_linear_relationship( test_reference, test_candidate, test_pifs) expected_gain = 0.5 self.assertEqual(transform.gain, expected_gain) expected_offset = 0 self.assertEqual(transform.offset, expected_offset)
Example #17
Source File: utils.py From radiometric_normalization with Apache License 2.0 | 6 votes |
def pixel_list_to_array(pixel_locations, shape): ''' Transforms a list of pixel locations into a 2D array. :param tuple pixel_locations: A tuple of two lists representing the x and y coordinates of the locations of a set of pixels (i.e. the output of numpy.nonzero(valid_pixels) where valid_pixels is a 2D boolean array representing the pixel locations) :param list active_pixels: A list the same length as the x and y coordinate lists within pixel_locations representing whether a pixel location should be represented in the mask or not :param tuple shape: The shape of the output array consisting of a tuple of (height, width) :returns: A 2-D boolean array representing active pixels ''' mask = numpy.zeros(shape, dtype=numpy.bool) mask[pixel_locations] = True return mask
Example #18
Source File: gimage.py From radiometric_normalization with Apache License 2.0 | 6 votes |
def read_alpha_and_band_count(gdal_ds, last_band_alpha=False): logging.info('GImage: Initial band count: {}'.format( gdal_ds.RasterCount)) last_band = gdal_ds.GetRasterBand(gdal_ds.RasterCount) if last_band.GetColorInterpretation() == gdal.GCI_AlphaBand: logging.info('GImage: Alpha band found, reducing band count') alpha = last_band.ReadAsArray().astype(numpy.bool) band_count = gdal_ds.RasterCount - 1 elif last_band_alpha: logging.info( 'GImage: Forcing last band to be an alpha band, reducing band ' 'count') alpha = last_band.ReadAsArray().astype(numpy.bool) band_count = gdal_ds.RasterCount - 1 else: logging.info('GImage: No alpha band found') alpha = numpy.ones( (gdal_ds.RasterYSize, gdal_ds.RasterXSize), dtype=numpy.bool) band_count = gdal_ds.RasterCount return alpha, band_count
Example #19
Source File: tedana.py From me-ica with GNU Lesser General Public License v2.1 | 6 votes |
def makeadmask(cdat,min=True,getsum=False): nx,ny,nz,Ne,nt = cdat.shape mask = np.ones((nx,ny,nz),dtype=np.bool) if min: mask = cdat[:,:,:,:,:].prod(axis=-1).prod(-1)!=0 return mask else: #Make a map of longest echo that a voxel can be sampled with, #with minimum value of map as X value of voxel that has median #value in the 1st echo. N.b. larger factor leads to bias to lower TEs emeans = cdat[:,:,:,:,:].mean(-1) medv = emeans[:,:,:,0] == stats.scoreatpercentile(emeans[:,:,:,0][emeans[:,:,:,0]!=0],33,interpolation_method='higher') lthrs = np.squeeze(np.array([ emeans[:,:,:,ee][medv]/3 for ee in range(Ne) ])) if len(lthrs.shape)==1: lthrs = np.atleast_2d(lthrs).T lthrs = lthrs[:,lthrs.sum(0).argmax()] mthr = np.ones([nx,ny,nz,ne]) for ee in range(Ne): mthr[:,:,:,ee]*=lthrs[ee] mthr = np.abs(emeans[:,:,:,:])>mthr masksum = np.array(mthr,dtype=np.int).sum(-1) mask = masksum!=0 if getsum: return mask,masksum else: return mask
Example #20
Source File: input_output_space.py From visual_turing_test-tutorial with MIT License | 6 votes |
def shift_with_index_vector(X, index, size, time_axis, value=1, dtype=np.bool): """ Shifts X along time_axis, and inserts a one-hot vector at the first column at this axis. In: X - n-array index - index for value, the other elements of the corresponding vector are 0 time_axis - axis where shifting happens value - value to place at index; by default 1 dtype - type of the new vector; by default np.bool """ tmp = np.zeros(size, dtype=dtype) tmp[..., index] = value return shift(X, tmp, time_axis)
Example #21
Source File: mp2.py From pyscf with Apache License 2.0 | 6 votes |
def get_frozen_mask(mp): '''Get boolean mask for the restricted reference orbitals. In the returned boolean (mask) array of frozen orbital indices, the element is False if it corresonds to the frozen orbital. ''' moidx = numpy.ones(mp.mo_occ.size, dtype=numpy.bool) if mp._nmo is not None: moidx[mp._nmo:] = False elif mp.frozen is None: pass elif isinstance(mp.frozen, (int, numpy.integer)): moidx[:mp.frozen] = False elif len(mp.frozen) > 0: moidx[list(mp.frozen)] = False else: raise NotImplementedError return moidx
Example #22
Source File: text_proposal_graph_builder.py From ICDAR-2019-SROIE with MIT License | 6 votes |
def build_graph(self, text_proposals, scores, im_size): self.text_proposals = text_proposals self.scores = scores self.im_size = im_size self.heights = text_proposals[:, 3] - text_proposals[:, 1] + 1 boxes_table = [[] for _ in range(self.im_size[1])] for index, box in enumerate(text_proposals): boxes_table[int(box[0])].append(index) self.boxes_table = boxes_table graph = np.zeros((text_proposals.shape[0], text_proposals.shape[0]), np.bool) for index, box in enumerate(text_proposals): successions = self.get_successions(index) if len(successions) == 0: continue succession_index = successions[np.argmax(scores[successions])] if self.is_succession_node(index, succession_index): # NOTE: a box can have multiple successions(precursors) if multiple successions(precursors) # have equal scores. graph[index, succession_index] = True return Graph(graph)
Example #23
Source File: tf_example_decoder_test.py From object_detector_app with MIT License | 6 votes |
def testDecodeObjectDifficult(self): image_tensor = np.random.randint(255, size=(4, 5, 3)).astype(np.uint8) encoded_jpeg = self._EncodeImage(image_tensor) object_difficult = [0, 1] example = tf.train.Example(features=tf.train.Features(feature={ 'image/encoded': self._BytesFeature(encoded_jpeg), 'image/format': self._BytesFeature('jpeg'), 'image/object/difficult': self._Int64Feature(object_difficult), })).SerializeToString() example_decoder = tf_example_decoder.TfExampleDecoder() tensor_dict = example_decoder.Decode(tf.convert_to_tensor(example)) self.assertAllEqual((tensor_dict[ fields.InputDataFields.groundtruth_difficult].get_shape().as_list()), [None]) with self.test_session() as sess: tensor_dict = sess.run(tensor_dict) self.assertAllEqual([bool(item) for item in object_difficult], tensor_dict[ fields.InputDataFields.groundtruth_difficult])
Example #24
Source File: tf_example_decoder_test.py From object_detector_app with MIT License | 6 votes |
def testDecodeObjectIsCrowd(self): image_tensor = np.random.randint(255, size=(4, 5, 3)).astype(np.uint8) encoded_jpeg = self._EncodeImage(image_tensor) object_is_crowd = [0, 1] example = tf.train.Example(features=tf.train.Features(feature={ 'image/encoded': self._BytesFeature(encoded_jpeg), 'image/format': self._BytesFeature('jpeg'), 'image/object/is_crowd': self._Int64Feature(object_is_crowd), })).SerializeToString() example_decoder = tf_example_decoder.TfExampleDecoder() tensor_dict = example_decoder.Decode(tf.convert_to_tensor(example)) self.assertAllEqual((tensor_dict[ fields.InputDataFields.groundtruth_is_crowd].get_shape().as_list()), [None]) with self.test_session() as sess: tensor_dict = sess.run(tensor_dict) self.assertAllEqual([bool(item) for item in object_is_crowd], tensor_dict[ fields.InputDataFields.groundtruth_is_crowd])
Example #25
Source File: ModelingCloth.py From Modeling-Cloth with MIT License | 6 votes |
def tri_back_check(co, tri_min, tri_max, idxer, fudge): """Returns a bool aray indexing the vertices that intersect the bounds of the culled triangles""" # min check cull step 1 tb_min = np.min(tri_min, axis=0) - fudge check_min = co > tb_min in_min = np.all(check_min, axis=1) idx = idxer[in_min] # max check cull step 2 tb_max = np.max(tri_max, axis=0) + fudge check_max = co[in_min] < tb_max in_max = np.all(check_max, axis=1) in_min[idx[~in_max]] = False return in_min # ------------------------------------------------------- # -------------------------------------------------------
Example #26
Source File: kmp2.py From pyscf with Apache License 2.0 | 5 votes |
def get_frozen_mask(mp): '''Boolean mask for orbitals in k-point post-HF method. Creates a boolean mask to remove frozen orbitals and keep other orbitals for post-HF calculations. Args: mp (:class:`MP2`): An instantiation of an SCF or post-Hartree-Fock object. Returns: moidx (list of :obj:`ndarray` of `np.bool`): Boolean mask of orbitals to include. ''' moidx = [np.ones(x.size, dtype=np.bool) for x in mp.mo_occ] if mp.frozen is None: pass elif isinstance(mp.frozen, (int, np.integer)): for idx in moidx: idx[:mp.frozen] = False elif isinstance(mp.frozen[0], (int, np.integer)): frozen = list(mp.frozen) for idx in moidx: idx[frozen] = False elif isinstance(mp.frozen[0], (list, np.ndarray)): nkpts = len(mp.frozen) if nkpts != mp.nkpts: raise RuntimeError('Frozen list has a different number of k-points (length) than passed in mean-field/' 'correlated calculation. \n\nCalculation nkpts = %d, frozen list = %s ' '(length = %d)' % (mp.nkpts, mp.frozen, nkpts)) [_frozen_sanity_check(fro, mo_occ, ikpt) for ikpt, fro, mo_occ in zip(range(nkpts), mp.frozen, mp.mo_occ)] for ikpt, kpt_occ in enumerate(moidx): kpt_occ[mp.frozen[ikpt]] = False else: raise NotImplementedError return moidx
Example #27
Source File: mAP.py From iAI with MIT License | 5 votes |
def extract_class_detetions(voc_detections, classname, image_numbers): class_detections = {} for image_num in image_numbers: R = [obj for obj in voc_detections[image_num] if obj['name'] == classname] image_bboxes = [x['bbox'] for x in R] # Transform VOC bboxes to make them describe pre-resized 300x300 images for idx, bbox in enumerate(image_bboxes): bbox = np.array(bbox).astype(np.float32) width = float(R[0]['image_width']) height = float(R[0]['image_height']) bbox[0] *= (300.0 / width) bbox[2] *= (300.0 / width) bbox[1] *= (300.0 / height) bbox[3] *= (300.0 / height) image_bboxes[idx] = bbox image_bboxes = np.array(image_bboxes) difficult = np.array([x['difficult'] for x in R]).astype(np.bool) det = [False] * len(R) class_detections[image_num] = { 'bbox': image_bboxes, 'difficult': difficult, 'det': det } return class_detections
Example #28
Source File: mAP.py From iAI with MIT License | 5 votes |
def extract_class_detetions(voc_detections, classname, image_numbers): class_detections = {} for image_num in image_numbers: R = [obj for obj in voc_detections[image_num] if obj['name'] == classname] image_bboxes = [x['bbox'] for x in R] # Transform VOC bboxes to make them describe pre-resized 300x300 images for idx, bbox in enumerate(image_bboxes): bbox = np.array(bbox).astype(np.float32) width = float(R[0]['image_width']) height = float(R[0]['image_height']) bbox[0] *= (300.0 / width) bbox[2] *= (300.0 / width) bbox[1] *= (300.0 / height) bbox[3] *= (300.0 / height) image_bboxes[idx] = bbox image_bboxes = np.array(image_bboxes) difficult = np.array([x['difficult'] for x in R]).astype(np.bool) det = [False] * len(R) class_detections[image_num] = { 'bbox': image_bboxes, 'difficult': difficult, 'det': det } return class_detections
Example #29
Source File: core.py From neuropythy with GNU Affero General Public License v3.0 | 5 votes |
def dataframe_except(df, *cols, **filters): ''' dataframe_except(df, k1=v1, k2=v2...) yields df after selecting all the columns in which the given keys (k1, k2, etc.) have been selected such that the associated columns in the dataframe contain only the rows whose cells match the given values. dataframe_except(df, col1, col2...) selects all columns except for the given columns. dataframe_except(df, col1, col2..., k1=v1, k2=v2...) selects on both conditions. The dataframe_except() function is identical to the dataframe_select() function with the single difference being that the column names provided to dataframe_except() are dropped from the result while column names passed to dataframe_select() are kept. If a value is a tuple/list of 2 elements, then it is considered a range where cells must fall between the values. If value is a tuple/list of more than 2 elements or is a set of any length then it is a list of values, any one of which can match the cell. ''' ii = np.ones(len(df), dtype='bool') for (k,v) in six.iteritems(filters): vals = df[k].values if pimms.is_set(v): jj = np.isin(vals, list(v)) elif pimms.is_vector(v) and len(v) == 2: jj = (v[0] <= vals) & (vals < v[1]) elif pimms.is_vector(v): jj = np.isin(vals, list(v)) else: jj = (vals == v) ii = np.logical_and(ii, jj) if len(ii) != np.sum(ii): df = df.loc[ii] if len(cols) > 0: df = df.drop(list(cols), axis=1, inplace=False) return df
Example #30
Source File: usage_ga_custom.py From pymoo with Apache License 2.0 | 5 votes |
def _do(self, problem, n_samples, **kwargs): X = np.full((n_samples, problem.n_var), False, dtype=np.bool) for k in range(n_samples): I = np.random.permutation(problem.n_var)[:problem.n_max] X[k, I] = True return X