当前位置: 首页>>代码示例>>Python>>正文


Python utils.Sequence方法代码示例

本文整理汇总了Python中tensorflow.keras.utils.Sequence方法的典型用法代码示例。如果您正苦于以下问题:Python utils.Sequence方法的具体用法?Python utils.Sequence怎么用?Python utils.Sequence使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tensorflow.keras.utils的用法示例。


在下文中一共展示了utils.Sequence方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from tensorflow.keras import utils [as 别名]
# 或者: from tensorflow.keras.utils import Sequence [as 别名]
def __init__(self, annotation_lines, batch_size, input_shape, anchors, num_classes, enhance_augment=None, rescale_interval=-1, shuffle=True):
        self.annotation_lines = annotation_lines
        self.batch_size = batch_size
        self.input_shape = input_shape
        self.anchors = anchors
        self.num_classes = num_classes
        self.enhance_augment = enhance_augment
        self.indexes = np.arange(len(self.annotation_lines))
        self.shuffle = shuffle
        # prepare multiscale config
        # TODO: error happens when using Sequence data generator with
        #       multiscale input shape, disable multiscale first
        if rescale_interval != -1:
            raise ValueError("tf.keras.Sequence generator doesn't support multiscale input, pls remove related config")
        #self.rescale_interval = rescale_interval
        self.rescale_interval = -1

        self.rescale_step = 0
        self.input_shape_list = get_multiscale_list() 
开发者ID:david8862,项目名称:keras-YOLOv3-model-set,代码行数:21,代码来源:data.py

示例2: seed

# 需要导入模块: from tensorflow.keras import utils [as 别名]
# 或者: from tensorflow.keras.utils import Sequence [as 别名]
def seed(self):
        """
        If multiprocessing, the processes will inherit the RNG state of the
        main process - here we reseed each process once so that the batches
        are randomly generated across multi-processes calls to the Sequence
        batch generator methods

        If multi-threading this method will just re-seed the 'MainProcess'
        process once
        """
        pname = current_process().name
        if pname not in self.is_seeded or not self.is_seeded[pname]:
            # Re-seed this process
            np.random.seed()
            self.is_seeded[pname] = True 
开发者ID:perslev,项目名称:U-Time,代码行数:17,代码来源:base_sequence.py

示例3: _assert_scaled

# 需要导入模块: from tensorflow.keras import utils [as 别名]
# 或者: from tensorflow.keras.utils import Sequence [as 别名]
def _assert_scaled(self, warn_mean=5, warn_std=5, n_batches=5):
        """
        Samples n_batches random batches from the sub-class Sequencer object
        and computes the mean and STD of the values across the batches. If
        their absolute values are higher than 'warn_mean' and 'warn_std'
        respectively, a warning is printed.

        Note: Does not raise an Error or Warning

        Args:
            warn_mean: Maximum allowed abs(mean) before warning is invoked
            warn_std:  Maximum allowed std before warning is invoked
            n_batches: Number of batches to sample for mean/std computation
        """
        # Get a set of random batches
        batches = []
        for ind in np.random.randint(0, len(self), n_batches):
            X, _ = self[ind]  # Use __getitem__ of the given Sequence class
            batches.append(X)
        mean, std = np.abs(np.mean(batches)), np.std(batches)
        self.logger("Mean assertion ({} batches):  {:.3f}".format(n_batches,
                                                                  mean))
        self.logger("Scale assertion ({} batches): {:.3f}".format(n_batches,
                                                                  std))
        if mean > warn_mean or std > warn_std:
            self.logger.warn("OBS: Found large abs(mean) and std values over 5"
                             " sampled batches ({:.3f} and {:.3f})."
                             " Make sure scaling is active at either the "
                             "global level (attribute 'scaler' has been set on"
                             " individual SleepStudy objects, typically via the"
                             " SleepStudyDataset set_scaler method), or "
                             "batch-wise via the batch_scaler attribute of the"
                             " Sequence object.".format(mean, std)) 
开发者ID:perslev,项目名称:U-Time,代码行数:35,代码来源:base_sequence.py

示例4: __len__

# 需要导入模块: from tensorflow.keras import utils [as 别名]
# 或者: from tensorflow.keras.utils import Sequence [as 别名]
def __len__(self):
        """Number of batch in the Sequence.

        Returns:
            The number of batches in the Sequence.
        """
        return sum([len(seq) for seq in self.sequencers]) 
开发者ID:perslev,项目名称:MultiPlanarUNet,代码行数:9,代码来源:multi_task_sequence.py

示例5: setUpClass

# 需要导入模块: from tensorflow.keras import utils [as 别名]
# 或者: from tensorflow.keras.utils import Sequence [as 别名]
def setUpClass(cls):
        cls.n_feature = 3
        cls.n_bond_features = 10
        cls.n_global_features = 2

        class Generator(Sequence):
            def __init__(self, x, y):
                self.x = x
                self.y = y
            def __len__(self):
                return 10
            def __getitem__(self, index):
                return  self.x, self.y

        x_crystal = [np.array([1, 2, 3, 4]).reshape((1, -1)),
                     np.random.normal(size=(1, 6, cls.n_bond_features)),
                     np.random.normal(size=(1, 2, cls.n_global_features)),
                     np.array([[0, 0, 1, 1, 2, 3]]),
                     np.array([[1, 1, 0, 0, 3, 2]]),
                     np.array([[0, 0, 1, 1]]),
                     np.array([[0, 0, 0, 0, 1, 1]]),
                     ]

        y = np.random.normal(size=(1, 2, 1))
        cls.train_gen_crystal = Generator(x_crystal, y)
        x_mol = [np.random.normal(size=(1, 4, cls.n_feature)),
                 np.random.normal(size=(1, 6, cls.n_bond_features)),
                 np.random.normal(size=(1, 2, cls.n_global_features)),
                 np.array([[0, 0, 1, 1, 2, 3]]),
                 np.array([[1, 1, 0, 0, 3, 2]]),
                 np.array([[0, 0, 1, 1]]),
                 np.array([[0, 0, 0, 0, 1, 1]]),
                 ]
        y = np.random.normal(size=(1, 2, 1))
        cls.train_gen_mol = Generator(x_mol, y)

        cls.model = MEGNetModel(10, 2, nblocks=1, lr=1e-2,
                                n1=4, n2=4, n3=4, npass=1, ntarget=1,
                                graph_converter=CrystalGraph(bond_converter=GaussianDistance(np.linspace(0, 5, 10), 0.5)),
                                )
        cls.model2 = MEGNetModel(10, 2, nblocks=1, lr=1e-2,
                                 n1=4, n2=4, n3=4, npass=1, ntarget=2,
                                 graph_converter=CrystalGraph(bond_converter=GaussianDistance(np.linspace(0, 5, 10), 0.5)),
                                 ) 
开发者ID:materialsvirtuallab,项目名称:megnet,代码行数:46,代码来源:test_models.py


注:本文中的tensorflow.keras.utils.Sequence方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。