def api_ofrecord_image_decoder_random_crop( input_blob: BlobDef, blob_name: str, color_space: str = "BGR", num_attempts: int = 10, seed: Optional[int] = None, random_area: Sequence[float] = [0.08, 1.0], random_aspect_ratio: Sequence[float] = [0.75, 1.333333], name: str = "OFRecordImageDecoderRandomCrop", ) -> BlobDef: assert isinstance(name, str) if seed is not None: assert name is not None module = flow.find_or_create_module( name, lambda: OFRecordImageDecoderRandomCropModule( blob_name=blob_name, color_space=color_space, num_attempts=num_attempts, random_seed=seed, random_area=random_area, random_aspect_ratio=random_aspect_ratio, name=name, ), ) return module(input_blob)
def api_image_random_crop( input_blob: BlobDef, num_attempts: int = 10, seed: Optional[int] = None, random_area: Sequence[float] = None, random_aspect_ratio: Sequence[float] = None, name: str = "ImageRandomCrop", ) -> BlobDef: assert isinstance(name, str) if seed is not None: assert name is not None if random_area is None: random_area = [0.08, 1.0] if random_aspect_ratio is None: random_aspect_ratio = [0.75, 1.333333] module = flow.find_or_create_module( name, lambda: ImageRandomCropModule( num_attempts=num_attempts, random_seed=seed, random_area=random_area, random_aspect_ratio=random_aspect_ratio, name=name, ), ) return module(input_blob)
def api_coco_reader( annotation_file: str, image_dir: str, batch_size: int, shuffle: bool = True, random_seed: Optional[int] = None, group_by_aspect_ratio: bool = True, stride_partition: bool = True, name: str = None, ) -> BlobDef: assert name is not None module = flow.find_or_create_module( name, lambda: COCOReader( annotation_file=annotation_file, image_dir=image_dir, batch_size=batch_size, shuffle=shuffle, random_seed=random_seed, group_by_aspect_ratio=group_by_aspect_ratio, stride_partition=stride_partition, name=name, ), ) return module()
def Bernoulli( x: remote_blob_util.BlobDef, seed: Optional[int] = None, dtype: Optional[dtype_util.dtype] = None, name: str = "Bernoulli", ) -> remote_blob_util.BlobDef: """This operator returns a Blob with binaray random numbers (0 / 1) from a Bernoulli distribution. Args: x (remote_blob_util.BlobDef): The input Blob. seed (Optional[int], optional): The random seed. Defaults to None. dtype (Optional[dtype_util.dtype], optional): The data type. Defaults to None. name (str, optional): The name for the operation. Defaults to "Bernoulli". Returns: remote_blob_util.BlobDef: The result Blob. For example: .. code-block:: python import oneflow as flow import numpy as np import oneflow.typing as tp @flow.global_function() def bernoulli_Job(x: tp.Numpy.Placeholder(shape=(3, 3), dtype=flow.float32), ) -> tp.Numpy: out = flow.random.bernoulli(x) return out x = np.array([[0.25, 0.45, 0.3], [0.55, 0.32, 0.13], [0.75, 0.15, 0.1]]).astype(np.float32) out = bernoulli_Job(x) # Because our random seed is not fixed, so the return value is different each time. # out [[1. 0. 0.] # [0. 0. 1.] # [0. 0. 0.]] """ assert isinstance(name, str) if dtype is None: dtype = x.dtype if seed is not None: assert name is not None module = flow.find_or_create_module( name, lambda: BernoulliModule(dtype=dtype, random_seed=seed, name=name), ) return module(x)
def AddJob(x: oft.Numpy.Placeholder(shape=x_shape), y: oft.Numpy.Placeholder(shape=y_shape)) -> oft.Numpy: with flow.scope.namespace("AddJob"): add_op = flow.find_or_create_module("Add", Add) z = add_op(x, y) # print(z.logical_blob_name) test_case.assertTrue( z.op_name == "AddJob-Add_{}".format(add_op.call_seq_no - 1)) v = add_op(z, x) # print(v.logical_blob_name) test_case.assertTrue( v.op_name == "AddJob-Add_{}".format(add_op.call_seq_no - 1)) return z
def api_coin_flip( batch_size: int = 1, seed: Optional[int] = None, probability: float = 0.5, name: str = "CoinFlip", ) -> BlobDef: assert isinstance(name, str) if seed is not None: assert name is not None module = flow.find_or_create_module( name, lambda: CoinFlipModule( batch_size=batch_size, probability=probability, random_seed=seed, name=name, ), ) return module()
def Bernoulli( x: remote_blob_util.BlobDef, seed: Optional[int] = None, dtype: Optional[dtype_util.dtype] = None, name: str = "Bernoulli", ) -> remote_blob_util.BlobDef: assert isinstance(name, str) if dtype is None: dtype = x.dtype if seed is not None: assert name is not None module = flow.find_or_create_module( name, lambda: BernoulliModule(dtype=dtype, random_seed=seed, name=name), ) return module(x)
def AddJob(xs: Tuple[(oft.Numpy.Placeholder((5, 2)), ) * 2]): adder = flow.find_or_create_module("Add", Add, reuse=True) adder = flow.find_or_create_module("Add", Add, reuse=True) x = adder(*xs) return adder(x, x)