' else self.name
+ graph_ctx = tf_utils.graph_context_for_symbolic_tensors(
+ y_true, y_pred, sample_weight)
+ with K.name_scope(scope_name or self.__class__.__name__), graph_ctx:
+ losses = self.call(y_true, y_pred)
+ return losses_utils.compute_weighted_loss(
+ losses, sample_weight, reduction=self._get_reduction())
+
+ @classmethod
+ def from_config(cls, config):
+ """Instantiates a `Loss` from its config (output of `get_config()`).
+
+ Args:
+ config: Output of `get_config()`.
+
+ Returns:
+ A `Loss` instance.
+ """
+ return cls(**config)
+
+ def get_config(self):
+ return {'reduction': self.reduction, 'name': self.name}
+
+ @abc.abstractmethod
+ @doc_controls.for_subclass_implementers
+ def call(self, y_true, y_pred):
+ """Invokes the `Loss` instance.
+
+ Args:
+ y_true: Ground truth values, with the same shape as 'y_pred'.
+ y_pred: The predicted values.
+ """
+ NotImplementedError('Must be implemented in subclasses.')
+
+ def _get_reduction(self):
+ """Handles `AUTO` reduction cases and returns the reduction value."""
+ if distribution_strategy_context.has_strategy() and (
+ self.reduction == losses_utils.ReductionV2.AUTO or
+ self.reduction == losses_utils.ReductionV2.SUM_OVER_BATCH_SIZE):
+ raise ValueError(
+ 'Please use `tf.keras.losses.Reduction.SUM` or '
+ '`tf.keras.losses.Reduction.NONE` for loss reduction when losses are '
+ 'used with `tf.distribute.Strategy` outside of the built-in training '
+ 'loops. You can implement '
+ '`tf.keras.losses.Reduction.SUM_OVER_BATCH_SIZE` using global batch '
+ 'size like:\n```\nwith strategy.scope():\n'
+ ' loss_obj = tf.keras.losses.CategoricalCrossentropy('
+ 'reduction=tf.keras.losses.reduction.NONE)\n....\n'
+ ' loss = tf.reduce_sum(loss_obj(labels, predictions)) * '
+ '(1. / global_batch_size)\n```\nPlease see '
+ 'https://www.tensorflow.org/alpha/tutorials/distribute/training_loops'
+ ' for more details.')
+
+ if self.reduction == losses_utils.ReductionV2.AUTO:
+ return losses_utils.ReductionV2.SUM_OVER_BATCH_SIZE
+ return self.reduction
+
+
+class LossFunctionWrapper(Loss):
+ """Wraps a loss function in the `Loss` class.
+
+ Args:
+ fn: The loss function to wrap, with signature `fn(y_true, y_pred,
+ **kwargs)`.
+ reduction: (Optional) Type of `tf.keras.losses.Reduction` to apply to loss.
+ Default value is `AUTO`. `AUTO` indicates that the reduction option will
+ be determined by the usage context. For almost all cases this defaults to
+ `SUM_OVER_BATCH_SIZE`.
+ When used with `tf.distribute.Strategy`, outside of built-in training
+ loops such as `tf.keras` `compile` and `fit`, using `AUTO` or
+ `SUM_OVER_BATCH_SIZE` will raise an error. Please see
+ https://www.tensorflow.org/alpha/tutorials/distribute/training_loops
+ for more details on this.
+ name: (Optional) name for the loss.
+ **kwargs: The keyword arguments that are passed on to `fn`.
+ """
+
+ def __init__(self,
+ fn,
+ reduction=losses_utils.ReductionV2.AUTO,
+ name=None,
+ **kwargs):
+ super(LossFunctionWrapper, self).__init__(reduction=reduction, name=name)
+ self.fn = fn
+ self._fn_kwargs = kwargs
+
+ def call(self, y_true, y_pred):
+ """Invokes the `LossFunctionWrapper` instance.
+
+ Args:
+ y_true: Ground truth values.
+ y_pred: The predicted values.
+
+ Returns:
+ Loss values per sample.
+ """
+ if tensor_util.is_tensor(y_pred) and tensor_util.is_tensor(y_true):
+ y_pred, y_true = tf_losses_util.squeeze_or_expand_dimensions(
+ y_pred, y_true)
+ return self.fn(y_true, y_pred, **self._fn_kwargs)
+
+ def get_config(self):
+ config = {}
+ for k, v in six.iteritems(self._fn_kwargs):
+ config[k] = K.eval(v) if tf_utils.is_tensor_or_variable(v) else v
+ base_config = super(LossFunctionWrapper, self).get_config()
+ return dict(list(base_config.items()) + list(config.items()))
+
+
+@keras_export('keras.losses.MeanSquaredError')
+class MeanSquaredError(LossFunctionWrapper):
+ """Computes the mean of squares of errors between labels and predictions.
+
+ `loss = square(y_true - y_pred)`
+
+ Usage:
+
+ ```python
+ mse = tf.keras.losses.MeanSquaredError()
+ loss = mse([0., 0., 1., 1.], [1., 1., 1., 0.])
+ print('Loss: ', loss.numpy()) # Loss: 0.75
+ ```
+
+ Usage with the `compile` API:
+
+ ```python
+ model = tf.keras.Model(inputs, outputs)
+ model.compile('sgd', loss=tf.keras.losses.MeanSquaredError())
+ ```
+ """
+
+ def __init__(self,
+ reduction=losses_utils.ReductionV2.AUTO,
+ name='mean_squared_error'):
+ super(MeanSquaredError, self).__init__(
+ mean_squared_error, name=name, reduction=reduction)
+
+
+@keras_export('keras.losses.MeanAbsoluteError')
+class MeanAbsoluteError(LossFunctionWrapper):
+ """Computes the mean of absolute difference between labels and predictions.
+
+ `loss = abs(y_true - y_pred)`
+
+ Usage:
+
+ ```python
+ mae = tf.keras.losses.MeanAbsoluteError()
+ loss = mae([0., 0., 1., 1.], [1., 1., 1., 0.])
+ print('Loss: ', loss.numpy()) # Loss: 0.75
+ ```
+
+ Usage with the `compile` API:
+
+ ```python
+ model = tf.keras.Model(inputs, outputs)
+ model.compile('sgd', loss=tf.keras.losses.MeanAbsoluteError())
+ ```
+ """
+
+ def __init__(self,
+ reduction=losses_utils.ReductionV2.AUTO,
+ name='mean_absolute_error'):
+ super(MeanAbsoluteError, self).__init__(
+ mean_absolute_error, name=name, reduction=reduction)
+
+
+@keras_export('keras.losses.MeanAbsolutePercentageError')
+class MeanAbsolutePercentageError(LossFunctionWrapper):
+ """Computes the mean absolute percentage error between `y_true` and `y_pred`.
+
+ `loss = 100 * abs(y_true - y_pred) / y_true`
+
+ Usage:
+
+ ```python
+ mape = tf.keras.losses.MeanAbsolutePercentageError()
+ loss = mape([0., 0., 1., 1.], [1., 1., 1., 0.])
+ print('Loss: ', loss.numpy()) # Loss: 5e+08
+ ```
+
+ Usage with the `compile` API:
+
+ ```python
+ model = tf.keras.Model(inputs, outputs)
+ model.compile('sgd', loss=tf.keras.losses.MeanAbsolutePercentageError())
+ ```
+ """
+
+ def __init__(self,
+ reduction=losses_utils.ReductionV2.AUTO,
+ name='mean_absolute_percentage_error'):
+ super(MeanAbsolutePercentageError, self).__init__(
+ mean_absolute_percentage_error, name=name, reduction=reduction)
+
+
+@keras_export('keras.losses.MeanSquaredLogarithmicError')
+class MeanSquaredLogarithmicError(LossFunctionWrapper):
+ """Computes the mean squared logarithmic error between `y_true` and `y_pred`.
+
+ `loss = square(log(y_true) - log(y_pred))`
+
+ Usage:
+
+ ```python
+ msle = tf.keras.losses.MeanSquaredLogarithmicError()
+ loss = msle([0., 0., 1., 1.], [1., 1., 1., 0.])
+ print('Loss: ', loss.numpy()) # Loss: 0.36034
+ ```
+
+ Usage with the `compile` API:
+
+ ```python
+ model = tf.keras.Model(inputs, outputs)
+ model.compile('sgd', loss=tf.keras.losses.MeanSquaredLogarithmicError())
+ ```
+ """
+
+ def __init__(self,
+ reduction=losses_utils.ReductionV2.AUTO,
+ name='mean_squared_logarithmic_error'):
+ super(MeanSquaredLogarithmicError, self).__init__(
+ mean_squared_logarithmic_error, name=name, reduction=reduction)
+
+
+@keras_export('keras.losses.BinaryCrossentropy')
+class BinaryCrossentropy(LossFunctionWrapper):
+ """Computes the cross-entropy loss between true labels and predicted labels.
+
+ Use this cross-entropy loss when there are only two label classes (assumed to
+ be 0 and 1). For each example, there should be a single floating-point value
+ per prediction.
+
+ In the snippet below, each of the four examples has only a single
+ floating-pointing value, and both `y_pred` and `y_true` have the shape
+ `[batch_size]`.
+
+ Usage:
+
+ ```python
+ bce = tf.keras.losses.BinaryCrossentropy()
+ loss = bce([0., 0., 1., 1.], [1., 1., 1., 0.])
+ print('Loss: ', loss.numpy()) # Loss: 11.522857
+ ```
+
+ Usage with the `tf.keras` API:
+
+ ```python
+ model = tf.keras.Model(inputs, outputs)
+ model.compile('sgd', loss=tf.keras.losses.BinaryCrossentropy())
+ ```
+
+ Args:
+ from_logits: Whether to interpret `y_pred` as a tensor of
+ [logit](https://en.wikipedia.org/wiki/Logit) values. By default, we assume
+ that `y_pred` contains probabilities (i.e., values in [0, 1]).
+ Note: Using from_logits=True may be more numerically stable.
+ label_smoothing: Float in [0, 1]. When 0, no smoothing occurs. When > 0, we
+ compute the loss between the predicted labels and a smoothed version of
+ the true labels, where the smoothing squeezes the labels towards 0.5.
+ Larger values of `label_smoothing` correspond to heavier smoothing.
+ reduction: (Optional) Type of `tf.keras.losses.Reduction` to apply to loss.
+ Default value is `AUTO`. `AUTO` indicates that the reduction option will
+ be determined by the usage context. For almost all cases this defaults to
+ `SUM_OVER_BATCH_SIZE`.
+ When used with `tf.distribute.Strategy`, outside of built-in training
+ loops such as `tf.keras` `compile` and `fit`, using `AUTO` or
+ `SUM_OVER_BATCH_SIZE` will raise an error. Please see
+ https://www.tensorflow.org/alpha/tutorials/distribute/training_loops
+ for more details on this.
+ name: (Optional) Name for the op.
+ """
+
+ def __init__(self,
+ from_logits=False,
+ label_smoothing=0,
+ reduction=losses_utils.ReductionV2.AUTO,
+ name='binary_crossentropy'):
+ super(BinaryCrossentropy, self).__init__(
+ binary_crossentropy,
+ name=name,
+ reduction=reduction,
+ from_logits=from_logits,
+ label_smoothing=label_smoothing)
+ self.from_logits = from_logits
+
+
+@keras_export('keras.losses.CategoricalCrossentropy')
+class CategoricalCrossentropy(LossFunctionWrapper):
+ """Computes the crossentropy loss between the labels and predictions.
+
+ Use this crossentropy loss function when there are two or more label classes.
+ We expect labels to be provided in a `one_hot` representation. If you want to
+ provide labels as integers, please use `SparseCategoricalCrossentropy` loss.
+ There should be `# classes` floating point values per feature.
+
+ In the snippet below, there is `# classes` floating pointing values per
+ example. The shape of both `y_pred` and `y_true` are
+ `[batch_size, num_classes]`.
+
+ Usage:
+
+ ```python
+ cce = tf.keras.losses.CategoricalCrossentropy()
+ loss = cce(
+ [[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]],
+ [[.9, .05, .05], [.05, .89, .06], [.05, .01, .94]])
+ print('Loss: ', loss.numpy()) # Loss: 0.0945
+ ```
+
+ Usage with the `compile` API:
+
+ ```python
+ model = tf.keras.Model(inputs, outputs)
+ model.compile('sgd', loss=tf.keras.losses.CategoricalCrossentropy())
+ ```
+
+ Args:
+ from_logits: Whether `y_pred` is expected to be a logits tensor. By default,
+ we assume that `y_pred` encodes a probability distribution.
+ Note: Using from_logits=True may be more numerically stable.
+ label_smoothing: Float in [0, 1]. When > 0, label values are smoothed,
+ meaning the confidence on label values are relaxed. e.g.
+ `label_smoothing=0.2` means that we will use a value of `0.1` for label
+ `0` and `0.9` for label `1`"
+ reduction: (Optional) Type of `tf.keras.losses.Reduction` to apply to loss.
+ Default value is `AUTO`. `AUTO` indicates that the reduction option will
+ be determined by the usage context. For almost all cases this defaults to
+ `SUM_OVER_BATCH_SIZE`.
+ When used with `tf.distribute.Strategy`, outside of built-in training
+ loops such as `tf.keras` `compile` and `fit`, using `AUTO` or
+ `SUM_OVER_BATCH_SIZE` will raise an error. Please see
+ https://www.tensorflow.org/alpha/tutorials/distribute/training_loops
+ for more details on this.
+ name: Optional name for the op.
+ """
+
+ def __init__(self,
+ from_logits=False,
+ label_smoothing=0,
+ reduction=losses_utils.ReductionV2.AUTO,
+ name='categorical_crossentropy'):
+ super(CategoricalCrossentropy, self).__init__(
+ categorical_crossentropy,
+ name=name,
+ reduction=reduction,
+ from_logits=from_logits,
+ label_smoothing=label_smoothing)
+
+
+@keras_export('keras.losses.SparseCategoricalCrossentropy')
+class SparseCategoricalCrossentropy(LossFunctionWrapper):
+ """Computes the crossentropy loss between the labels and predictions.
+
+ Use this crossentropy loss function when there are two or more label classes.
+ We expect labels to be provided as integers. If you want to provide labels
+ using `one-hot` representation, please use `CategoricalCrossentropy` loss.
+ There should be `# classes` floating point values per feature for `y_pred`
+ and a single floating point value per feature for `y_true`.
+
+ In the snippet below, there is a single floating point value per example for
+ `y_true` and `# classes` floating pointing values per example for `y_pred`.
+ The shape of `y_true` is `[batch_size]` and the shape of `y_pred` is
+ `[batch_size, num_classes]`.
+
+ Usage:
+
+ ```python
+ cce = tf.keras.losses.SparseCategoricalCrossentropy()
+ loss = cce(
+ [0, 1, 2],
+ [[.9, .05, .05], [.5, .89, .6], [.05, .01, .94]])
+ print('Loss: ', loss.numpy()) # Loss: 0.3239
+ ```
+
+ Usage with the `compile` API:
+
+ ```python
+ model = tf.keras.Model(inputs, outputs)
+ model.compile('sgd', loss=tf.keras.losses.SparseCategoricalCrossentropy())
+ ```
+
+ Args:
+ from_logits: Whether `y_pred` is expected to be a logits tensor. By default,
+ we assume that `y_pred` encodes a probability distribution.
+ Note: Using from_logits=True may be more numerically stable.
+ reduction: (Optional) Type of `tf.keras.losses.Reduction` to apply to loss.
+ Default value is `AUTO`. `AUTO` indicates that the reduction option will
+ be determined by the usage context. For almost all cases this defaults to
+ `SUM_OVER_BATCH_SIZE`.
+ When used with `tf.distribute.Strategy`, outside of built-in training
+ loops such as `tf.keras` `compile` and `fit`, using `AUTO` or
+ `SUM_OVER_BATCH_SIZE` will raise an error. Please see
+ https://www.tensorflow.org/alpha/tutorials/distribute/training_loops
+ for more details on this.
+ name: Optional name for the op.
+ """
+
+ def __init__(self,
+ from_logits=False,
+ reduction=losses_utils.ReductionV2.AUTO,
+ name='sparse_categorical_crossentropy'):
+ super(SparseCategoricalCrossentropy, self).__init__(
+ sparse_categorical_crossentropy,
+ name=name,
+ reduction=reduction,
+ from_logits=from_logits)
+
+
+@keras_export('keras.losses.Hinge')
+class Hinge(LossFunctionWrapper):
+ """Computes the hinge loss between `y_true` and `y_pred`.
+
+ `loss = maximum(1 - y_true * y_pred, 0)`
+
+ `y_true` values are expected to be -1 or 1. If binary (0 or 1) labels are
+ provided we will convert them to -1 or 1.
+
+ Usage:
+
+ ```python
+ h = tf.keras.losses.Hinge()
+ loss = h([-1., 1., 1.], [0.6, -0.7, -0.5])
+
+ # loss = max(0, 1 - y_true * y_pred) = [1.6 + 1.7 + 1.5] / 3
+
+ print('Loss: ', loss.numpy()) # Loss: 1.6
+ ```
+
+ Usage with the `compile` API:
+
+ ```python
+ model = tf.keras.Model(inputs, outputs)
+ model.compile('sgd', loss=tf.keras.losses.Hinge())
+ ```
+ """
+
+ def __init__(self, reduction=losses_utils.ReductionV2.AUTO, name='hinge'):
+ super(Hinge, self).__init__(hinge, name=name, reduction=reduction)
+
+
+@keras_export('keras.losses.SquaredHinge')
+class SquaredHinge(LossFunctionWrapper):
+ """Computes the squared hinge loss between `y_true` and `y_pred`.
+
+ `loss = square(maximum(1 - y_true * y_pred, 0))`
+
+ `y_true` values are expected to be -1 or 1. If binary (0 or 1) labels are
+ provided we will convert them to -1 or 1.
+
+ Usage:
+
+ ```python
+ sh = tf.keras.losses.SquaredHinge()
+ loss = sh([-1., 1., 1.], [0.6, -0.7, -0.5])
+
+ # loss = (max(0, 1 - y_true * y_pred))^2 = [1.6^2 + 1.7^2 + 1.5^2] / 3
+
+ print('Loss: ', loss.numpy()) # Loss: 2.566666
+ ```
+
+ Usage with the `compile` API:
+
+ ```python
+ model = tf.keras.Model(inputs, outputs)
+ model.compile('sgd', loss=tf.keras.losses.SquaredHinge())
+ ```
+ """
+
+ def __init__(self,
+ reduction=losses_utils.ReductionV2.AUTO,
+ name='squared_hinge'):
+ super(SquaredHinge, self).__init__(
+ squared_hinge, name=name, reduction=reduction)
+
+
+@keras_export('keras.losses.CategoricalHinge')
+class CategoricalHinge(LossFunctionWrapper):
+ """Computes the categorical hinge loss between `y_true` and `y_pred`.
+
+ `loss = maximum(neg - pos + 1, 0)`
+ where `neg = sum(y_true * y_pred)` and `pos = maximum(1 - y_true)`
+
+ Usage:
+
+ ```python
+ ch = tf.keras.losses.CategoricalHinge()
+ loss = ch([0., 1., 1.], [1., 0., 1.])
+ print('Loss: ', loss.numpy()) # Loss: 1.0
+ ```
+
+ Usage with the `compile` API:
+
+ ```python
+ model = tf.keras.Model(inputs, outputs)
+ model.compile('sgd', loss=tf.keras.losses.CategoricalHinge())
+ ```
+ """
+
+ def __init__(self,
+ reduction=losses_utils.ReductionV2.AUTO,
+ name='categorical_hinge'):
+ super(CategoricalHinge, self).__init__(
+ categorical_hinge, name=name, reduction=reduction)
+
+
+@keras_export('keras.losses.Poisson')
+class Poisson(LossFunctionWrapper):
+ """Computes the Poisson loss between `y_true` and `y_pred`.
+
+ `loss = y_pred - y_true * log(y_pred)`
+
+ Usage:
+
+ ```python
+ p = tf.keras.losses.Poisson()
+ loss = p([1., 9., 2.], [4., 8., 12.])
+ print('Loss: ', loss.numpy()) # Loss: -0.35702705
+ ```
+
+ Usage with the `compile` API:
+
+ ```python
+ model = tf.keras.Model(inputs, outputs)
+ model.compile('sgd', loss=tf.keras.losses.Poisson())
+ ```
+ """
+
+ def __init__(self, reduction=losses_utils.ReductionV2.AUTO, name='poisson'):
+ super(Poisson, self).__init__(poisson, name=name, reduction=reduction)
+
+
+@keras_export('keras.losses.LogCosh')
+class LogCosh(LossFunctionWrapper):
+ """Computes the logarithm of the hyperbolic cosine of the prediction error.
+
+ `logcosh = log((exp(x) + exp(-x))/2)`,
+ where x is the error `y_pred - y_true`.
+
+ Usage:
+
+ ```python
+ l = tf.keras.losses.LogCosh()
+ loss = l([0., 1., 1.], [1., 0., 1.])
+ print('Loss: ', loss.numpy()) # Loss: 0.289
+ ```
+
+ Usage with the `compile` API:
+
+ ```python
+ model = tf.keras.Model(inputs, outputs)
+ model.compile('sgd', loss=tf.keras.losses.LogCosh())
+ ```
+ """
+
+ def __init__(self, reduction=losses_utils.ReductionV2.AUTO, name='logcosh'):
+ super(LogCosh, self).__init__(logcosh, name=name, reduction=reduction)
+
+
+@keras_export('keras.losses.KLDivergence')
+class KLDivergence(LossFunctionWrapper):
+ """Computes Kullback-Leibler divergence loss between `y_true` and `y_pred`.
+
+ `loss = y_true * log(y_true / y_pred)`
+
+ See: https://en.wikipedia.org/wiki/Kullback%E2%80%93Leibler_divergence
+
+ Usage:
+
+ ```python
+ k = tf.keras.losses.KLDivergence()
+ loss = k([.4, .9, .2], [.5, .8, .12])
+ print('Loss: ', loss.numpy()) # Loss: 0.11891246
+ ```
+
+ Usage with the `compile` API:
+
+ ```python
+ model = tf.keras.Model(inputs, outputs)
+ model.compile('sgd', loss=tf.keras.losses.KLDivergence())
+ ```
+ """
+
+ def __init__(self,
+ reduction=losses_utils.ReductionV2.AUTO,
+ name='kullback_leibler_divergence'):
+ super(KLDivergence, self).__init__(
+ kullback_leibler_divergence, name=name, reduction=reduction)
+
+
+@keras_export('keras.losses.Huber')
+class Huber(LossFunctionWrapper):
+ """Computes the Huber loss between `y_true` and `y_pred`.
+
+ For each value x in `error = y_true - y_pred`:
+
+ ```
+ loss = 0.5 * x^2 if |x| <= d
+ loss = 0.5 * d^2 + d * (|x| - d) if |x| > d
+ ```
+ where d is `delta`. See: https://en.wikipedia.org/wiki/Huber_loss
+
+ Usage:
+
+ ```python
+ l = tf.keras.losses.Huber()
+ loss = l([0., 1., 1.], [1., 0., 1.])
+ print('Loss: ', loss.numpy()) # Loss: 0.333
+ ```
+
+ Usage with the `compile` API:
+
+ ```python
+ model = tf.keras.Model(inputs, outputs)
+ model.compile('sgd', loss=tf.keras.losses.Huber())
+ ```
+
+ Args:
+ delta: A float, the point where the Huber loss function changes from a
+ quadratic to linear.
+ reduction: (Optional) Type of `tf.keras.losses.Reduction` to apply to loss.
+ Default value is `AUTO`. `AUTO` indicates that the reduction option will
+ be determined by the usage context. For almost all cases this defaults to
+ `SUM_OVER_BATCH_SIZE`.
+ When used with `tf.distribute.Strategy`, outside of built-in training
+ loops such as `tf.keras` `compile` and `fit`, using `AUTO` or
+ `SUM_OVER_BATCH_SIZE` will raise an error. Please see
+ https://www.tensorflow.org/alpha/tutorials/distribute/training_loops
+ for more details on this.
+ name: Optional name for the op.
+ """
+
+ def __init__(self,
+ delta=1.0,
+ reduction=losses_utils.ReductionV2.AUTO,
+ name='huber_loss'):
+ super(Huber, self).__init__(
+ huber_loss, name=name, reduction=reduction, delta=delta)
+
+
+@keras_export('keras.metrics.mean_squared_error',
+ 'keras.metrics.mse',
+ 'keras.metrics.MSE',
+ 'keras.losses.mean_squared_error',
+ 'keras.losses.mse',
+ 'keras.losses.MSE')
+def mean_squared_error(y_true, y_pred):
+ y_pred = ops.convert_to_tensor(y_pred)
+ y_true = math_ops.cast(y_true, y_pred.dtype)
+ return K.mean(math_ops.squared_difference(y_pred, y_true), axis=-1)
+
+
+@keras_export('keras.metrics.mean_absolute_error',
+ 'keras.metrics.mae',
+ 'keras.metrics.MAE',
+ 'keras.losses.mean_absolute_error',
+ 'keras.losses.mae',
+ 'keras.losses.MAE')
+def mean_absolute_error(y_true, y_pred):
+ y_pred = ops.convert_to_tensor(y_pred)
+ y_true = math_ops.cast(y_true, y_pred.dtype)
+ return K.mean(math_ops.abs(y_pred - y_true), axis=-1)
+
+
+@keras_export('keras.metrics.mean_absolute_percentage_error',
+ 'keras.metrics.mape',
+ 'keras.metrics.MAPE',
+ 'keras.losses.mean_absolute_percentage_error',
+ 'keras.losses.mape',
+ 'keras.losses.MAPE')
+def mean_absolute_percentage_error(y_true, y_pred): # pylint: disable=missing-docstring
+ y_pred = ops.convert_to_tensor(y_pred)
+ y_true = math_ops.cast(y_true, y_pred.dtype)
+ diff = math_ops.abs(
+ (y_true - y_pred) / K.clip(math_ops.abs(y_true), K.epsilon(), None))
+ return 100. * K.mean(diff, axis=-1)
+
+
+@keras_export('keras.metrics.mean_squared_logarithmic_error',
+ 'keras.metrics.msle',
+ 'keras.metrics.MSLE',
+ 'keras.losses.mean_squared_logarithmic_error',
+ 'keras.losses.msle',
+ 'keras.losses.MSLE')
+def mean_squared_logarithmic_error(y_true, y_pred): # pylint: disable=missing-docstring
+ y_pred = ops.convert_to_tensor(y_pred)
+ y_true = math_ops.cast(y_true, y_pred.dtype)
+ first_log = math_ops.log(K.clip(y_pred, K.epsilon(), None) + 1.)
+ second_log = math_ops.log(K.clip(y_true, K.epsilon(), None) + 1.)
+ return K.mean(math_ops.squared_difference(first_log, second_log), axis=-1)
+
+
+def _maybe_convert_labels(y_true):
+ """Converts binary labels into -1/1."""
+ are_zeros = math_ops.equal(y_true, 0)
+ are_ones = math_ops.equal(y_true, 1)
+ is_binary = math_ops.reduce_all(math_ops.logical_or(are_zeros, are_ones))
+
+ def _convert_binary_labels():
+ # Convert the binary labels to -1 or 1.
+ return 2. * y_true - 1.
+
+ updated_y_true = smart_cond.smart_cond(is_binary,
+ _convert_binary_labels, lambda: y_true)
+ return updated_y_true
+
+
+@keras_export('keras.metrics.squared_hinge', 'keras.losses.squared_hinge')
+def squared_hinge(y_true, y_pred):
+ """Computes the squared hinge loss between `y_true` and `y_pred`.
+
+ Args:
+ y_true: The ground truth values. `y_true` values are expected to be -1 or 1.
+ If binary (0 or 1) labels are provided we will convert them to -1 or 1.
+ y_pred: The predicted values.
+
+ Returns:
+ Tensor with one scalar loss entry per sample.
+ """
+ y_pred = ops.convert_to_tensor(y_pred)
+ y_true = math_ops.cast(y_true, y_pred.dtype)
+ y_true = _maybe_convert_labels(y_true)
+ return K.mean(
+ math_ops.square(math_ops.maximum(1. - y_true * y_pred, 0.)), axis=-1)
+
+
+@keras_export('keras.metrics.hinge', 'keras.losses.hinge')
+def hinge(y_true, y_pred):
+ """Computes the hinge loss between `y_true` and `y_pred`.
+
+ Args:
+ y_true: The ground truth values. `y_true` values are expected to be -1 or 1.
+ If binary (0 or 1) labels are provided they will be converted to -1 or 1.
+ y_pred: The predicted values.
+
+ Returns:
+ Tensor with one scalar loss entry per sample.
+ """
+ y_pred = ops.convert_to_tensor(y_pred)
+ y_true = math_ops.cast(y_true, y_pred.dtype)
+ y_true = _maybe_convert_labels(y_true)
+ return K.mean(math_ops.maximum(1. - y_true * y_pred, 0.), axis=-1)
+
+
+@keras_export('keras.losses.categorical_hinge')
+def categorical_hinge(y_true, y_pred):
+ """Computes the categorical hinge loss between `y_true` and `y_pred`.
+
+ Args:
+ y_true: The ground truth values. `y_true` values are expected to be -1 or 1.
+ If binary (0 or 1) labels are provided they will be converted to -1 or 1.
+ y_pred: The predicted values.
+
+ Returns:
+ A tensor.
+ """
+ y_pred = ops.convert_to_tensor(y_pred)
+ y_true = math_ops.cast(y_true, y_pred.dtype)
+ pos = math_ops.reduce_sum(y_true * y_pred, axis=-1)
+ neg = math_ops.reduce_max((1. - y_true) * y_pred, axis=-1)
+ return math_ops.maximum(0., neg - pos + 1.)
+
+
+def huber_loss(y_true, y_pred, delta=1.0):
+ """Computes Huber loss value.
+
+ For each value x in `error = y_true - y_pred`:
+
+ ```
+ loss = 0.5 * x^2 if |x| <= d
+ loss = 0.5 * d^2 + d * (|x| - d) if |x| > d
+ ```
+ where d is `delta`. See: https://en.wikipedia.org/wiki/Huber_loss
+
+ Args:
+ y_true: tensor of true targets.
+ y_pred: tensor of predicted targets.
+ delta: A float, the point where the Huber loss function changes from a
+ quadratic to linear.
+
+ Returns:
+ Tensor with one scalar loss entry per sample.
+ """
+ y_pred = math_ops.cast(y_pred, dtype=K.floatx())
+ y_true = math_ops.cast(y_true, dtype=K.floatx())
+ error = math_ops.subtract(y_pred, y_true)
+ abs_error = math_ops.abs(error)
+ quadratic = math_ops.minimum(abs_error, delta)
+ linear = math_ops.subtract(abs_error, quadratic)
+ return math_ops.add(
+ math_ops.multiply(
+ ops.convert_to_tensor(0.5, dtype=quadratic.dtype),
+ math_ops.multiply(quadratic, quadratic)),
+ math_ops.multiply(delta, linear))
+
+
+@keras_export('keras.losses.logcosh')
+def logcosh(y_true, y_pred):
+ """Logarithm of the hyperbolic cosine of the prediction error.
+
+ `log(cosh(x))` is approximately equal to `(x ** 2) / 2` for small `x` and
+ to `abs(x) - log(2)` for large `x`. This means that 'logcosh' works mostly
+ like the mean squared error, but will not be so strongly affected by the
+ occasional wildly incorrect prediction.
+
+ Arguments:
+ y_true: tensor of true targets.
+ y_pred: tensor of predicted targets.
+
+ Returns:
+ Tensor with one scalar loss entry per sample.
+ """
+ y_pred = ops.convert_to_tensor(y_pred)
+ y_true = math_ops.cast(y_true, y_pred.dtype)
+
+ def _logcosh(x):
+ return x + nn.softplus(-2. * x) - math_ops.log(2.)
+
+ return K.mean(_logcosh(y_pred - y_true), axis=-1)
+
+
+@keras_export('keras.metrics.categorical_crossentropy',
+ 'keras.losses.categorical_crossentropy')
+def categorical_crossentropy(y_true,
+ y_pred,
+ from_logits=False,
+ label_smoothing=0):
+ """Computes the categorical crossentropy loss.
+
+ Args:
+ y_true: tensor of true targets.
+ y_pred: tensor of predicted targets.
+ from_logits: Whether `y_pred` is expected to be a logits tensor. By default,
+ we assume that `y_pred` encodes a probability distribution.
+ label_smoothing: Float in [0, 1]. If > `0` then smooth the labels.
+
+ Returns:
+ Categorical crossentropy loss value.
+ """
+ y_pred = ops.convert_to_tensor(y_pred)
+ y_true = math_ops.cast(y_true, y_pred.dtype)
+ label_smoothing = ops.convert_to_tensor(label_smoothing, dtype=K.floatx())
+
+ def _smooth_labels():
+ num_classes = math_ops.cast(array_ops.shape(y_true)[1], y_pred.dtype)
+ return y_true * (1.0 - label_smoothing) + (label_smoothing / num_classes)
+
+ y_true = smart_cond.smart_cond(label_smoothing,
+ _smooth_labels, lambda: y_true)
+ return K.categorical_crossentropy(y_true, y_pred, from_logits=from_logits)
+
+
+@keras_export('keras.metrics.sparse_categorical_crossentropy',
+ 'keras.losses.sparse_categorical_crossentropy')
+def sparse_categorical_crossentropy(y_true, y_pred, from_logits=False, axis=-1):
+ return my_backend.sparse_categorical_crossentropy(
+ y_true, y_pred, from_logits=from_logits, axis=axis)
+
+
+@keras_export('keras.metrics.binary_crossentropy',
+ 'keras.losses.binary_crossentropy')
+def binary_crossentropy(y_true, y_pred, from_logits=False, label_smoothing=0): # pylint: disable=missing-docstring
+ y_pred = ops.convert_to_tensor(y_pred)
+ y_true = math_ops.cast(y_true, y_pred.dtype)
+ label_smoothing = ops.convert_to_tensor(label_smoothing, dtype=K.floatx())
+
+ def _smooth_labels():
+ return y_true * (1.0 - label_smoothing) + 0.5 * label_smoothing
+
+ y_true = smart_cond.smart_cond(label_smoothing,
+ _smooth_labels, lambda: y_true)
+ return K.mean(
+ K.binary_crossentropy(y_true, y_pred, from_logits=from_logits), axis=-1)
+
+
+@keras_export('keras.metrics.kullback_leibler_divergence',
+ 'keras.metrics.kld',
+ 'keras.metrics.KLD',
+ 'keras.losses.kullback_leibler_divergence',
+ 'keras.losses.kld',
+ 'keras.losses.KLD')
+def kullback_leibler_divergence(y_true, y_pred):
+ """Computes Kullback-Leibler divergence loss between `y_true` and `y_pred`.
+
+ `loss = y_true * log(y_true / y_pred)`
+
+ See: https://en.wikipedia.org/wiki/Kullback%E2%80%93Leibler_divergence
+
+ Usage:
+
+ ```python
+ loss = tf.keras.losses.KLD([.4, .9, .2], [.5, .8, .12])
+ print('Loss: ', loss.numpy()) # Loss: 0.11891246
+ ```
+
+ Args:
+ y_true: Tensor of true targets.
+ y_pred: Tensor of predicted targets.
+
+ Returns:
+ A `Tensor` with loss.
+
+ Raises:
+ TypeError: If `y_true` cannot be cast to the `y_pred.dtype`.
+
+ """
+ y_pred = ops.convert_to_tensor(y_pred)
+ y_true = math_ops.cast(y_true, y_pred.dtype)
+ y_true = K.clip(y_true, K.epsilon(), 1)
+ y_pred = K.clip(y_pred, K.epsilon(), 1)
+ return math_ops.reduce_sum(y_true * math_ops.log(y_true / y_pred), axis=-1)
+
+
+@keras_export('keras.metrics.poisson', 'keras.losses.poisson')
+def poisson(y_true, y_pred):
+ """Computes the Poisson loss between y_true and y_pred.
+
+ The Poisson loss is the mean of the elements of the `Tensor`
+ `y_pred - y_true * log(y_pred)`.
+
+ Usage:
+
+ ```python
+ loss = tf.keras.losses.poisson([1.4, 9.3, 2.2], [4.3, 8.2, 12.2])
+ print('Loss: ', loss.numpy()) # Loss: -0.8045559
+ ```
+
+ Args:
+ y_true: Tensor of true targets.
+ y_pred: Tensor of predicted targets.
+
+ Returns:
+ A `Tensor` with the mean Poisson loss.
+
+ Raises:
+ InvalidArgumentError: If `y_true` and `y_pred` have incompatible shapes.
+ """
+ y_pred = ops.convert_to_tensor(y_pred)
+ y_true = math_ops.cast(y_true, y_pred.dtype)
+ return K.mean(y_pred - y_true * math_ops.log(y_pred + K.epsilon()), axis=-1)
+
+
+@keras_export(
+ 'keras.losses.cosine_similarity',
+ v1=[
+ 'keras.metrics.cosine_proximity',
+ 'keras.metrics.cosine',
+ 'keras.losses.cosine_proximity',
+ 'keras.losses.cosine',
+ 'keras.losses.cosine_similarity',
+ ])
+def cosine_similarity(y_true, y_pred, axis=-1):
+ """Computes the cosine similarity between labels and predictions.
+
+ Note that it is a negative quantity between -1 and 0, where 0 indicates
+ orthogonality and values closer to -1 indicate greater similarity. This makes
+ it usable as a loss function in a setting where you try to maximize the
+ proximity between predictions and targets.
+
+ `loss = -sum(y_true * y_pred)`
+
+ Args:
+ y_true: Tensor of true targets.
+ y_pred: Tensor of predicted targets.
+ axis: Axis along which to determine similarity.
+
+ Returns:
+ Cosine similarity tensor.
+ """
+ y_true = nn.l2_normalize(y_true, axis=axis)
+ y_pred = nn.l2_normalize(y_pred, axis=axis)
+ return -math_ops.reduce_sum(y_true * y_pred, axis=axis)
+
+
+@keras_export('keras.losses.CosineSimilarity')
+class CosineSimilarity(LossFunctionWrapper):
+ """Computes the cosine similarity between `y_true` and `y_pred`.
+
+ Usage:
+
+ ```python
+ cosine_loss = tf.keras.losses.CosineSimilarity(axis=1)
+ loss = cosine_loss([[0., 1.], [1., 1.]], [[1., 0.], [1., 1.]])
+ # l2_norm(y_true) = [[0., 1.], [1./1.414], 1./1.414]]]
+ # l2_norm(y_pred) = [[1., 0.], [1./1.414], 1./1.414]]]
+ # l2_norm(y_true) . l2_norm(y_pred) = [[0., 0.], [0.5, 0.5]]
+ # loss = mean(sum(l2_norm(y_true) . l2_norm(y_pred), axis=1))
+ = ((0. + 0.) + (0.5 + 0.5)) / 2
+
+ print('Loss: ', loss.numpy()) # Loss: 0.5
+ ```
+
+ Usage with the `compile` API:
+
+ ```python
+ model = tf.keras.Model(inputs, outputs)
+ model.compile('sgd', loss=tf.keras.losses.CosineSimilarity(axis=1))
+ ```
+
+ Args:
+ axis: (Optional) Defaults to -1. The dimension along which the cosine
+ similarity is computed.
+ reduction: (Optional) Type of `tf.keras.losses.Reduction` to apply to loss.
+ Default value is `AUTO`. `AUTO` indicates that the reduction option will
+ be determined by the usage context. For almost all cases this defaults to
+ `SUM_OVER_BATCH_SIZE`.
+ When used with `tf.distribute.Strategy`, outside of built-in training
+ loops such as `tf.keras` `compile` and `fit`, using `AUTO` or
+ `SUM_OVER_BATCH_SIZE` will raise an error. Please see
+ https://www.tensorflow.org/alpha/tutorials/distribute/training_loops
+ for more details on this.
+ name: Optional name for the op.
+ """
+
+ def __init__(self,
+ axis=-1,
+ reduction=losses_utils.ReductionV2.AUTO,
+ name='cosine_similarity'):
+ super(CosineSimilarity, self).__init__(
+ cosine_similarity, reduction=reduction, name=name, axis=axis)
+
+
+# Aliases.
+
+mse = MSE = mean_squared_error
+mae = MAE = mean_absolute_error
+mape = MAPE = mean_absolute_percentage_error
+msle = MSLE = mean_squared_logarithmic_error
+kld = KLD = kullback_leibler_divergence
+
+
+def is_categorical_crossentropy(loss):
+ result = ((isinstance(loss, CategoricalCrossentropy) or
+ (isinstance(loss, LossFunctionWrapper) and
+ loss.fn == categorical_crossentropy) or
+ (hasattr(loss, '__name__') and
+ loss.__name__ == 'categorical_crossentropy') or
+ (loss == 'categorical_crossentropy')))
+ return result
+
+
+@keras_export('keras.losses.serialize')
+def serialize(loss):
+ return serialize_keras_object(loss)
+
+
+@keras_export('keras.losses.deserialize')
+def deserialize(name, custom_objects=None):
+ return deserialize_keras_object(
+ name,
+ module_objects=globals(),
+ custom_objects=custom_objects,
+ printable_module_name='loss function')
+
+
+@keras_export('keras.losses.get')
+def get(identifier):
+ if identifier is None:
+ return None
+ if isinstance(identifier, six.string_types):
+ identifier = str(identifier)
+ return deserialize(identifier)
+ if isinstance(identifier, dict):
+ return deserialize(identifier)
+ elif callable(identifier):
+ return identifier
+ else:
+ raise ValueError('Could not interpret '
+ 'loss function identifier:', identifier)
+
+
+LABEL_DTYPES_FOR_LOSSES = {
+ losses_impl.sparse_softmax_cross_entropy: 'int32',
+ sparse_categorical_crossentropy: 'int32'
+}
\ No newline at end of file
diff --git a/TensorFlow2/built-in/keras_sample/involution_ID2515_for_TensorFlow2.X/requirements.txt b/TensorFlow2/built-in/keras_sample/involution_ID2515_for_TensorFlow2.X/requirements.txt
new file mode 100644
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
diff --git a/TensorFlow2/built-in/keras_sample/involution_ID2515_for_TensorFlow2.X/test/train_full_1p_static.sh b/TensorFlow2/built-in/keras_sample/involution_ID2515_for_TensorFlow2.X/test/train_full_1p_static.sh
new file mode 100644
index 0000000000000000000000000000000000000000..91507abd51677518e3ecab396d3ab24fd52cbd40
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/involution_ID2515_for_TensorFlow2.X/test/train_full_1p_static.sh
@@ -0,0 +1,171 @@
+#!/bin/bash
+cur_path=`pwd`/../
+
+#设置默认日志级别,不需要修改
+# export ASCEND_GLOBAL_LOG_LEVEL=3
+
+#基础参数,需要模型审视修改
+#Batch Size
+batch_size=256
+#网络名称,同目录名称
+Network="involution_ID2515_for_TensorFlow2.X"
+#Device数量,单卡默认为1
+RANK_SIZE=1
+#训练epoch,可选
+train_epochs=200
+#训练step
+#train_steps=50000
+#学习率
+#learning_rate=1e-5
+#网络类型 convolution or involution
+network="convolution"
+#参数配置
+data_path=""
+
+############维测参数##############
+precision_mode="allow_mix_precision"
+#维持参数,以下不需要修改
+over_dump=False
+if [[ $over_dump == True ]];then
+ over_dump_path=$cur_path/test/overflow_dump #此处cur_path为代码根目录
+ mkdir -p ${over_dump_path}
+fi
+data_dump_flag=False
+data_dump_step="10"
+profiling=False
+use_mixlist=True
+mixlist_file="./configs/ops_info.json"
+fusion_off_flag=False
+fusion_off_file="./configs/fusion_switch.cfg"
+auto_tune=False
+############维测参数##############
+
+if [[ $1 == --help || $1 == --h ]];then
+ echo "usage: ./train_performance_1p.sh"
+ exit 1
+fi
+
+for para in $*
+do
+ if [[ $para == --data_path* ]];then
+ data_path=`echo ${para#*=}`
+ fi
+done
+
+for para in $*
+do
+ if [[ $para == --data_path* ]];then
+ data_path=`echo ${para#*=}`
+ elif [[ $para == --precision_mode* ]];then
+ precision_mode=`echo ${para#*=}`
+ elif [[ $para == --over_dump* ]];then
+ over_dump=`echo ${para#*=}`
+ over_dump_path=${cur_path}/output/overflow_dump
+ mkdir -p ${over_dump_path}
+ elif [[ $para == --data_dump_flag* ]];then
+ data_dump_flag=`echo ${para#*=}`
+ data_dump_path=${cur_path}/output/data_dump
+ mkdir -p ${data_dump_path}
+ elif [[ $para == --data_dump_step* ]];then
+ data_dump_step=`echo ${para#*=}`
+ elif [[ $para == --profiling* ]];then
+ profiling=`echo ${para#*=}`
+ profiling_dump_path=${cur_path}/output/profiling
+ mkdir -p ${profiling_dump_path}
+ elif [[ $para == --data_path* ]];then
+ data_path=`echo ${para#*=}`
+ elif [[ $para == --use_mixlist* ]];then
+ use_mixlist=`echo ${para#*=}`
+ elif [[ $para == --mixlist_file* ]];then
+ mixlist_file=`echo ${para#*=}`
+ elif [[ $para == --fusion_off_flag* ]];then
+ fusion_off_flag=`echo ${para#*=}`
+ elif [[ $para == --fusion_off_file* ]];then
+ fusion_off_file=`echo ${para#*=}`
+ elif [[ $para == --auto_tune* ]];then
+ auto_tune=`echo ${para#*=}`
+ fi
+done
+
+##############执行训练##########
+cd $cur_path
+
+if [ -d $cur_path/test/output ];then
+ rm -rf $cur_path/test/output/*
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+else
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+fi
+wait
+
+start=$(date +%s)
+nohup python3 involution.py --data_path=$data_path \
+ --epochs=$train_epochs \
+ --Drop_Reminder=True \
+ --batch_size=$batch_size \
+ --save_h5=False \
+ --network=$network \
+ --precision_mode=${precision_mode} \
+ --over_dump=${over_dump} \
+ --over_dump_path=${over_dump_path} \
+ --data_dump_flag=${data_dump_flag} \
+ --data_dump_step=${data_dump_step} \
+ --data_dump_path=${data_dump_path} \
+ --profiling=${profiling} \
+ --use_mixlist=${use_mixlist} \
+ --fusion_off_flag=${fusion_off_flag} \
+ --mixlist_file=${mixlist_file} \
+ --fusion_off_file=${fusion_off_file} \
+ --auto_tune=${auto_tune} \
+ --profiling_dump_path=${profiling_dump_path} > $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 &
+wait
+
+end=$(date +%s)
+e2e_time=$(( $end - $start ))
+
+echo "Final Training Duration sec : $e2e_time"
+
+#结果打印,不需要修改
+echo "------------------ Final result ------------------"
+#输出性能FPS,需要模型审视修改
+single_batch_step_sec=`grep TimeHistory $cur_path/test/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk 'END {print $4}'`
+FPS=`awk 'BEGIN{printf "%.2f\n",'${single_batch_step_sec}'}'`
+wait
+
+#打印,不需要修改
+echo "Final Performance images/sec : $FPS"
+
+#输出训练精度,需要模型审视修改
+train_accuracy=`grep val_loss $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | awk 'END {print$15}'`
+#打印,不需要修改
+echo "Final Train Accuracy : ${train_accuracy}"
+
+
+#精度看护结果汇总
+#训练用例信息,不需要修改
+BatchSize=${batch_size}
+DeviceType=`uname -m`
+CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc'
+
+##获取性能数据,不需要修改
+#吞吐量
+ActualFPS=${FPS}
+#单迭代训练时长
+TrainingTime=`awk 'BEGIN{printf "%.2f\n",'${BatchSize}'*'${RANK_SIZE}'*1000/'${FPS}'}'`
+
+#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视
+cat $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log| grep val_loss | awk -F " " '{print $6}' > $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt
+#最后一个迭代loss值,不需要修改
+ActualLoss=`awk 'END {print $1}' $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt`
+
+#关键信息打印到${CaseName}.log中,不需要修改
+echo "Network = ${Network}" > $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "RankSize = ${RANK_SIZE}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "BatchSize = ${BatchSize}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "DeviceType = ${DeviceType}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "CaseName = ${CaseName}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualFPS = ${ActualFPS}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainingTime = ${TrainingTime}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualLoss = ${ActualLoss}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
diff --git a/TensorFlow2/built-in/keras_sample/involution_ID2515_for_TensorFlow2.X/test/train_performance_1p.sh b/TensorFlow2/built-in/keras_sample/involution_ID2515_for_TensorFlow2.X/test/train_performance_1p.sh
new file mode 100644
index 0000000000000000000000000000000000000000..ce3d5853fdb5b41c656381c54a5828ef0043deba
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/involution_ID2515_for_TensorFlow2.X/test/train_performance_1p.sh
@@ -0,0 +1,136 @@
+#!/bin/bash
+cur_path=`pwd`/../
+
+#设置默认日志级别,不需要修改
+export ASCEND_SLOG_PRINT_TO_STDOUT=1
+
+#基础参数,需要模型审视修改
+#Batch Size
+batch_size=1024
+#网络名称,同目录名称
+Network="involution_ID2515_for_TensorFlow2.X"
+#Device数量,单卡默认为1
+RANK_SIZE=1
+#训练epoch,可选
+train_epochs=20
+#训练step
+#train_steps=50000
+#学习率
+#learning_rate=1e-5
+#网络类型 convolution or involution
+network="convolution"
+#参数配置
+data_path=""
+
+if [[ $1 == --help || $1 == --h ]];then
+ echo "usage: ./train_performance_1p.sh"
+ exit 1
+fi
+
+for para in $*
+do
+ if [[ $para == --data_path* ]];then
+ data_path=`echo ${para#*=}`
+ fi
+done
+
+if [[ $data_path == "" ]];then
+ echo "[Error] para \"data_path \" must be config"
+ exit 1
+fi
+
+##############执行训练##########
+cd $cur_path
+
+#参数修改
+#sed -i "s|../data/tfrecord|${data_path}/data/tfrecord|g" ${cur_path}/data/io/read_tfrecord.py
+#sed -i "s|PRETRAINED_CKPT = ROOT_PATH + '/|PRETRAINED_CKPT = '${cur_path}/|g" ${cur_path}/libs/configs/cfgs.py
+
+if [ -d $cur_path/test/output ];then
+ rm -rf $cur_path/test/output/*
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+else
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+fi
+wait
+
+start=$(date +%s)
+nohup python3 involution.py --data_path=$data_path \
+ --batch_size=$batch_size \
+ --epochs=$train_epochs \
+ --Drop_Reminder=False \
+ --save_h5=False \
+ --network=$network > $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 &
+wait
+
+end=$(date +%s)
+e2etime=$(( $end - $start ))
+
+#echo "Final Performance ms/step : $average_perf"
+echo "Final Training Duration sec : $e2e_time"
+
+#参数回改
+#sed -i "s|${datth}/th}//io//tfrecord|../data/tfrecord|g" ${cur_path}/data/io/read_tfrecord.py
+#sed -i "s|PRETRAINED_C'/|g" ${cur_paath}/|PRETRAINED_CKPT = ROOT_PATH + '/|g" ${cur_path}/libs/configs/cfgs.py
+
+#结果打印,不需要修改
+echo "------------------ Final result ------------------"
+#输出性能FPS,需要模型审视修改
+#由于loss和性能取值不连续,所以每次只取每个Epoch的最后一个loss和性能值
+#StepTime=`grep loss $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | grep -v 'ETA' | awk '{print $5}' | tr -d ms/step | awk '{sum+=$1} END {print sum/NR}'`
+#FPS计算
+#FPS=`awk 'BEGIN{printf "%.2f\n",'1000'*'${batch_size}'/'${StepTime}'}'`
+#打印,不需要修改
+echo "Final Performance images/sec : $FPS"
+
+#输出训练精度,需要模型审视修改
+#train_accuracy=`grep accuracy $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | grep -v 'ETA' | awk '{print $11}' | awk '{sum+=$1} END {print sum/NR}'`
+#打印,不需要修改
+echo "Final Train Accuracy : ${train_accuracy}"
+
+#echo "Final Performance ms/step : $average_perf"
+echo "Final Training Duration sec : $e2etime"
+
+###下面字段用于冒烟看护
+BatchSize=${batch_size}
+#设备类型,自动获取
+DeviceType=`uname -m`
+#用例名称,自动获取
+CaseName=${Network}_bs${BatchSize}_${RankSize}'p'_'perf'
+
+##获取性能数据,不需要修改
+#吞吐量
+#ActualFPS=${FPS}
+#单迭代训练时长
+#TrainingTime=`grep loss $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | grep -v 'ETA' | awk '{print $4}' | tr -d s | awk '{sum+=$1} END {print sum}'`
+
+#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视
+grep loss: $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | grep -Eo " loss: [0-9]*\.[0-9]*"| awk '{print $2}' > $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt
+#最后一个迭代loss值,不需要修改
+ActualLoss=`awk 'END {print $1}' $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt`
+
+##获取错误信息
+#系统错误信息
+ModelStatus="图执行FAIL"
+error_msg="EZ3002"
+#判断错误信息是否和历史状态一致,此处无需修改
+error_msg="Graph engine process graph failed: EZ3002: Optype \[Conv2DBackpropFilter\] of Ops kernel"
+Status=`grep "${error_msg}" $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|wc -l`
+#DTS单号或者issue链接
+DTS_Number="DTS2021090622224"
+
+#关键信息打印到CaseName.log中,此处无需修改
+echo "Network = ${Network}" > $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "RankSize = ${RANK_SIZE}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "BatchSize = ${BatchSize}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "DeviceType = ${DeviceType}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "CaseName = ${CaseName}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ModelStatus = ${ModelStatus}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "DTS_Number = ${DTS_Number}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "Status = ${Status}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "error_msg = ${error_msg}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+#echo "ActualFPS = ${ActualFPS}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+#echo "TrainingTime = ${TrainingTime}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+#echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+#echo "ActualLoss = ${ActualLoss}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+#echo "E2ETrainingTime = ${e2etime}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
\ No newline at end of file
diff --git a/TensorFlow2/built-in/keras_sample/involution_ID2515_for_TensorFlow2.X/test/train_performance_1p_inv.sh b/TensorFlow2/built-in/keras_sample/involution_ID2515_for_TensorFlow2.X/test/train_performance_1p_inv.sh
new file mode 100644
index 0000000000000000000000000000000000000000..9fd389328f926ba1e7f4592ae4059575a97a8200
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/involution_ID2515_for_TensorFlow2.X/test/train_performance_1p_inv.sh
@@ -0,0 +1,160 @@
+#!/bin/bash
+cur_path=`pwd`/../
+
+#基础参数,需要模型审视修改
+#Batch Size
+batch_size=256
+#网络名称,同目录名称
+Network="involution_ID2515_for_TensorFlow2.X"
+#Device数量,单卡默认为1
+RANK_SIZE=1
+#训练epoch,可选
+train_epochs=2
+#训练step
+#train_steps=50000
+#学习率
+#learning_rate=1e-5
+#网络类型 convolution or involution
+network="involution"
+#参数配置
+data_path=""
+
+############维测参数##############
+precision_mode="allow_mix_precision"
+#维持参数,以下不需要修改
+over_dump=False
+if [[ $over_dump == True ]];then
+ over_dump_path=$cur_path/test/overflow_dump #此处cur_path为代码根目录
+ mkdir -p ${over_dump_path}
+fi
+data_dump_flag=False
+data_dump_step="10"
+profiling=False
+use_mixlist=True
+mixlist_file="./configs/ops_info.json"
+fusion_off_flag=False
+fusion_off_file="./configs/fusion_switch.cfg"
+auto_tune=False
+############维测参数##############
+
+if [[ $1 == --help || $1 == --h ]];then
+ echo "usage: ./train_performance_1p.sh"
+ exit 1
+fi
+
+for para in $*
+do
+ if [[ $para == --data_path* ]];then
+ data_path=`echo ${para#*=}`
+ fi
+done
+
+for para in $*
+do
+ if [[ $para == --data_path* ]];then
+ data_path=`echo ${para#*=}`
+ elif [[ $para == --precision_mode* ]];then
+ precision_mode=`echo ${para#*=}`
+ elif [[ $para == --over_dump* ]];then
+ over_dump=`echo ${para#*=}`
+ over_dump_path=${cur_path}/output/overflow_dump
+ mkdir -p ${over_dump_path}
+ elif [[ $para == --data_dump_flag* ]];then
+ data_dump_flag=`echo ${para#*=}`
+ data_dump_path=${cur_path}/output/data_dump
+ mkdir -p ${data_dump_path}
+ elif [[ $para == --data_dump_step* ]];then
+ data_dump_step=`echo ${para#*=}`
+ elif [[ $para == --profiling* ]];then
+ profiling=`echo ${para#*=}`
+ profiling_dump_path=${cur_path}/output/profiling
+ mkdir -p ${profiling_dump_path}
+ elif [[ $para == --data_path* ]];then
+ data_path=`echo ${para#*=}`
+ elif [[ $para == --use_mixlist* ]];then
+ use_mixlist=`echo ${para#*=}`
+ elif [[ $para == --mixlist_file* ]];then
+ mixlist_file=`echo ${para#*=}`
+ elif [[ $para == --fusion_off_flag* ]];then
+ fusion_off_flag=`echo ${para#*=}`
+ elif [[ $para == --fusion_off_file* ]];then
+ fusion_off_file=`echo ${para#*=}`
+ elif [[ $para == --auto_tune* ]];then
+ auto_tune=`echo ${para#*=}`
+ fi
+done
+
+##############执行训练##########
+cd $cur_path
+
+if [ -d $cur_path/test/output ];then
+ rm -rf $cur_path/test/output/*
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+else
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+fi
+wait
+
+start=$(date +%s)
+nohup python3 involution.py --data_path=$data_path \
+ --epochs=$train_epochs \
+ --Drop_Reminder=True \
+ --batch_size=$batch_size \
+ --save_h5=False \
+ --network=$network \
+ --precision_mode=${precision_mode} \
+ --over_dump=${over_dump} \
+ --over_dump_path=${over_dump_path} \
+ --data_dump_flag=${data_dump_flag} \
+ --data_dump_step=${data_dump_step} \
+ --data_dump_path=${data_dump_path} \
+ --profiling=${profiling} \
+ --use_mixlist=${use_mixlist} \
+ --fusion_off_flag=${fusion_off_flag} \
+ --mixlist_file=${mixlist_file} \
+ --fusion_off_file=${fusion_off_file} \
+ --auto_tune=${auto_tune} \
+ --profiling_dump_path=${profiling_dump_path} > $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 &
+wait
+
+end=$(date +%s)
+e2etime=$(( $end - $start ))
+
+#echo "Final Performance ms/step : $average_perf"
+echo "Final Training Duration sec : $e2e_time"
+
+#结果打印,不需要修改
+echo "------------------ Final result ------------------"
+echo "Final Training Duration sec : $e2etime"
+
+###下面字段用于冒烟看护
+BatchSize=${batch_size}
+#设备类型,自动获取
+DeviceType=`uname -m`
+#用例名称,自动获取
+CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf'
+
+##获取错误信息
+#系统错误信息
+ModelStatus="图执行FAIL"
+#判断错误信息是否和历史状态一致,此处无需修改
+error_msg="E19014: Value \[input x shape\] for Op \[inv_model/inv_2/reshape_1/Shape\] is invalid. Reason: contains negative or zero dimension."
+Status=`grep "${error_msg}" $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|wc -l`
+#DTS单号或者issue链接
+DTS_Number="DTS2021090622224"
+
+#关键信息打印到CaseName.log中,此处无需修改
+echo "Network = ${Network}" > $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "RankSize = ${RANK_SIZE}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "BatchSize = ${BatchSize}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "DeviceType = ${DeviceType}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "CaseName = ${CaseName}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ModelStatus = ${ModelStatus}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "DTS_Number = ${DTS_Number}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "Status = ${Status}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "error_msg = ${error_msg}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+#echo "ActualFPS = ${ActualFPS}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+#echo "TrainingTime = ${TrainingTime}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+#echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+#echo "ActualLoss = ${ActualLoss}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+#echo "E2ETrainingTime = ${e2etime}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
\ No newline at end of file
diff --git a/TensorFlow2/built-in/keras_sample/involution_ID2515_for_TensorFlow2.X/test/train_performance_1p_static.sh b/TensorFlow2/built-in/keras_sample/involution_ID2515_for_TensorFlow2.X/test/train_performance_1p_static.sh
new file mode 100644
index 0000000000000000000000000000000000000000..c19eb17a8ae4fca1d2481592182e54057b5c3bdb
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/involution_ID2515_for_TensorFlow2.X/test/train_performance_1p_static.sh
@@ -0,0 +1,171 @@
+#!/bin/bash
+cur_path=`pwd`/../
+
+#设置默认日志级别,不需要修改
+# export ASCEND_GLOBAL_LOG_LEVEL=3
+
+#基础参数,需要模型审视修改
+#Batch Size
+batch_size=512
+#网络名称,同目录名称
+Network="involution_ID2515_for_TensorFlow2.X"
+#Device数量,单卡默认为1
+RANK_SIZE=1
+#训练epoch,可选
+train_epochs=5
+#训练step
+#train_steps=50000
+#学习率
+#learning_rate=1e-5
+#网络类型 convolution or involution
+network="convolution"
+#参数配置
+data_path=""
+
+############维测参数##############
+precision_mode="allow_mix_precision"
+#维持参数,以下不需要修改
+over_dump=False
+if [[ $over_dump == True ]];then
+ over_dump_path=$cur_path/test/overflow_dump #此处cur_path为代码根目录
+ mkdir -p ${over_dump_path}
+fi
+data_dump_flag=False
+data_dump_step="10"
+profiling=False
+use_mixlist=True
+mixlist_file="./configs/ops_info.json"
+fusion_off_flag=False
+fusion_off_file="./configs/fusion_switch.cfg"
+auto_tune=False
+############维测参数##############
+
+if [[ $1 == --help || $1 == --h ]];then
+ echo "usage: ./train_performance_1p.sh"
+ exit 1
+fi
+
+for para in $*
+do
+ if [[ $para == --data_path* ]];then
+ data_path=`echo ${para#*=}`
+ fi
+done
+
+for para in $*
+do
+ if [[ $para == --data_path* ]];then
+ data_path=`echo ${para#*=}`
+ elif [[ $para == --precision_mode* ]];then
+ precision_mode=`echo ${para#*=}`
+ elif [[ $para == --over_dump* ]];then
+ over_dump=`echo ${para#*=}`
+ over_dump_path=${cur_path}/output/overflow_dump
+ mkdir -p ${over_dump_path}
+ elif [[ $para == --data_dump_flag* ]];then
+ data_dump_flag=`echo ${para#*=}`
+ data_dump_path=${cur_path}/output/data_dump
+ mkdir -p ${data_dump_path}
+ elif [[ $para == --data_dump_step* ]];then
+ data_dump_step=`echo ${para#*=}`
+ elif [[ $para == --profiling* ]];then
+ profiling=`echo ${para#*=}`
+ profiling_dump_path=${cur_path}/output/profiling
+ mkdir -p ${profiling_dump_path}
+ elif [[ $para == --data_path* ]];then
+ data_path=`echo ${para#*=}`
+ elif [[ $para == --use_mixlist* ]];then
+ use_mixlist=`echo ${para#*=}`
+ elif [[ $para == --mixlist_file* ]];then
+ mixlist_file=`echo ${para#*=}`
+ elif [[ $para == --fusion_off_flag* ]];then
+ fusion_off_flag=`echo ${para#*=}`
+ elif [[ $para == --fusion_off_file* ]];then
+ fusion_off_file=`echo ${para#*=}`
+ elif [[ $para == --auto_tune* ]];then
+ auto_tune=`echo ${para#*=}`
+ fi
+done
+
+##############执行训练##########
+cd $cur_path
+
+if [ -d $cur_path/test/output ];then
+ rm -rf $cur_path/test/output/*
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+else
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+fi
+wait
+
+start=$(date +%s)
+nohup python3 involution.py --data_path=$data_path \
+ --epochs=$train_epochs \
+ --Drop_Reminder=True \
+ --batch_size=$batch_size \
+ --save_h5=False \
+ --network=$network \
+ --precision_mode=${precision_mode} \
+ --over_dump=${over_dump} \
+ --over_dump_path=${over_dump_path} \
+ --data_dump_flag=${data_dump_flag} \
+ --data_dump_step=${data_dump_step} \
+ --data_dump_path=${data_dump_path} \
+ --profiling=${profiling} \
+ --use_mixlist=${use_mixlist} \
+ --fusion_off_flag=${fusion_off_flag} \
+ --mixlist_file=${mixlist_file} \
+ --fusion_off_file=${fusion_off_file} \
+ --auto_tune=${auto_tune} \
+ --profiling_dump_path=${profiling_dump_path} > $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 &
+wait
+
+end=$(date +%s)
+e2e_time=$(( $end - $start ))
+
+echo "Final Training Duration sec : $e2e_time"
+
+#结果打印,不需要修改
+echo "------------------ Final result ------------------"
+#输出性能FPS,需要模型审视修改
+single_batch_step_sec=`grep TimeHistory $cur_path/test/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk 'END {print $4}'`
+FPS=`awk 'BEGIN{printf "%.2f\n",'${single_batch_step_sec}'}'`
+wait
+
+#打印,不需要修改
+echo "Final Performance images/sec : $FPS"
+
+#输出训练精度,需要模型审视修改
+train_accuracy=`grep val_loss $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | awk 'END {print$15}'`
+#打印,不需要修改
+echo "Final Train Accuracy : ${train_accuracy}"
+
+
+#精度看护结果汇总
+#训练用例信息,不需要修改
+BatchSize=${batch_size}
+DeviceType=`uname -m`
+CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf'
+
+##获取性能数据,不需要修改
+#吞吐量
+ActualFPS=${FPS}
+#单迭代训练时长
+TrainingTime=`awk 'BEGIN{printf "%.2f\n",'${BatchSize}'*'${RANK_SIZE}'*1000/'${FPS}'}'`
+
+#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视
+cat $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log| grep val_loss | awk -F " " '{print $6}' > $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt
+#最后一个迭代loss值,不需要修改
+ActualLoss=`awk 'END {print $1}' $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt`
+
+#关键信息打印到${CaseName}.log中,不需要修改
+echo "Network = ${Network}" > $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "RankSize = ${RANK_SIZE}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "BatchSize = ${BatchSize}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "DeviceType = ${DeviceType}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "CaseName = ${CaseName}_static" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualFPS = ${ActualFPS}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainingTime = ${TrainingTime}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualLoss = ${ActualLoss}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
diff --git a/TensorFlow2/built-in/keras_sample/keypoint_detection_ID2516_for_TensorFlow2.X/LICENSE b/TensorFlow2/built-in/keras_sample/keypoint_detection_ID2516_for_TensorFlow2.X/LICENSE
new file mode 100644
index 0000000000000000000000000000000000000000..51d555a151df9c6c96d16137aa4bcf6142a447ef
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/keypoint_detection_ID2516_for_TensorFlow2.X/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2018 Ke YU
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/TensorFlow2/built-in/keras_sample/keypoint_detection_ID2516_for_TensorFlow2.X/README.md b/TensorFlow2/built-in/keras_sample/keypoint_detection_ID2516_for_TensorFlow2.X/README.md
new file mode 100644
index 0000000000000000000000000000000000000000..ca02720a25af404f2bb0855c0ae1848328e32758
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/keypoint_detection_ID2516_for_TensorFlow2.X/README.md
@@ -0,0 +1,212 @@
+- [基本信息](#基本信息.md)
+- [概述](#概述.md)
+- [训练环境准备](#训练环境准备.md)
+- [快速上手](#快速上手.md)
+- [迁移学习指导](#迁移学习指导.md)
+- [高级参考](#高级参考.md)
+
+基本信息
+
+**发布者(Publisher):Huawei**
+
+**应用领域(Application Domain):Object Detection**
+
+**版本(Version):1.1**
+
+**修改时间(Modified) :2022.04.11**
+
+**大小(Size):10.2M**
+
+**框架(Framework):TensorFlow_2.6.2**
+
+**模型格式(Model Format):ckpt**
+
+**精度(Precision):Mixed**
+
+**处理器(Processor):昇腾910**
+
+**应用级别(Categories):Research**
+
+**描述(Description):基于TensorFlow2.X框架的图像关键点检测网络训练代码**
+
+
+概述
+
+## 简述
+
+ keypoint_detection网络使用数据增强和迁移学习训练图像关键点检测器。关键点检测包括定位关键对象部分,例如,我们脸部的关键部位包括鼻尖、眉毛、眼角等。这些部分有助于以功能丰富的方式表示底层对象。关键点检测的应用包括姿势估计、人脸检测等。
+
+
+ - 参考论文:
+
+ skip
+
+ - 参考实现:
+ https://github.com/keras-team/keras-io/blob/master/examples/vision/keypoint_detection.py(https://github.com/keras-team/keras-io/blob/master/examples/vision/keypoint_detection.py)
+
+
+ - 适配昇腾 AI 处理器的实现:
+ skip
+
+ - 通过Git获取对应commit\_id的代码方法如下:
+ ```
+ git clone {repository_url} # 克隆仓库的代码
+ cd {repository_name} # 切换到模型的代码仓目录
+ git checkout {branch} # 切换到对应分支
+ git reset --hard {commit_id} # 代码设置到对应的commit_id
+ cd {code_path} # 切换到模型代码所在路径,若仓库下只有该模型,则无需切换
+ ```
+
+
+
+
+## 默认配置
+
+
+- 网络结构
+ - 在 ImageNet-1k 数据集上预训练的 MobileNetV2 作为主干网络
+ - 网络总参数2,354,256
+
+- 训练超参(单卡):
+ - Batch size: 64
+ - IMG_SIZE: 224
+ - NUM_KEYPOINTS: 24 * 2
+ - Train epoch: 5
+
+
+## 支持特性
+
+| 特性列表 | 是否支持 |
+|-------|------|
+| 分布式训练 | 否 |
+| 混合精度 | 是 |
+| 数据并行 | 否 |
+
+## 混合精度训练
+
+昇腾910 AI处理器提供自动混合精度功能,可以针对全网中float32数据类型的算子,按照内置的优化策略,自动将部分float32的算子降低精度到float16,从而在精度损失很小的情况下提升系统性能并减少内存使用。
+
+## 开启混合精度
+相关代码示例。
+
+```
+ config_proto = tf.ConfigProto(allow_soft_placement=True)
+ custom_op = config_proto.graph_options.rewrite_options.custom_optimizers.add()
+ custom_op.name = 'NpuOptimizer'
+ custom_op.parameter_map["use_off_line"].b = True
+ custom_op.parameter_map["precision_mode"].s = tf.compat.as_bytes("allow_mix_precision")
+ config_proto.graph_options.rewrite_options.remapping = RewriterConfig.OFF
+ session_config = npu_config_proto(config_proto=config_proto)
+```
+
+训练环境准备
+
+- 硬件环境和运行环境准备请参见《[CANN软件安装指南](https://support.huawei.com/enterprise/zh/ascend-computing/cann-pid-251168373?category=installation-update)》
+- 运行以下命令安装依赖。
+```
+pip3 install requirements.txt
+```
+说明:依赖配置文件requirements.txt文件位于模型的根目录
+
+
+快速上手
+
+## 数据集准备
+
+ 模型训练使用StanfordExtra数据集,包含 12,000 张狗的图像以及关键点和分割图,由从斯坦福狗数据集开发的。
+注释在 StanfordExtra 数据集中作为单个 JSON 文件提供,需要填写此表单才能访问它。JSON 文件预计将在本地以stanfordextra_v12.zip.下载文件后,我们可以提取档案。
+```
+tar xf images.tar
+unzip -qq ~/stanfordextra_v12.zip
+```
+
+
+## 模型训练
+- 单击“立即下载”,并选择合适的下载方式下载源码包。
+- 开始训练。
+
+ 1. 启动训练之前,首先要配置程序运行相关环境变量。
+
+ 环境变量配置信息参见:
+
+ [Ascend 910训练平台环境变量设置](https://gitee.com/ascend/modelzoo/wikis/Ascend%20910%E8%AE%AD%E7%BB%83%E5%B9%B3%E5%8F%B0%E7%8E%AF%E5%A2%83%E5%8F%98%E9%87%8F%E8%AE%BE%E7%BD%AE?sort_id=3148819)
+
+
+ 2. 单卡训练
+
+ 2.1 设置单卡训练参数(脚本位于keypoint_detection_ID2516_for_TensorFlow2.X/test/train_full_1p.sh),示例如下。
+
+
+ ```
+ batch_size=64
+ #训练step
+ train_epochs=5
+
+ ```
+
+
+
+ 2.2 单卡训练指令(keypoint_detection_ID2516_for_TensorFlow2.X/test)
+
+ ```
+ 于终端中运行export ASCEND_DEVICE_ID=0 (0~7)以指定单卡训练时使用的卡
+ bash train_full_1p.sh --data_path=xx
+ 数据集提供了一个元数据文件keypoint_definitions.csv,其中指定了有关关键点的附加信息,如颜色信息、动物姿势名称等。我们将把这个文件加载到pandas 数据框中以提取信息以用于可视化目的。配置data_path时需指定为data这一层,例:--data_path=/home/data
+ ├─data
+ ├─Images
+ ├─keypoint_definitions.csv
+ ├─models
+ ├─StanfordExtra_V12
+
+
+ ```
+
+迁移学习指导
+
+- 数据集准备。
+
+ 1. 获取数据。
+ 请参见“快速上手”中的数据集准备
+
+- 模型训练
+
+ 请参考“快速上手”章节
+
+高级参考
+
+## 脚本和示例代码
+
+ ├── README.md //说明文档
+ ├── requirements.txt //依赖
+ ├── modelzoo_level.txt //状态文件
+ ├── keypoint_detection.py //网络结构定义脚本
+ ├── test
+ | |—— train_full_1p.sh //单卡训练脚本
+ | |—— train_performance_1p.sh //单卡训练脚本
+
+
+## 脚本参数
+
+```
+batch_size 训练batch_size
+learning_rate 初始学习率
+epochs 训练epoch数
+precision_mode default="allow_mix_precision", type=str,help='the path to save over dump data'
+over_dump type=ast.literal_eval,help='if or not over detection, default is False'
+data_dump_flag type=ast.literal_eval,help='data dump flag, default is False'
+data_dump_step data dump step, default is 10
+profiling type=ast.literal_eval help='if or not profiling for performance debug, default is False'
+profiling_dump_path type=str, help='the path to save profiling data'
+over_dump_path type=str, help='the path to save over dump data'
+data_dump_path type=str, help='the path to save dump data'
+use_mixlist type=ast.literal_eval,help='use_mixlist flag, default is False'
+fusion_off_flag type=ast.literal_eval,help='fusion_off flag, default is False'
+mixlist_file type=str,help='mixlist file name, default is ops_info.json'
+fusion_off_file type=str,help='fusion_off file name, default is fusion_switch.cfg'
+auto_tune help='auto_tune flag, default is False'
+```
+
+## 训练过程
+
+通过“模型训练”中的训练指令启动单卡训练。
+将训练脚本(train_full_1p.sh)中的data_path设置为训练数据集的路径。具体的流程参见“模型训练”的示例。
diff --git a/TensorFlow2/built-in/keras_sample/keypoint_detection_ID2516_for_TensorFlow2.X/README_BAK.md b/TensorFlow2/built-in/keras_sample/keypoint_detection_ID2516_for_TensorFlow2.X/README_BAK.md
new file mode 100644
index 0000000000000000000000000000000000000000..f08901a53a59eda320b4a29cf826bc14b3a524ad
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/keypoint_detection_ID2516_for_TensorFlow2.X/README_BAK.md
@@ -0,0 +1,533 @@
+# Keypoint Detection with Transfer Learning
+
+**Author:** [Sayak Paul](https://twitter.com/RisingSayak)
+**Date created:** 2021/05/02
+**Last modified:** 2021/05/02
+**Description:** Training a keypoint detector with data augmentation and transfer learning.
+
+
+
[**View in Colab**](https://colab.research.google.com/github/keras-team/keras-io/blob/master/examples/vision/ipynb/keypoint_detection.ipynb) •
[**GitHub source**](https://github.com/keras-team/keras-io/blob/master/examples/vision/keypoint_detection.py)
+
+
+
+Keypoint detection consists of locating key object parts. For example, the key parts
+of our faces include nose tips, eyebrows, eye corners, and so on. These parts help to
+represent the underlying object in a feature-rich manner. Keypoint detection has
+applications that include pose estimation, face detection, etc.
+
+In this example, we will build a keypoint detector using the
+[StanfordExtra dataset](https://github.com/benjiebob/StanfordExtra),
+using transfer learning. This example requires TensorFlow 2.4 or higher,
+as well as [`imgaug`](https://imgaug.readthedocs.io/) library,
+which can be installed using the following command:
+
+
+```python
+!pip install -q -U imgaug
+```
+
+---
+## Data collection
+
+The StanfordExtra dataset contains 12,000 images of dogs together with keypoints and
+segmentation maps. It is developed from the [Stanford dogs dataset](http://vision.stanford.edu/aditya86/ImageNetDogs/).
+It can be downloaded with the command below:
+
+
+```python
+!wget -q http://vision.stanford.edu/aditya86/ImageNetDogs/images.tar
+```
+
+Annotations are provided as a single JSON file in the StanfordExtra dataset and one needs
+to fill [this form](https://forms.gle/sRtbicgxsWvRtRmUA) to get access to it. The
+authors explicitly instruct users not to share the JSON file, and this example respects this wish:
+you should obtain the JSON file yourself.
+
+The JSON file is expected to be locally available as `stanfordextra_v12.zip`.
+
+After the files are downloaded, we can extract the archives.
+
+
+```python
+!tar xf images.tar
+!unzip -qq ~/stanfordextra_v12.zip
+```
+
+---
+## Imports
+
+
+```python
+from tensorflow.keras import layers
+from tensorflow import keras
+import tensorflow as tf
+
+from imgaug.augmentables.kps import KeypointsOnImage
+from imgaug.augmentables.kps import Keypoint
+import imgaug.augmenters as iaa
+
+from PIL import Image
+from sklearn.model_selection import train_test_split
+from matplotlib import pyplot as plt
+import pandas as pd
+import numpy as np
+import json
+import os
+```
+
+---
+## Define hyperparameters
+
+
+```python
+IMG_SIZE = 224
+BATCH_SIZE = 64
+EPOCHS = 5
+NUM_KEYPOINTS = 24 * 2 # 24 pairs each having x and y coordinates
+```
+
+---
+## Load data
+
+The authors also provide a metadata file that specifies additional information about the
+keypoints, like color information, animal pose name, etc. We will load this file in a `pandas`
+dataframe to extract information for visualization purposes.
+
+
+```python
+IMG_DIR = "Images"
+JSON = "StanfordExtra_V12/StanfordExtra_v12.json"
+KEYPOINT_DEF = (
+ "https://github.com/benjiebob/StanfordExtra/raw/master/keypoint_definitions.csv"
+)
+
+# Load the ground-truth annotations.
+with open(JSON) as infile:
+ json_data = json.load(infile)
+
+# Set up a dictionary, mapping all the ground-truth information
+# with respect to the path of the image.
+json_dict = {i["img_path"]: i for i in json_data}
+```
+
+A single entry of `json_dict` looks like the following:
+
+```
+'n02085782-Japanese_spaniel/n02085782_2886.jpg':
+{'img_bbox': [205, 20, 116, 201],
+ 'img_height': 272,
+ 'img_path': 'n02085782-Japanese_spaniel/n02085782_2886.jpg',
+ 'img_width': 350,
+ 'is_multiple_dogs': False,
+ 'joints': [[108.66666666666667, 252.0, 1],
+ [147.66666666666666, 229.0, 1],
+ [163.5, 208.5, 1],
+ [0, 0, 0],
+ [0, 0, 0],
+ [0, 0, 0],
+ [54.0, 244.0, 1],
+ [77.33333333333333, 225.33333333333334, 1],
+ [79.0, 196.5, 1],
+ [0, 0, 0],
+ [0, 0, 0],
+ [0, 0, 0],
+ [0, 0, 0],
+ [0, 0, 0],
+ [150.66666666666666, 86.66666666666667, 1],
+ [88.66666666666667, 73.0, 1],
+ [116.0, 106.33333333333333, 1],
+ [109.0, 123.33333333333333, 1],
+ [0, 0, 0],
+ [0, 0, 0],
+ [0, 0, 0],
+ [0, 0, 0],
+ [0, 0, 0],
+ [0, 0, 0]],
+ 'seg': ...}
+```
+
+In this example, the keys we are interested in are:
+
+* `img_path`
+* `joints`
+
+There are a total of 24 entries present inside `joints`. Each entry has 3 values:
+
+* x-coordinate
+* y-coordinate
+* visibility flag of the keypoints (1 indicates visibility and 0 indicates non-visibility)
+
+As we can see `joints` contain multiple `[0, 0, 0]` entries which denote that those
+keypoints were not labeled. In this example, we will consider both non-visible as well as
+unlabeled keypoints in order to allow mini-batch learning.
+
+
+```python
+# Load the metdata definition file and preview it.
+keypoint_def = pd.read_csv(KEYPOINT_DEF)
+keypoint_def.head()
+
+# Extract the colours and labels.
+colours = keypoint_def["Hex colour"].values.tolist()
+colours = ["#" + colour for colour in colours]
+labels = keypoint_def["Name"].values.tolist()
+
+# Utility for reading an image and for getting its annotations.
+def get_dog(name):
+ data = json_dict[name]
+ img_data = plt.imread(os.path.join(IMG_DIR, data["img_path"]))
+ # If the image is RGBA convert it to RGB.
+ if img_data.shape[-1] == 4:
+ img_data = img_data.astype(np.uint8)
+ img_data = Image.fromarray(img_data)
+ img_data = np.array(img_data.convert("RGB"))
+ data["img_data"] = img_data
+
+ return data
+
+```
+
+---
+## Visualize data
+
+Now, we write a utility function to visualize the images and their keypoints.
+
+
+```python
+# Parts of this code come from here:
+# https://github.com/benjiebob/StanfordExtra/blob/master/demo.ipynb
+def visualize_keypoints(images, keypoints):
+ fig, axes = plt.subplots(nrows=len(images), ncols=2, figsize=(16, 12))
+ [ax.axis("off") for ax in np.ravel(axes)]
+
+ for (ax_orig, ax_all), image, current_keypoint in zip(axes, images, keypoints):
+ ax_orig.imshow(image)
+ ax_all.imshow(image)
+
+ # If the keypoints were formed by `imgaug` then the coordinates need
+ # to be iterated differently.
+ if isinstance(current_keypoint, KeypointsOnImage):
+ for idx, kp in enumerate(current_keypoint.keypoints):
+ ax_all.scatter(
+ [kp.x], [kp.y], c=colours[idx], marker="x", s=50, linewidths=5
+ )
+ else:
+ current_keypoint = np.array(current_keypoint)
+ # Since the last entry is the visibility flag, we discard it.
+ current_keypoint = current_keypoint[:, :2]
+ for idx, (x, y) in enumerate(current_keypoint):
+ ax_all.scatter([x], [y], c=colours[idx], marker="x", s=50, linewidths=5)
+
+ plt.tight_layout(pad=2.0)
+ plt.show()
+
+
+# Select four samples randomly for visualization.
+samples = list(json_dict.keys())
+num_samples = 4
+selected_samples = np.random.choice(samples, num_samples, replace=False)
+
+images, keypoints = [], []
+
+for sample in selected_samples:
+ data = get_dog(sample)
+ image = data["img_data"]
+ keypoint = data["joints"]
+
+ images.append(image)
+ keypoints.append(keypoint)
+
+visualize_keypoints(images, keypoints)
+```
+
+
+
+
+
+
+
+The plots show that we have images of non-uniform sizes, which is expected in most
+real-world scenarios. However, if we resize these images to have a uniform shape (for
+instance (224 x 224)) their ground-truth annotations will also be affected. The same
+applies if we apply any geometric transformation (horizontal flip, for e.g.) to an image.
+Fortunately, `imgaug` provides utilities that can handle this issue.
+In the next section, we will write a data generator inheriting the
+[`keras.utils.Sequence`](https://keras.io/api/utils/python_utils/#sequence-class) class
+that applies data augmentation on batches of data using `imgaug`.
+
+---
+## Prepare data generator
+
+
+```python
+
+class KeyPointsDataset(keras.utils.Sequence):
+ def __init__(self, image_keys, aug, batch_size=BATCH_SIZE, train=True):
+ self.image_keys = image_keys
+ self.aug = aug
+ self.batch_size = batch_size
+ self.train = train
+ self.on_epoch_end()
+
+ def __len__(self):
+ return len(self.image_keys) // self.batch_size
+
+ def on_epoch_end(self):
+ self.indexes = np.arange(len(self.image_keys))
+ if self.train:
+ np.random.shuffle(self.indexes)
+
+ def __getitem__(self, index):
+ indexes = self.indexes[index * self.batch_size : (index + 1) * self.batch_size]
+ image_keys_temp = [self.image_keys[k] for k in indexes]
+ (images, keypoints) = self.__data_generation(image_keys_temp)
+
+ return (images, keypoints)
+
+ def __data_generation(self, image_keys_temp):
+ batch_images = np.empty((self.batch_size, IMG_SIZE, IMG_SIZE, 3), dtype="int")
+ batch_keypoints = np.empty(
+ (self.batch_size, 1, 1, NUM_KEYPOINTS), dtype="float32"
+ )
+
+ for i, key in enumerate(image_keys_temp):
+ data = get_dog(key)
+ current_keypoint = np.array(data["joints"])[:, :2]
+ kps = []
+
+ # To apply our data augmentation pipeline, we first need to
+ # form Keypoint objects with the original coordinates.
+ for j in range(0, len(current_keypoint)):
+ kps.append(Keypoint(x=current_keypoint[j][0], y=current_keypoint[j][1]))
+
+ # We then project the original image and its keypoint coordinates.
+ current_image = data["img_data"]
+ kps_obj = KeypointsOnImage(kps, shape=current_image.shape)
+
+ # Apply the augmentation pipeline.
+ (new_image, new_kps_obj) = self.aug(image=current_image, keypoints=kps_obj)
+ batch_images[i,] = new_image
+
+ # Parse the coordinates from the new keypoint object.
+ kp_temp = []
+ for keypoint in new_kps_obj:
+ kp_temp.append(np.nan_to_num(keypoint.x))
+ kp_temp.append(np.nan_to_num(keypoint.y))
+
+ # More on why this reshaping later.
+ batch_keypoints[i,] = np.array(kp_temp).reshape(1, 1, 24 * 2)
+
+ # Scale the coordinates to [0, 1] range.
+ batch_keypoints = batch_keypoints / IMG_SIZE
+
+ return (batch_images, batch_keypoints)
+
+```
+
+To know more about how to operate with keypoints in `imgaug` check out
+[this document](https://imgaug.readthedocs.io/en/latest/source/examples_keypoints.html).
+
+---
+## Define augmentation transforms
+
+
+```python
+train_aug = iaa.Sequential(
+ [
+ iaa.Resize(IMG_SIZE, interpolation="linear"),
+ iaa.Fliplr(0.3),
+ # `Sometimes()` applies a function randomly to the inputs with
+ # a given probability (0.3, in this case).
+ iaa.Sometimes(0.3, iaa.Affine(rotate=10, scale=(0.5, 0.7))),
+ ]
+)
+
+test_aug = iaa.Sequential([iaa.Resize(IMG_SIZE, interpolation="linear")])
+```
+
+---
+## Create training and validation splits
+
+
+```python
+np.random.shuffle(samples)
+train_keys, validation_keys = (
+ samples[int(len(samples) * 0.15) :],
+ samples[: int(len(samples) * 0.15)],
+)
+
+```
+
+---
+## Data generator investigation
+
+
+```python
+train_dataset = KeyPointsDataset(train_keys, train_aug)
+validation_dataset = KeyPointsDataset(validation_keys, test_aug, train=False)
+
+print(f"Total batches in training set: {len(train_dataset)}")
+print(f"Total batches in validation set: {len(validation_dataset)}")
+
+sample_images, sample_keypoints = next(iter(train_dataset))
+assert sample_keypoints.max() == 1.0
+assert sample_keypoints.min() == 0.0
+
+sample_keypoints = sample_keypoints[:4].reshape(-1, 24, 2) * IMG_SIZE
+visualize_keypoints(sample_images[:4], sample_keypoints)
+```
+
+
+```
+Total batches in training set: 166
+Total batches in validation set: 29
+
+```
+
+
+
+
+
+
+---
+## Model building
+
+The [Stanford dogs dataset](http://vision.stanford.edu/aditya86/ImageNetDogs/) (on which
+the StanfordExtra dataset is based) was built using the [ImageNet-1k dataset](http://image-net.org/).
+So, it is likely that the models pretrained on the ImageNet-1k dataset would be useful
+for this task. We will use a MobileNetV2 pre-trained on this dataset as a backbone to
+extract meaningful features from the images and then pass those to a custom regression
+head for predicting coordinates.
+
+
+```python
+
+def get_model():
+ # Load the pre-trained weights of MobileNetV2 and freeze the weights
+ backbone = keras.applications.MobileNetV2(
+ weights="imagenet", include_top=False, input_shape=(IMG_SIZE, IMG_SIZE, 3)
+ )
+ backbone.trainable = False
+
+ inputs = layers.Input((IMG_SIZE, IMG_SIZE, 3))
+ x = keras.applications.mobilenet_v2.preprocess_input(inputs)
+ x = backbone(x)
+ x = layers.Dropout(0.3)(x)
+ x = layers.SeparableConv2D(
+ NUM_KEYPOINTS, kernel_size=5, strides=1, activation="relu"
+ )(x)
+ outputs = layers.SeparableConv2D(
+ NUM_KEYPOINTS, kernel_size=3, strides=1, activation="sigmoid"
+ )(x)
+
+ return keras.Model(inputs, outputs, name="keypoint_detector")
+
+```
+
+Our custom network is fully-convolutional which makes it more parameter-friendly than the
+same version of the network having fully-connected dense layers.
+
+
+```python
+get_model().summary()
+```
+
+
+```
+Model: "keypoint_detector"
+_________________________________________________________________
+Layer (type) Output Shape Param #
+=================================================================
+input_2 (InputLayer) [(None, 224, 224, 3)] 0
+_________________________________________________________________
+tf.math.truediv (TFOpLambda) (None, 224, 224, 3) 0
+_________________________________________________________________
+tf.math.subtract (TFOpLambda (None, 224, 224, 3) 0
+_________________________________________________________________
+mobilenetv2_1.00_224 (Functi (None, 7, 7, 1280) 2257984
+_________________________________________________________________
+dropout (Dropout) (None, 7, 7, 1280) 0
+_________________________________________________________________
+separable_conv2d (SeparableC (None, 3, 3, 48) 93488
+_________________________________________________________________
+separable_conv2d_1 (Separabl (None, 1, 1, 48) 2784
+=================================================================
+Total params: 2,354,256
+Trainable params: 96,272
+Non-trainable params: 2,257,984
+_________________________________________________________________
+
+```
+
+Notice the output shape of the network: `(None, 1, 1, 48)`. This is why we have reshaped
+the coordinates as: `batch_keypoints[i, :] = np.array(kp_temp).reshape(1, 1, 24 * 2)`.
+
+---
+## Model compilation and training
+
+For this example, we will train the network only for five epochs.
+
+
+```python
+model = get_model()
+model.compile(loss="mse", optimizer=keras.optimizers.Adam(1e-4))
+model.fit(train_dataset, validation_data=validation_dataset, epochs=EPOCHS)
+```
+
+
+```
+Epoch 1/5
+166/166 [==============================] - 85s 486ms/step - loss: 0.1087 - val_loss: 0.0950
+Epoch 2/5
+166/166 [==============================] - 78s 471ms/step - loss: 0.0830 - val_loss: 0.0778
+Epoch 3/5
+166/166 [==============================] - 78s 468ms/step - loss: 0.0778 - val_loss: 0.0739
+Epoch 4/5
+166/166 [==============================] - 78s 470ms/step - loss: 0.0753 - val_loss: 0.0711
+Epoch 5/5
+166/166 [==============================] - 78s 468ms/step - loss: 0.0735 - val_loss: 0.0692
+
+
+
+```
+
+---
+## Make predictions and visualize them
+
+
+```python
+sample_val_images, sample_val_keypoints = next(iter(validation_dataset))
+sample_val_images = sample_val_images[:4]
+sample_val_keypoints = sample_val_keypoints[:4].reshape(-1, 24, 2) * IMG_SIZE
+predictions = model.predict(sample_val_images).reshape(-1, 24, 2) * IMG_SIZE
+
+# Ground-truth
+visualize_keypoints(sample_val_images, sample_val_keypoints)
+
+# Predictions
+visualize_keypoints(sample_val_images, predictions)
+```
+
+
+
+
+
+
+
+
+
+
+
+
+
+Predictions will likely improve with more training.
+
+---
+## Going further
+
+* Try using other augmentation transforms from `imgaug` to investigate how that changes
+the results.
+* Here, we transferred the features from the pre-trained network linearly that is we did
+not [fine-tune](https://keras.io/guides/transfer_learning/) it. You are encouraged to fine-tune it on this task and see if that
+improves the performance. You can also try different architectures and see how they
+affect the final performance.
diff --git a/TensorFlow2/built-in/keras_sample/keypoint_detection_ID2516_for_TensorFlow2.X/keypoint_detection.py b/TensorFlow2/built-in/keras_sample/keypoint_detection_ID2516_for_TensorFlow2.X/keypoint_detection.py
new file mode 100644
index 0000000000000000000000000000000000000000..6f41f747ef59c8d3457f9540e0158eaed1877611
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/keypoint_detection_ID2516_for_TensorFlow2.X/keypoint_detection.py
@@ -0,0 +1,970 @@
+"""
+Title: Keypoint Detection with Transfer Learning
+Author: [Sayak Paul](https://twitter.com/RisingSayak)
+Date created: 2021/05/02
+Last modified: 2021/05/02
+Description: Training a keypoint detector with data augmentation and transfer learning.
+"""
+"""
+Keypoint detection consists of locating key object parts. For example, the key parts
+of our faces include nose tips, eyebrows, eye corners, and so on. These parts help to
+represent the underlying object in a feature-rich manner. Keypoint detection has
+applications that include pose estimation, face detection, etc.
+
+In this example, we will build a keypoint detector using the
+[StanfordExtra dataset](https://github.com/benjiebob/StanfordExtra),
+using transfer learning. This example requires TensorFlow 2.4 or higher,
+as well as [`imgaug`](https://imgaug.readthedocs.io/) library,
+which can be installed using the following command:
+"""
+
+"""shell
+pip install -q -U imgaug
+"""
+
+"""
+## Data collection
+"""
+
+"""
+The StanfordExtra dataset contains 12,000 images of dogs together with keypoints and
+segmentation maps. It is developed from the [Stanford dogs dataset](http://vision.stanford.edu/aditya86/ImageNetDogs/).
+It can be downloaded with the command below:
+"""
+
+"""shell
+wget -q http://vision.stanford.edu/aditya86/ImageNetDogs/images.tar
+"""
+
+"""
+Annotations are provided as a single JSON file in the StanfordExtra dataset and one needs
+to fill [this form](https://forms.gle/sRtbicgxsWvRtRmUA) to get access to it. The
+authors explicitly instruct users not to share the JSON file, and this example respects this wish:
+you should obtain the JSON file yourself.
+
+The JSON file is expected to be locally available as `stanfordextra_v12.zip`.
+
+After the files are downloaded, we can extract the archives.
+"""
+
+"""shell
+tar xf images.tar
+unzip -qq ~/stanfordextra_v12.zip
+"""
+
+"""
+## Imports
+"""
+
+from tensorflow.keras import layers
+from tensorflow import keras
+import tensorflow as tf
+
+from imgaug.augmentables.kps import KeypointsOnImage
+from imgaug.augmentables.kps import Keypoint
+import imgaug.augmenters as iaa
+
+from PIL import Image
+from sklearn.model_selection import train_test_split
+from matplotlib import pyplot as plt
+import pandas as pd
+import numpy as np
+import json
+import os
+import ast
+import argparse
+import npu_device
+
+# npu_device.open().as_default()
+
+def parse_args():
+ parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
+ parser.add_argument('--data_path', default='/root/keypoint_detection', help="""directory to data""")
+ parser.add_argument('--batch_size', default=64, type=int, help="""batch size for 1p""")
+ parser.add_argument('--epochs', default=5, type=int, help="""epochs""")
+ parser.add_argument('--static', default=0, type=int, help="""static""")
+ parser.add_argument('--precision_mode', default="allow_mix_precision", type=str,help='the path to save over dump data')
+ parser.add_argument('--over_dump', dest='over_dump', type=ast.literal_eval,help='if or not over detection, default is False')
+ parser.add_argument('--data_dump_flag', dest='data_dump_flag', type=ast.literal_eval,help='data dump flag, default is False')
+ parser.add_argument('--data_dump_step', default="10",help='data dump step, default is 10')
+ parser.add_argument('--profiling', dest='profiling', type=ast.literal_eval,help='if or not profiling for performance debug, default is False')
+ parser.add_argument('--profiling_dump_path', default="/home/data", type=str,help='the path to save profiling data')
+ parser.add_argument('--over_dump_path', default="/home/data", type=str,help='the path to save over dump data')
+ parser.add_argument('--data_dump_path', default="/home/data", type=str,help='the path to save dump data')
+ parser.add_argument('--use_mixlist', dest='use_mixlist', type=ast.literal_eval, help='use_mixlist flag, default is False')
+ parser.add_argument('--fusion_off_flag', dest='fusion_off_flag', type=ast.literal_eval,help='fusion_off flag, default is False')
+ parser.add_argument('--mixlist_file', default="ops_info.json", type=str,help='mixlist file name, default is ops_info.json')
+ parser.add_argument('--fusion_off_file', default="fusion_switch.cfg", type=str,help='fusion_off file name, default is fusion_switch.cfg')
+ parser.add_argument('--auto_tune', dest='auto_tune', type=ast.literal_eval,help='auto_tune flag, default is False')
+ args, unknown_args = parser.parse_known_args()
+ if len(unknown_args) > 0:
+ for bad_arg in unknown_args:
+ print("ERROR: Unknown command line arg: %s" % bad_arg)
+ raise ValueError("Invalid command line arg(s)")
+ return args
+
+
+args = parse_args()
+
+def npu_config():
+ if args.data_dump_flag:
+ npu_device.global_options().dump_config.enable_dump = True
+ npu_device.global_options().dump_config.dump_path = args.data_dump_path
+ npu_device.global_options().dump_config.dump_step = args.data_dump_step
+ npu_device.global_options().dump_config.dump_mode = "all"
+
+ if args.over_dump:
+ npu_device.global_options().dump_config.enable_dump_debug = True
+ npu_device.global_options().dump_config.dump_path = args.over_dump_path
+ npu_device.global_options().dump_config.dump_debug_mode = "all"
+
+ if args.profiling:
+ npu_device.global_options().profiling_config.enable_profiling = True
+ profiling_options = '{"output":"' + args.profiling_dump_path + '", \
+ "training_trace":"on", \
+ "task_trace":"on", \
+ "aicpu":"on", \
+ "aic_metrics":"PipeUtilization",\
+ "fp_point":"", \
+ "bp_point":""}'
+ npu_device.global_options().profiling_config.profiling_options = profiling_options
+ npu_device.global_options().precision_mode = args.precision_mode
+ if args.use_mixlist and args.precision_mode=='allow_mix_precision':
+ npu_device.global_options().modify_mixlist=args.mixlist_file
+ if args.fusion_off_flag:
+ npu_device.global_options().fusion_switch_file=args.fusion_off_file
+ if args.auto_tune:
+ npu_device.global_options().auto_tune_mode="RL,GA"
+ npu_device.open().as_default()
+#===============================NPU Migration=========================================
+npu_config()
+
+"""
+## Define hyperparameters
+"""
+
+IMG_SIZE = 224
+BATCH_SIZE = args.batch_size # 64
+EPOCHS = args.epochs # 5
+NUM_KEYPOINTS = 24 * 2 # 24 pairs each having x and y coordinates
+
+"""
+## Load data
+
+The authors also provide a metadata file that specifies additional information about the
+keypoints, like color information, animal pose name, etc. We will load this file in a `pandas`
+dataframe to extract information for visualization purposes.
+"""
+
+IMG_DIR = os.path.join(args.data_path, "Images")
+JSON = os.path.join(args.data_path, "StanfordExtra_V12/StanfordExtra_v12.json")
+KEYPOINT_DEF = (
+ # "https://github.com/benjiebob/StanfordExtra/raw/master/keypoint_definitions.csv"
+ os.path.join(args.data_path, "keypoint_definitions.csv")
+)
+
+# Load the ground-truth annotations.
+with open(JSON) as infile:
+ json_data = json.load(infile)
+
+# Set up a dictionary, mapping all the ground-truth information
+# with respect to the path of the image.
+json_dict = {i["img_path"]: i for i in json_data}
+
+
+"""
+A single entry of `json_dict` looks like the following:
+
+```
+'n02085782-Japanese_spaniel/n02085782_2886.jpg':
+{'img_bbox': [205, 20, 116, 201],
+ 'img_height': 272,
+ 'img_path': 'n02085782-Japanese_spaniel/n02085782_2886.jpg',
+ 'img_width': 350,
+ 'is_multiple_dogs': False,
+ 'joints': [[108.66666666666667, 252.0, 1],
+ [147.66666666666666, 229.0, 1],
+ [163.5, 208.5, 1],
+ [0, 0, 0],
+ [0, 0, 0],
+ [0, 0, 0],
+ [54.0, 244.0, 1],
+ [77.33333333333333, 225.33333333333334, 1],
+ [79.0, 196.5, 1],
+ [0, 0, 0],
+ [0, 0, 0],
+ [0, 0, 0],
+ [0, 0, 0],
+ [0, 0, 0],
+ [150.66666666666666, 86.66666666666667, 1],
+ [88.66666666666667, 73.0, 1],
+ [116.0, 106.33333333333333, 1],
+ [109.0, 123.33333333333333, 1],
+ [0, 0, 0],
+ [0, 0, 0],
+ [0, 0, 0],
+ [0, 0, 0],
+ [0, 0, 0],
+ [0, 0, 0]],
+ 'seg': ...}
+```
+"""
+
+"""
+In this example, the keys we are interested in are:
+
+* `img_path`
+* `joints`
+
+There are a total of 24 entries present inside `joints`. Each entry has 3 values:
+
+* x-coordinate
+* y-coordinate
+* visibility flag of the keypoints (1 indicates visibility and 0 indicates non-visibility)
+
+As we can see `joints` contain multiple `[0, 0, 0]` entries which denote that those
+keypoints were not labeled. In this example, we will consider both non-visible as well as
+unlabeled keypoints in order to allow mini-batch learning.
+"""
+
+# Load the metdata definition file and preview it.
+keypoint_def = pd.read_csv(KEYPOINT_DEF)
+keypoint_def.head()
+
+# Extract the colours and labels.
+colours = keypoint_def["Hex colour"].values.tolist()
+colours = ["#" + colour for colour in colours]
+labels = keypoint_def["Name"].values.tolist()
+
+
+# Utility for reading an image and for getting its annotations.
+def get_dog(name):
+ data = json_dict[name]
+ img_data = plt.imread(os.path.join(IMG_DIR, data["img_path"]))
+ # If the image is RGBA convert it to RGB.
+ if img_data.shape[-1] == 4:
+ img_data = img_data.astype(np.uint8)
+ img_data = Image.fromarray(img_data)
+ img_data = np.array(img_data.convert("RGB"))
+ data["img_data"] = img_data
+
+ return data
+
+
+"""
+## Visualize data
+
+Now, we write a utility function to visualize the images and their keypoints.
+"""
+
+
+# Parts of this code come from here:
+# https://github.com/benjiebob/StanfordExtra/blob/master/demo.ipynb
+def visualize_keypoints(images, keypoints):
+ fig, axes = plt.subplots(nrows=len(images), ncols=2, figsize=(16, 12))
+ [ax.axis("off") for ax in np.ravel(axes)]
+
+ for (ax_orig, ax_all), image, current_keypoint in zip(axes, images, keypoints):
+ ax_orig.imshow(image)
+ ax_all.imshow(image)
+
+ # If the keypoints were formed by `imgaug` then the coordinates need
+ # to be iterated differently.
+ if isinstance(current_keypoint, KeypointsOnImage):
+ for idx, kp in enumerate(current_keypoint.keypoints):
+ ax_all.scatter(
+ [kp.x], [kp.y], c=colours[idx], marker="x", s=50, linewidths=5
+ )
+ else:
+ current_keypoint = np.array(current_keypoint)
+ # Since the last entry is the visibility flag, we discard it.
+ current_keypoint = current_keypoint[:, :2]
+ for idx, (x, y) in enumerate(current_keypoint):
+ ax_all.scatter([x], [y], c=colours[idx], marker="x", s=50, linewidths=5)
+
+ plt.tight_layout(pad=2.0)
+ plt.show()
+
+
+# Select four samples randomly for visualization.
+samples = list(json_dict.keys())
+num_samples = 4
+selected_samples = np.random.choice(samples, num_samples, replace=False)
+
+images, keypoints = [], []
+
+for sample in selected_samples:
+ data = get_dog(sample)
+ image = data["img_data"]
+ keypoint = data["joints"]
+
+ images.append(image)
+ keypoints.append(keypoint)
+
+visualize_keypoints(images, keypoints)
+
+"""
+The plots show that we have images of non-uniform sizes, which is expected in most
+real-world scenarios. However, if we resize these images to have a uniform shape (for
+instance (224 x 224)) their ground-truth annotations will also be affected. The same
+applies if we apply any geometric transformation (horizontal flip, for e.g.) to an image.
+Fortunately, `imgaug` provides utilities that can handle this issue.
+In the next section, we will write a data generator inheriting the
+[`keras.utils.Sequence`](https://keras.io/api/utils/python_utils/#sequence-class) class
+that applies data augmentation on batches of data using `imgaug`.
+"""
+
+"""
+## Prepare data generator
+"""
+
+
+class KeyPointsDataset(keras.utils.Sequence):
+ def __init__(self, image_keys, aug, batch_size=BATCH_SIZE, train=True):
+ self.image_keys = image_keys
+ self.aug = aug
+ self.batch_size = batch_size
+ self.train = train
+ self.on_epoch_end()
+
+ def __len__(self):
+ return len(self.image_keys) // self.batch_size
+
+ def on_epoch_end(self):
+ self.indexes = np.arange(len(self.image_keys))
+ if self.train:
+ np.random.shuffle(self.indexes)
+
+ def __getitem__(self, index):
+ indexes = self.indexes[index * self.batch_size: (index + 1) * self.batch_size]
+ image_keys_temp = [self.image_keys[k] for k in indexes]
+ (images, keypoints) = self.__data_generation(image_keys_temp)
+
+ return (images, keypoints)
+
+ def __data_generation(self, image_keys_temp):
+ batch_images = np.empty((self.batch_size, IMG_SIZE, IMG_SIZE, 3), dtype="int")
+ batch_keypoints = np.empty(
+ (self.batch_size, 1, 1, NUM_KEYPOINTS), dtype="float32"
+ )
+
+ for i, key in enumerate(image_keys_temp):
+ data = get_dog(key)
+ current_keypoint = np.array(data["joints"])[:, :2]
+ kps = []
+
+ # To apply our data augmentation pipeline, we first need to
+ # form Keypoint objects with the original coordinates.
+ for j in range(0, len(current_keypoint)):
+ kps.append(Keypoint(x=current_keypoint[j][0], y=current_keypoint[j][1]))
+
+ # We then project the original image and its keypoint coordinates.
+ current_image = data["img_data"]
+ kps_obj = KeypointsOnImage(kps, shape=current_image.shape)
+
+ # Apply the augmentation pipeline.
+ (new_image, new_kps_obj) = self.aug(image=current_image, keypoints=kps_obj)
+ batch_images[i,] = new_image
+
+ # Parse the coordinates from the new keypoint object.
+ kp_temp = []
+ for keypoint in new_kps_obj:
+ kp_temp.append(np.nan_to_num(keypoint.x))
+ kp_temp.append(np.nan_to_num(keypoint.y))
+
+ # More on why this reshaping later.
+ batch_keypoints[i,] = np.array(kp_temp).reshape(1, 1, 24 * 2)
+
+ # Scale the coordinates to [0, 1] range.
+ batch_keypoints = batch_keypoints / IMG_SIZE
+
+ return (batch_images, batch_keypoints)
+
+
+"""
+To know more about how to operate with keypoints in `imgaug` check out
+[this document](https://imgaug.readthedocs.io/en/latest/source/examples_keypoints.html).
+"""
+
+"""
+## Define augmentation transforms
+"""
+
+train_aug = iaa.Sequential(
+ [
+ iaa.Resize(IMG_SIZE, interpolation="linear"),
+ iaa.Fliplr(0.3),
+ # `Sometimes()` applies a function randomly to the inputs with
+ # a given probability (0.3, in this case).
+ iaa.Sometimes(0.3, iaa.Affine(rotate=10, scale=(0.5, 0.7))),
+ ]
+)
+
+test_aug = iaa.Sequential([iaa.Resize(IMG_SIZE, interpolation="linear")])
+
+"""
+## Create training and validation splits
+"""
+
+np.random.shuffle(samples)
+
+train_keys, validation_keys = (
+ samples[int(len(samples) * 0.15):],
+ samples[: int(len(samples) * 0.15)]
+ )
+
+"""
+## Data generator investigation
+"""
+
+train_dataset = KeyPointsDataset(train_keys, train_aug)
+print('-------------------------------------------------------------------TTTTTTTTTTTTTTTTType')
+#print(train_dataset.shape)
+print(type(train_dataset))
+if args.static==1:
+ train_dataset=(np.array(train_dataset[0][:4096]),[np.array(train_dataset[1][:4096]), np.array(train_dataset[2][:4096]), np.array(train_dataset[3][:4096])])
+validation_dataset = KeyPointsDataset(validation_keys, test_aug, train=False)
+
+print(f"Total batches in training set: {len(train_dataset)}")
+print(f"Total batches in validation set: {len(validation_dataset)}")
+
+sample_images, sample_keypoints = next(iter(train_dataset))
+assert sample_keypoints.max() == 1.0
+assert sample_keypoints.min() == 0.0
+
+sample_keypoints = sample_keypoints[:4].reshape(-1, 24, 2) * IMG_SIZE
+visualize_keypoints(sample_images[:4], sample_keypoints)
+
+"""
+## Model building
+
+The [Stanford dogs dataset](http://vision.stanford.edu/aditya86/ImageNetDogs/) (on which
+the StanfordExtra dataset is based) was built using the [ImageNet-1k dataset](http://image-net.org/).
+So, it is likely that the models pretrained on the ImageNet-1k dataset would be useful
+for this task. We will use a MobileNetV2 pre-trained on this dataset as a backbone to
+extract meaningful features from the images and then pass those to a custom regression
+head for predicting coordinates.
+"""
+
+import tensorflow.compat.v2 as tf
+
+from keras import backend
+from keras.applications import imagenet_utils
+from keras.engine import training
+from keras.layers import VersionAwareLayers
+from keras.utils import data_utils
+from keras.utils import layer_utils
+from tensorflow.python.platform import tf_logging as logging
+from tensorflow.python.util.tf_export import keras_export
+
+BASE_WEIGHT_PATH = ('https://storage.googleapis.com/tensorflow/'
+ 'keras-applications/mobilenet_v2/')
+layers = None
+
+
+@keras_export('keras.applications.mobilenet_v2.MobileNetV2',
+ 'keras.applications.MobileNetV2')
+def MobileNetV2(input_shape=None,
+ alpha=1.0,
+ include_top=True,
+ weights='imagenet',
+ input_tensor=None,
+ pooling=None,
+ classes=1000,
+ classifier_activation='softmax',
+ cache_dir=None,
+ **kwargs):
+ """Instantiates the MobileNetV2 architecture.
+
+ MobileNetV2 is very similar to the original MobileNet,
+ except that it uses inverted residual blocks with
+ bottlenecking features. It has a drastically lower
+ parameter count than the original MobileNet.
+ MobileNets support any input size greater
+ than 32 x 32, with larger image sizes
+ offering better performance.
+
+ Reference:
+ - [MobileNetV2: Inverted Residuals and Linear Bottlenecks](
+ https://arxiv.org/abs/1801.04381) (CVPR 2018)
+
+ This function returns a Keras image classification model,
+ optionally loaded with weights pre-trained on ImageNet.
+
+ For image classification use cases, see
+ [this page for detailed examples](
+ https://keras.io/api/applications/#usage-examples-for-image-classification-models).
+
+ For transfer learning use cases, make sure to read the
+ [guide to transfer learning & fine-tuning](
+ https://keras.io/guides/transfer_learning/).
+
+ Note: each Keras Application expects a specific kind of input preprocessing.
+ For MobileNetV2, call `tf.keras.applications.mobilenet_v2.preprocess_input`
+ on your inputs before passing them to the model.
+ `mobilenet_v2.preprocess_input` will scale input pixels between -1 and 1.
+
+ Args:
+ input_shape: Optional shape tuple, to be specified if you would
+ like to use a model with an input image resolution that is not
+ (224, 224, 3).
+ It should have exactly 3 inputs channels (224, 224, 3).
+ You can also omit this option if you would like
+ to infer input_shape from an input_tensor.
+ If you choose to include both input_tensor and input_shape then
+ input_shape will be used if they match, if the shapes
+ do not match then we will throw an error.
+ E.g. `(160, 160, 3)` would be one valid value.
+ alpha: Float between 0 and 1. controls the width of the network.
+ This is known as the width multiplier in the MobileNetV2 paper,
+ but the name is kept for consistency with `applications.MobileNetV1`
+ model in Keras.
+ - If `alpha` < 1.0, proportionally decreases the number
+ of filters in each layer.
+ - If `alpha` > 1.0, proportionally increases the number
+ of filters in each layer.
+ - If `alpha` = 1.0, default number of filters from the paper
+ are used at each layer.
+ include_top: Boolean, whether to include the fully-connected
+ layer at the top of the network. Defaults to `True`.
+ weights: String, one of `None` (random initialization),
+ 'imagenet' (pre-training on ImageNet),
+ or the path to the weights file to be loaded.
+ input_tensor: Optional Keras tensor (i.e. output of
+ `layers.Input()`)
+ to use as image input for the model.
+ pooling: String, optional pooling mode for feature extraction
+ when `include_top` is `False`.
+ - `None` means that the output of the model
+ will be the 4D tensor output of the
+ last convolutional block.
+ - `avg` means that global average pooling
+ will be applied to the output of the
+ last convolutional block, and thus
+ the output of the model will be a
+ 2D tensor.
+ - `max` means that global max pooling will
+ be applied.
+ classes: Integer, optional number of classes to classify images
+ into, only to be specified if `include_top` is True, and
+ if no `weights` argument is specified.
+ classifier_activation: A `str` or callable. The activation function to use
+ on the "top" layer. Ignored unless `include_top=True`. Set
+ `classifier_activation=None` to return the logits of the "top" layer.
+ When loading pretrained weights, `classifier_activation` can only
+ be `None` or `"softmax"`.
+ **kwargs: For backwards compatibility only.
+
+ Returns:
+ A `keras.Model` instance.
+ """
+ global layers
+ if 'layers' in kwargs:
+ layers = kwargs.pop('layers')
+ else:
+ layers = VersionAwareLayers()
+ if kwargs:
+ raise ValueError('Unknown argument(s): %s' % (kwargs,))
+ if not (weights in {'imagenet', None} or tf.io.gfile.exists(weights)):
+ raise ValueError('The `weights` argument should be either '
+ '`None` (random initialization), `imagenet` '
+ '(pre-training on ImageNet), '
+ 'or the path to the weights file to be loaded.')
+
+ if weights == 'imagenet' and include_top and classes != 1000:
+ raise ValueError('If using `weights` as `"imagenet"` with `include_top` '
+ 'as true, `classes` should be 1000')
+
+ # Determine proper input shape and default size.
+ # If both input_shape and input_tensor are used, they should match
+ if input_shape is not None and input_tensor is not None:
+ try:
+ is_input_t_tensor = backend.is_keras_tensor(input_tensor)
+ except ValueError:
+ try:
+ is_input_t_tensor = backend.is_keras_tensor(
+ layer_utils.get_source_inputs(input_tensor))
+ except ValueError:
+ raise ValueError('input_tensor: ', input_tensor,
+ 'is not type input_tensor')
+ if is_input_t_tensor:
+ if backend.image_data_format() == 'channels_first':
+ if backend.int_shape(input_tensor)[1] != input_shape[1]:
+ raise ValueError('input_shape: ', input_shape, 'and input_tensor: ',
+ input_tensor,
+ 'do not meet the same shape requirements')
+ else:
+ if backend.int_shape(input_tensor)[2] != input_shape[1]:
+ raise ValueError('input_shape: ', input_shape, 'and input_tensor: ',
+ input_tensor,
+ 'do not meet the same shape requirements')
+ else:
+ raise ValueError('input_tensor specified: ', input_tensor,
+ 'is not a keras tensor')
+
+ # If input_shape is None, infer shape from input_tensor
+ if input_shape is None and input_tensor is not None:
+
+ try:
+ backend.is_keras_tensor(input_tensor)
+ except ValueError:
+ raise ValueError('input_tensor: ', input_tensor, 'is type: ',
+ type(input_tensor), 'which is not a valid type')
+
+ if input_shape is None and not backend.is_keras_tensor(input_tensor):
+ default_size = 224
+ elif input_shape is None and backend.is_keras_tensor(input_tensor):
+ if backend.image_data_format() == 'channels_first':
+ rows = backend.int_shape(input_tensor)[2]
+ cols = backend.int_shape(input_tensor)[3]
+ else:
+ rows = backend.int_shape(input_tensor)[1]
+ cols = backend.int_shape(input_tensor)[2]
+
+ if rows == cols and rows in [96, 128, 160, 192, 224]:
+ default_size = rows
+ else:
+ default_size = 224
+
+ # If input_shape is None and no input_tensor
+ elif input_shape is None:
+ default_size = 224
+
+ # If input_shape is not None, assume default size
+ else:
+ if backend.image_data_format() == 'channels_first':
+ rows = input_shape[1]
+ cols = input_shape[2]
+ else:
+ rows = input_shape[0]
+ cols = input_shape[1]
+
+ if rows == cols and rows in [96, 128, 160, 192, 224]:
+ default_size = rows
+ else:
+ default_size = 224
+
+ input_shape = imagenet_utils.obtain_input_shape(
+ input_shape,
+ default_size=default_size,
+ min_size=32,
+ data_format=backend.image_data_format(),
+ require_flatten=include_top,
+ weights=weights)
+
+ if backend.image_data_format() == 'channels_last':
+ row_axis, col_axis = (0, 1)
+ else:
+ row_axis, col_axis = (1, 2)
+ rows = input_shape[row_axis]
+ cols = input_shape[col_axis]
+
+ if weights == 'imagenet':
+ if alpha not in [0.35, 0.50, 0.75, 1.0, 1.3, 1.4]:
+ raise ValueError('If imagenet weights are being loaded, '
+ 'alpha can be one of `0.35`, `0.50`, `0.75`, '
+ '`1.0`, `1.3` or `1.4` only.')
+
+ if rows != cols or rows not in [96, 128, 160, 192, 224]:
+ rows = 224
+ logging.warning('`input_shape` is undefined or non-square, '
+ 'or `rows` is not in [96, 128, 160, 192, 224].'
+ ' Weights for input shape (224, 224) will be'
+ ' loaded as the default.')
+
+ if input_tensor is None:
+ img_input = layers.Input(shape=input_shape)
+ else:
+ if not backend.is_keras_tensor(input_tensor):
+ img_input = layers.Input(tensor=input_tensor, shape=input_shape)
+ else:
+ img_input = input_tensor
+
+ channel_axis = 1 if backend.image_data_format() == 'channels_first' else -1
+
+ first_block_filters = _make_divisible(32 * alpha, 8)
+ x = layers.Conv2D(
+ first_block_filters,
+ kernel_size=3,
+ strides=(2, 2),
+ padding='same',
+ use_bias=False,
+ name='Conv1')(img_input)
+ x = layers.BatchNormalization(
+ axis=channel_axis, epsilon=1e-3, momentum=0.999, name='bn_Conv1')(
+ x)
+ x = layers.ReLU(6., name='Conv1_relu')(x)
+
+ x = _inverted_res_block(
+ x, filters=16, alpha=alpha, stride=1, expansion=1, block_id=0)
+
+ x = _inverted_res_block(
+ x, filters=24, alpha=alpha, stride=2, expansion=6, block_id=1)
+ x = _inverted_res_block(
+ x, filters=24, alpha=alpha, stride=1, expansion=6, block_id=2)
+
+ x = _inverted_res_block(
+ x, filters=32, alpha=alpha, stride=2, expansion=6, block_id=3)
+ x = _inverted_res_block(
+ x, filters=32, alpha=alpha, stride=1, expansion=6, block_id=4)
+ x = _inverted_res_block(
+ x, filters=32, alpha=alpha, stride=1, expansion=6, block_id=5)
+
+ x = _inverted_res_block(
+ x, filters=64, alpha=alpha, stride=2, expansion=6, block_id=6)
+ x = _inverted_res_block(
+ x, filters=64, alpha=alpha, stride=1, expansion=6, block_id=7)
+ x = _inverted_res_block(
+ x, filters=64, alpha=alpha, stride=1, expansion=6, block_id=8)
+ x = _inverted_res_block(
+ x, filters=64, alpha=alpha, stride=1, expansion=6, block_id=9)
+
+ x = _inverted_res_block(
+ x, filters=96, alpha=alpha, stride=1, expansion=6, block_id=10)
+ x = _inverted_res_block(
+ x, filters=96, alpha=alpha, stride=1, expansion=6, block_id=11)
+ x = _inverted_res_block(
+ x, filters=96, alpha=alpha, stride=1, expansion=6, block_id=12)
+
+ x = _inverted_res_block(
+ x, filters=160, alpha=alpha, stride=2, expansion=6, block_id=13)
+ x = _inverted_res_block(
+ x, filters=160, alpha=alpha, stride=1, expansion=6, block_id=14)
+ x = _inverted_res_block(
+ x, filters=160, alpha=alpha, stride=1, expansion=6, block_id=15)
+
+ x = _inverted_res_block(
+ x, filters=320, alpha=alpha, stride=1, expansion=6, block_id=16)
+
+ # no alpha applied to last conv as stated in the paper:
+ # if the width multiplier is greater than 1 we
+ # increase the number of output channels
+ if alpha > 1.0:
+ last_block_filters = _make_divisible(1280 * alpha, 8)
+ else:
+ last_block_filters = 1280
+
+ x = layers.Conv2D(
+ last_block_filters, kernel_size=1, use_bias=False, name='Conv_1')(
+ x)
+ x = layers.BatchNormalization(
+ axis=channel_axis, epsilon=1e-3, momentum=0.999, name='Conv_1_bn')(
+ x)
+ x = layers.ReLU(6., name='out_relu')(x)
+
+ if include_top:
+ x = layers.GlobalAveragePooling2D()(x)
+ imagenet_utils.validate_activation(classifier_activation, weights)
+ x = layers.Dense(classes, activation=classifier_activation,
+ name='predictions')(x)
+
+ else:
+ if pooling == 'avg':
+ x = layers.GlobalAveragePooling2D()(x)
+ elif pooling == 'max':
+ x = layers.GlobalMaxPooling2D()(x)
+
+ # Ensure that the model takes into account
+ # any potential predecessors of `input_tensor`.
+ if input_tensor is not None:
+ inputs = layer_utils.get_source_inputs(input_tensor)
+ else:
+ inputs = img_input
+
+ # Create model.
+ model = training.Model(inputs, x, name='mobilenetv2_%0.2f_%s' % (alpha, rows))
+
+ # Load weights.
+ if weights == 'imagenet':
+ if include_top:
+ model_name = ('mobilenet_v2_weights_tf_dim_ordering_tf_kernels_' +
+ str(float(alpha)) + '_' + str(rows) + '.h5')
+ weight_path = BASE_WEIGHT_PATH + model_name
+ weights_path = data_utils.get_file(
+ model_name, weight_path, cache_subdir='models', cache_dir=cache_dir)
+ else:
+ model_name = ('mobilenet_v2_weights_tf_dim_ordering_tf_kernels_' +
+ str(float(alpha)) + '_' + str(rows) + '_no_top' + '.h5')
+ weight_path = BASE_WEIGHT_PATH + model_name
+ weights_path = data_utils.get_file(
+ model_name, weight_path, cache_subdir='models', cache_dir=cache_dir)
+ model.load_weights(weights_path)
+ elif weights is not None:
+ model.load_weights(weights)
+
+ return model
+
+
+def _inverted_res_block(inputs, expansion, stride, alpha, filters, block_id):
+ """Inverted ResNet block."""
+ channel_axis = 1 if backend.image_data_format() == 'channels_first' else -1
+
+ in_channels = backend.int_shape(inputs)[channel_axis]
+ pointwise_conv_filters = int(filters * alpha)
+ pointwise_filters = _make_divisible(pointwise_conv_filters, 8)
+ x = inputs
+ prefix = 'block_{}_'.format(block_id)
+
+ if block_id:
+ # Expand
+ x = layers.Conv2D(
+ expansion * in_channels,
+ kernel_size=1,
+ padding='same',
+ use_bias=False,
+ activation=None,
+ name=prefix + 'expand')(
+ x)
+ x = layers.BatchNormalization(
+ axis=channel_axis,
+ epsilon=1e-3,
+ momentum=0.999,
+ name=prefix + 'expand_BN')(
+ x)
+ x = layers.ReLU(6., name=prefix + 'expand_relu')(x)
+ else:
+ prefix = 'expanded_conv_'
+
+ # Depthwise
+ if stride == 2:
+ x = layers.ZeroPadding2D(
+ padding=imagenet_utils.correct_pad(x, 3),
+ name=prefix + 'pad')(x)
+ x = layers.DepthwiseConv2D(
+ kernel_size=3,
+ strides=stride,
+ activation=None,
+ use_bias=False,
+ padding='same' if stride == 1 else 'valid',
+ name=prefix + 'depthwise')(
+ x)
+ x = layers.BatchNormalization(
+ axis=channel_axis,
+ epsilon=1e-3,
+ momentum=0.999,
+ name=prefix + 'depthwise_BN')(
+ x)
+
+ x = layers.ReLU(6., name=prefix + 'depthwise_relu')(x)
+
+ # Project
+ x = layers.Conv2D(
+ pointwise_filters,
+ kernel_size=1,
+ padding='same',
+ use_bias=False,
+ activation=None,
+ name=prefix + 'project')(
+ x)
+ x = layers.BatchNormalization(
+ axis=channel_axis,
+ epsilon=1e-3,
+ momentum=0.999,
+ name=prefix + 'project_BN')(
+ x)
+
+ if in_channels == pointwise_filters and stride == 1:
+ return layers.Add(name=prefix + 'add')([inputs, x])
+ return x
+
+
+def _make_divisible(v, divisor, min_value=None):
+ if min_value is None:
+ min_value = divisor
+ new_v = max(min_value, int(v + divisor / 2) // divisor * divisor)
+ # Make sure that round down does not go down by more than 10%.
+ if new_v < 0.9 * v:
+ new_v += divisor
+ return new_v
+
+
+@keras_export('keras.applications.mobilenet_v2.preprocess_input')
+def preprocess_input(x, data_format=None):
+ return imagenet_utils.preprocess_input(x, data_format=data_format, mode='tf')
+
+
+@keras_export('keras.applications.mobilenet_v2.decode_predictions')
+def decode_predictions(preds, top=5):
+ return imagenet_utils.decode_predictions(preds, top=top)
+
+
+preprocess_input.__doc__ = imagenet_utils.PREPROCESS_INPUT_DOC.format(
+ mode='',
+ ret=imagenet_utils.PREPROCESS_INPUT_RET_DOC_TF,
+ error=imagenet_utils.PREPROCESS_INPUT_ERROR_DOC)
+decode_predictions.__doc__ = imagenet_utils.decode_predictions.__doc__
+
+
+def get_model():
+ # Load the pre-trained weights of MobileNetV2 and freeze the weights
+ backbone = MobileNetV2(
+ weights="imagenet", include_top=False, input_shape=(IMG_SIZE, IMG_SIZE, 3), cache_dir=args.data_path
+ )
+ backbone.trainable = False
+
+ inputs = layers.Input((IMG_SIZE, IMG_SIZE, 3))
+ x = keras.applications.mobilenet_v2.preprocess_input(inputs)
+ x = backbone(x)
+ x = layers.Dropout(0.3)(x)
+ x = layers.SeparableConv2D(
+ NUM_KEYPOINTS, kernel_size=5, strides=1, activation="relu"
+ )(x)
+ outputs = layers.SeparableConv2D(
+ NUM_KEYPOINTS, kernel_size=3, strides=1, activation="sigmoid"
+ )(x)
+
+ return keras.Model(inputs, outputs, name="keypoint_detector")
+
+
+"""
+Our custom network is fully-convolutional which makes it more parameter-friendly than the
+same version of the network having fully-connected dense layers.
+"""
+
+# get_model().summary()
+
+"""
+Notice the output shape of the network: `(None, 1, 1, 48)`. This is why we have reshaped
+the coordinates as: `batch_keypoints[i, :] = np.array(kp_temp).reshape(1, 1, 24 * 2)`.
+"""
+
+"""
+## Model compilation and training
+
+For this example, we will train the network only for five epochs.
+"""
+
+model = get_model()
+model.compile(loss="mse", optimizer=keras.optimizers.Adam(1e-4))
+model.fit(train_dataset, validation_data=validation_dataset, epochs=EPOCHS, verbose=2)
+model.save_weights(filepath="checkpoint/tf_model",save_format="tf")
+
+"""
+## Make predictions and visualize them
+"""
+
+# sample_val_images, sample_val_keypoints = next(iter(validation_dataset))
+# sample_val_images = sample_val_images[:4]
+# sample_val_keypoints = sample_val_keypoints[:4].reshape(-1, 24, 2) * IMG_SIZE
+# predictions = model.predict(sample_val_images).reshape(-1, 24, 2) * IMG_SIZE
+
+# # Ground-truth
+# visualize_keypoints(sample_val_images, sample_val_keypoints)
+
+# # Predictions
+# visualize_keypoints(sample_val_images, predictions)
+
+"""
+Predictions will likely improve with more training.
+"""
+
+"""
+## Going further
+
+* Try using other augmentation transforms from `imgaug` to investigate how that changes
+the results.
+* Here, we transferred the features from the pre-trained network linearly that is we did
+not [fine-tune](https://keras.io/guides/transfer_learning/) it. You are encouraged to fine-tune it on this task and see if that
+improves the performance. You can also try different architectures and see how they
+affect the final performance.
+"""
diff --git a/TensorFlow2/built-in/keras_sample/keypoint_detection_ID2516_for_TensorFlow2.X/modelzoo_level.txt b/TensorFlow2/built-in/keras_sample/keypoint_detection_ID2516_for_TensorFlow2.X/modelzoo_level.txt
new file mode 100644
index 0000000000000000000000000000000000000000..a829ab59b97a1022dd6fc33b59b7ae0d55009432
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/keypoint_detection_ID2516_for_TensorFlow2.X/modelzoo_level.txt
@@ -0,0 +1,3 @@
+FuncStatus:OK
+PerfStatus:NOK
+PrecisionStatus:OK
\ No newline at end of file
diff --git a/TensorFlow2/built-in/keras_sample/keypoint_detection_ID2516_for_TensorFlow2.X/requirements.txt b/TensorFlow2/built-in/keras_sample/keypoint_detection_ID2516_for_TensorFlow2.X/requirements.txt
new file mode 100644
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
diff --git a/TensorFlow2/built-in/keras_sample/keypoint_detection_ID2516_for_TensorFlow2.X/run_1p.sh b/TensorFlow2/built-in/keras_sample/keypoint_detection_ID2516_for_TensorFlow2.X/run_1p.sh
new file mode 100644
index 0000000000000000000000000000000000000000..29003bf08309fd305ad74d732daff814cdb9226f
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/keypoint_detection_ID2516_for_TensorFlow2.X/run_1p.sh
@@ -0,0 +1,2 @@
+cur_path='pwd'
+python3 ${cur_path}/keypoint_detection.py > loss+perf_gpu.txt 2>&1
diff --git a/TensorFlow2/built-in/keras_sample/keypoint_detection_ID2516_for_TensorFlow2.X/test/train_full_1p.sh b/TensorFlow2/built-in/keras_sample/keypoint_detection_ID2516_for_TensorFlow2.X/test/train_full_1p.sh
new file mode 100644
index 0000000000000000000000000000000000000000..f329db972700040a603346f89e1ce3eb4bb73daf
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/keypoint_detection_ID2516_for_TensorFlow2.X/test/train_full_1p.sh
@@ -0,0 +1,166 @@
+#!/bin/bash
+cur_path=`pwd`/../
+
+#设置默认日志级别,不需要修改
+# export ASCEND_GLOBAL_LOG_LEVEL=3
+
+#基础参数,需要模型审视修改
+#Batch Size
+batch_size=32
+#网络名称,同目录名称
+Network="keypoint_detection_ID2516_for_TensorFlow2.X"
+#Device数量,单卡默认为1
+RANK_SIZE=1
+#训练epoch,可选
+train_epochs=5
+#训练step
+#train_steps=50000
+#学习率
+# learning_rate=0.001
+# weight_decay=0.0001
+#参数配置
+data_path=""
+
+############维测参数##############
+precision_mode="allow_mix_precision"
+#维持参数,以下不需要修改
+over_dump=False
+if [[ $over_dump == True ]];then
+ over_dump_path=$cur_path/test/output/overflow_dump #此处cur_path为代码根目录
+ mkdir -p ${over_dump_path}
+fi
+data_dump_flag=False
+data_dump_step="10"
+profiling=False
+use_mixlist=False
+mixlist_file="./configs/ops_info.json"
+fusion_off_flag=False
+fusion_off_file="./configs/fusion_switch.cfg"
+auto_tune=False
+############维测参数##############
+
+if [[ $1 == --help || $1 == --h ]];then
+ echo "usage: ./train_full_1p.sh"
+ exit 1
+fi
+
+for para in $*
+do
+ if [[ $para == --data_path* ]];then
+ data_path=`echo ${para#*=}`
+ elif [[ $para == --precision_mode* ]];then
+ precision_mode=`echo ${para#*=}`
+ elif [[ $para == --over_dump* ]];then
+ over_dump=`echo ${para#*=}`
+ over_dump_path=${cur_path}/test/output/overflow_dump
+ mkdir -p ${over_dump_path}
+ elif [[ $para == --data_dump_flag* ]];then
+ data_dump_flag=`echo ${para#*=}`
+ data_dump_path=${cur_path}/test/output/data_dump
+ mkdir -p ${data_dump_path}
+ elif [[ $para == --data_dump_step* ]];then
+ data_dump_step=`echo ${para#*=}`
+ elif [[ $para == --profiling* ]];then
+ profiling=`echo ${para#*=}`
+ profiling_dump_path=${cur_path}/test/output/profiling
+ mkdir -p ${profiling_dump_path}
+ elif [[ $para == --data_path* ]];then
+ data_path=`echo ${para#*=}`
+ elif [[ $para == --use_mixlist* ]];then
+ use_mixlist=`echo ${para#*=}`
+ elif [[ $para == --mixlist_file* ]];then
+ mixlist_file=`echo ${para#*=}`
+ elif [[ $para == --fusion_off_flag* ]];then
+ fusion_off_flag=`echo ${para#*=}`
+ elif [[ $para == --fusion_off_file* ]];then
+ fusion_off_file=`echo ${para#*=}`
+ elif [[ $para == --auto_tune* ]];then
+ auto_tune=`echo ${para#*=}`
+ fi
+done
+
+if [[ $data_path == "" ]];then
+ echo "[Error] para \"data_path \" must be config"
+ exit 1
+fi
+
+##############执行训练##########
+cd $cur_path
+
+if [ -d $cur_path/test/output ];then
+ rm -rf $cur_path/test/output/*
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+else
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+fi
+wait
+
+start=$(date +%s)
+nohup python3 keypoint_detection.py \
+ --data_path=$data_path \
+ --epochs=${train_epochs} \
+ --batch_size=${batch_size} \
+ --precision_mode=${precision_mode} \
+ --over_dump=${over_dump} \
+ --over_dump_path=${over_dump_path} \
+ --data_dump_flag=${data_dump_flag} \
+ --data_dump_step=${data_dump_step} \
+ --data_dump_path=${data_dump_path} \
+ --profiling=${profiling} \
+ --use_mixlist=${use_mixlist} \
+ --fusion_off_flag=${fusion_off_flag} \
+ --mixlist_file=${mixlist_file} \
+ --fusion_off_file=${fusion_off_file} \
+ --auto_tune=${auto_tune} \
+ --profiling_dump_path=${profiling_dump_path}>$cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 &
+wait
+
+end=$(date +%s)
+e2e_time=$(( $end - $start ))
+
+echo "Final Training Duration sec : $e2e_time"
+
+#结果打印,不需要修改
+echo "------------------ Final result ------------------"
+#输出性能FPS,需要模型审视修改
+TrainingTime=`grep 333/333 $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk '{print $3}'|awk 'NR==2'|tr -cd "[0-9]"`
+FPS=`awk 'BEGIN{printf "%.2f\n",'333'*'${batch_size}'/'${TrainingTime}'}'`
+wait
+
+#打印,不需要修改
+echo "Final Performance images/sec : $FPS"
+
+#输出训练精度,需要模型审视修改
+train_accuracy=`grep '333/333' $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | awk 'END {print $6}'`
+#打印,不需要修改
+echo "Final Train Accuracy : =${train_accuracy}"
+
+
+#精度看护结果汇总
+#训练用例信息,不需要修改
+BatchSize=${batch_size}
+DeviceType=`uname -m`
+CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc'
+
+##获取性能数据,不需要修改
+#吞吐量
+ActualFPS=${FPS}
+#单迭代训练时长
+TrainingTime=${TrainingTime}
+
+#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视
+cat $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log| grep 333/333 | awk '{print $6}' > $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt
+#最后一个迭代loss值,不需要修改
+ActualLoss=`awk 'END {print $1}' $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt`
+
+#关键信息打印到${CaseName}.log中,不需要修改
+echo "Network = ${Network}" > $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "RankSize = ${RANK_SIZE}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "BatchSize = ${BatchSize}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "DeviceType = ${DeviceType}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "CaseName = ${CaseName}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualFPS = ${ActualFPS}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainingTime = ${TrainingTime}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualLoss = ${ActualLoss}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
\ No newline at end of file
diff --git a/TensorFlow2/built-in/keras_sample/keypoint_detection_ID2516_for_TensorFlow2.X/test/train_performance_1p.sh b/TensorFlow2/built-in/keras_sample/keypoint_detection_ID2516_for_TensorFlow2.X/test/train_performance_1p.sh
new file mode 100644
index 0000000000000000000000000000000000000000..ca8a3aa55c68b4523d8fe2660617cd92a4d4a64d
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/keypoint_detection_ID2516_for_TensorFlow2.X/test/train_performance_1p.sh
@@ -0,0 +1,166 @@
+#!/bin/bash
+cur_path=`pwd`/../
+
+#设置默认日志级别,不需要修改
+# export ASCEND_GLOBAL_LOG_LEVEL_ETP=3
+
+#基础参数,需要模型审视修改
+#Batch Size
+batch_size=64
+#网络名称,同目录名称
+Network="keypoint_detection_ID2516_for_TensorFlow2.X"
+#Device数量,单卡默认为1
+RANK_SIZE=1
+#训练epoch,可选
+train_epochs=2
+#训练step
+#train_steps=50000
+#学习率
+# learning_rate=0.001
+# weight_decay=0.0001
+#参数配置
+data_path=""
+
+############维测参数##############
+precision_mode="allow_mix_precision"
+#维持参数,以下不需要修改
+over_dump=False
+if [[ $over_dump == True ]];then
+ over_dump_path=$cur_path/test/output/overflow_dump #此处cur_path为代码根目录
+ mkdir -p ${over_dump_path}
+fi
+data_dump_flag=False
+data_dump_step="10"
+profiling=False
+use_mixlist=False
+mixlist_file="./configs/ops_info.json"
+fusion_off_flag=False
+fusion_off_file="./configs/fusion_switch.cfg"
+auto_tune=False
+############维测参数##############
+
+if [[ $1 == --help || $1 == --h ]];then
+ echo "usage: ./train_performance_1p.sh"
+ exit 1
+fi
+
+for para in $*
+do
+ if [[ $para == --data_path* ]];then
+ data_path=`echo ${para#*=}`
+ elif [[ $para == --precision_mode* ]];then
+ precision_mode=`echo ${para#*=}`
+ elif [[ $para == --over_dump* ]];then
+ over_dump=`echo ${para#*=}`
+ over_dump_path=${cur_path}/test/output/overflow_dump
+ mkdir -p ${over_dump_path}
+ elif [[ $para == --data_dump_flag* ]];then
+ data_dump_flag=`echo ${para#*=}`
+ data_dump_path=${cur_path}/test/output/data_dump
+ mkdir -p ${data_dump_path}
+ elif [[ $para == --data_dump_step* ]];then
+ data_dump_step=`echo ${para#*=}`
+ elif [[ $para == --profiling* ]];then
+ profiling=`echo ${para#*=}`
+ profiling_dump_path=${cur_path}/test/output/profiling
+ mkdir -p ${profiling_dump_path}
+ elif [[ $para == --data_path* ]];then
+ data_path=`echo ${para#*=}`
+ elif [[ $para == --use_mixlist* ]];then
+ use_mixlist=`echo ${para#*=}`
+ elif [[ $para == --mixlist_file* ]];then
+ mixlist_file=`echo ${para#*=}`
+ elif [[ $para == --fusion_off_flag* ]];then
+ fusion_off_flag=`echo ${para#*=}`
+ elif [[ $para == --fusion_off_file* ]];then
+ fusion_off_file=`echo ${para#*=}`
+ elif [[ $para == --auto_tune* ]];then
+ auto_tune=`echo ${para#*=}`
+ fi
+done
+
+if [[ $data_path == "" ]];then
+ echo "[Error] para \"data_path \" must be config"
+ exit 1
+fi
+
+##############执行训练##########
+cd $cur_path
+
+if [ -d $cur_path/test/output ];then
+ rm -rf $cur_path/test/output/*
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+else
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+fi
+wait
+
+start=$(date +%s)
+nohup python3 keypoint_detection.py \
+ --data_path=$data_path \
+ --epochs=${train_epochs} \
+ --batch_size=${batch_size} \
+ --precision_mode=${precision_mode} \
+ --over_dump=${over_dump} \
+ --over_dump_path=${over_dump_path} \
+ --data_dump_flag=${data_dump_flag} \
+ --data_dump_step=${data_dump_step} \
+ --data_dump_path=${data_dump_path} \
+ --profiling=${profiling} \
+ --use_mixlist=${use_mixlist} \
+ --fusion_off_flag=${fusion_off_flag} \
+ --mixlist_file=${mixlist_file} \
+ --fusion_off_file=${fusion_off_file} \
+ --auto_tune=${auto_tune} \
+ --profiling_dump_path=${profiling_dump_path}>$cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 &
+wait
+
+end=$(date +%s)
+e2e_time=$(( $end - $start ))
+
+echo "Final Training Duration sec : $e2e_time"
+
+#结果打印,不需要修改
+echo "------------------ Final result ------------------"
+#输出性能FPS,需要模型审视修改
+TrainingTime=`grep 166/166 $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log |awk '{print $3}'|tr -d 's'|awk '{sum+=$1} END {print"",sum/NR}'|sed s/[[:space:]]//g`
+FPS=`awk 'BEGIN{printf "%.2f\n",'${batch_size}'/'${TrainingTime}'}'`
+wait
+
+#打印,不需要修改
+echo "Final Performance images/sec : $FPS"
+
+#输出训练精度,需要模型审视修改
+# train_accuracy=`grep val_loss $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | awk 'END {print$9}'`
+#打印,不需要修改
+echo "Final Train Accuracy : =Loss"
+
+
+#精度看护结果汇总
+#训练用例信息,不需要修改
+BatchSize=${batch_size}
+DeviceType=`uname -m`
+CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf'
+
+##获取性能数据,不需要修改
+#吞吐量
+ActualFPS=${FPS}
+#单迭代训练时长
+TrainingTime=${TrainingTime}
+
+#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视
+cat $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|grep 166/166 |awk '{print $6}'|sed s/[[:space:]]//g > $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt
+#最后一个迭代loss值,不需要修改
+ActualLoss=`awk 'END {print $1}' $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt`
+
+#关键信息打印到${CaseName}.log中,不需要修改
+echo "Network = ${Network}" > $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "RankSize = ${RANK_SIZE}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "BatchSize = ${BatchSize}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "DeviceType = ${DeviceType}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "CaseName = ${CaseName}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualFPS = ${ActualFPS}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainingTime = ${TrainingTime}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+#echo "TrainAccuracy = Loss" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualLoss = ${ActualLoss}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
\ No newline at end of file
diff --git a/TensorFlow2/built-in/keras_sample/keypoint_detection_ID2516_for_TensorFlow2.X/test/train_performance_1p_static.sh b/TensorFlow2/built-in/keras_sample/keypoint_detection_ID2516_for_TensorFlow2.X/test/train_performance_1p_static.sh
new file mode 100644
index 0000000000000000000000000000000000000000..ea35d321fdaae6f8e8aea949ae32e41ee0827c07
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/keypoint_detection_ID2516_for_TensorFlow2.X/test/train_performance_1p_static.sh
@@ -0,0 +1,167 @@
+#!/bin/bash
+cur_path=`pwd`/../
+
+#设置默认日志级别,不需要修改
+# export ASCEND_GLOBAL_LOG_LEVEL=3
+
+#基础参数,需要模型审视修改
+#Batch Size
+batch_size=32
+#网络名称,同目录名称
+Network="keypoint_detection_ID2516_for_TensorFlow2.X"
+#Device数量,单卡默认为1
+RANK_SIZE=1
+#训练epoch,可选
+train_epochs=2
+#训练step
+#train_steps=50000
+#学习率
+# learning_rate=0.001
+# weight_decay=0.0001
+#参数配置
+data_path=""
+
+############维测参数##############
+precision_mode="allow_mix_precision"
+#维持参数,以下不需要修改
+over_dump=False
+if [[ $over_dump == True ]];then
+ over_dump_path=$cur_path/test/output/overflow_dump #此处cur_path为代码根目录
+ mkdir -p ${over_dump_path}
+fi
+data_dump_flag=False
+data_dump_step="10"
+profiling=False
+use_mixlist=False
+mixlist_file="./configs/ops_info.json"
+fusion_off_flag=False
+fusion_off_file="./configs/fusion_switch.cfg"
+auto_tune=False
+############维测参数##############
+
+if [[ $1 == --help || $1 == --h ]];then
+ echo "usage: ./train_full_1p.sh"
+ exit 1
+fi
+
+for para in $*
+do
+ if [[ $para == --data_path* ]];then
+ data_path=`echo ${para#*=}`
+ elif [[ $para == --precision_mode* ]];then
+ precision_mode=`echo ${para#*=}`
+ elif [[ $para == --over_dump* ]];then
+ over_dump=`echo ${para#*=}`
+ over_dump_path=${cur_path}/test/output/overflow_dump
+ mkdir -p ${over_dump_path}
+ elif [[ $para == --data_dump_flag* ]];then
+ data_dump_flag=`echo ${para#*=}`
+ data_dump_path=${cur_path}/test/output/data_dump
+ mkdir -p ${data_dump_path}
+ elif [[ $para == --data_dump_step* ]];then
+ data_dump_step=`echo ${para#*=}`
+ elif [[ $para == --profiling* ]];then
+ profiling=`echo ${para#*=}`
+ profiling_dump_path=${cur_path}/test/output/profiling
+ mkdir -p ${profiling_dump_path}
+ elif [[ $para == --data_path* ]];then
+ data_path=`echo ${para#*=}`
+ elif [[ $para == --use_mixlist* ]];then
+ use_mixlist=`echo ${para#*=}`
+ elif [[ $para == --mixlist_file* ]];then
+ mixlist_file=`echo ${para#*=}`
+ elif [[ $para == --fusion_off_flag* ]];then
+ fusion_off_flag=`echo ${para#*=}`
+ elif [[ $para == --fusion_off_file* ]];then
+ fusion_off_file=`echo ${para#*=}`
+ elif [[ $para == --auto_tune* ]];then
+ auto_tune=`echo ${para#*=}`
+ fi
+done
+
+if [[ $data_path == "" ]];then
+ echo "[Error] para \"data_path \" must be config"
+ exit 1
+fi
+
+##############执行训练##########
+cd $cur_path
+
+if [ -d $cur_path/test/output ];then
+ rm -rf $cur_path/test/output/*
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+else
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+fi
+wait
+
+start=$(date +%s)
+nohup python3 keypoint_detection.py \
+ --data_path=$data_path \
+ --epochs=${train_epochs} \
+ --batch_size=${batch_size} \
+ --precision_mode=${precision_mode} \
+ --over_dump=${over_dump} \
+ --over_dump_path=${over_dump_path} \
+ --data_dump_flag=${data_dump_flag} \
+ --data_dump_step=${data_dump_step} \
+ --data_dump_path=${data_dump_path} \
+ --profiling=${profiling} \
+ --use_mixlist=${use_mixlist} \
+ --fusion_off_flag=${fusion_off_flag} \
+ --mixlist_file=${mixlist_file} \
+ --fusion_off_file=${fusion_off_file} \
+ --auto_tune=${auto_tune} \
+ --profiling_dump_path=${profiling_dump_path} \
+ --static=1 >$cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 &
+wait
+
+end=$(date +%s)
+e2e_time=$(( $end - $start ))
+
+echo "Final Training Duration sec : $e2e_time"
+
+#结果打印,不需要修改
+echo "------------------ Final result ------------------"
+#输出性能FPS,需要模型审视修改
+TrainingTime=`grep loss: $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk '{print $3}'|awk 'NR==2'|tr -cd "[0-9]"`
+FPS=`awk 'BEGIN{printf "%.2f\n",'333'*'${batch_size}'/'${TrainingTime}'}'`
+wait
+
+#打印,不需要修改
+echo "Final Performance images/sec : $FPS"
+
+#输出训练精度,需要模型审视修改
+train_accuracy=`grep 'loss:' $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | awk 'END {print $6}'`
+#打印,不需要修改
+echo "Final Train Accuracy : =${train_accuracy}"
+
+
+#精度看护结果汇总
+#训练用例信息,不需要修改
+BatchSize=${batch_size}
+DeviceType=`uname -m`
+CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf'
+
+##获取性能数据,不需要修改
+#吞吐量
+ActualFPS=${FPS}
+#单迭代训练时长
+TrainingTime=${TrainingTime}
+
+#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视
+cat $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log| grep loss: | awk '{print $6}' > $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt
+#最后一个迭代loss值,不需要修改
+ActualLoss=`awk 'END {print $1}' $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt`
+
+#关键信息打印到${CaseName}.log中,不需要修改
+echo "Network = ${Network}" > $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "RankSize = ${RANK_SIZE}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "BatchSize = ${BatchSize}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "DeviceType = ${DeviceType}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "CaseName = ${CaseName}_static" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualFPS = ${ActualFPS}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainingTime = ${TrainingTime}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualLoss = ${ActualLoss}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
\ No newline at end of file
diff --git a/TensorFlow2/built-in/keras_sample/knowledge_disti_ID2517_for_TensorFlow2.X/LICENSE b/TensorFlow2/built-in/keras_sample/knowledge_disti_ID2517_for_TensorFlow2.X/LICENSE
new file mode 100644
index 0000000000000000000000000000000000000000..d87a402b53d094a701d748276c3d98bd25daaa96
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/knowledge_disti_ID2517_for_TensorFlow2.X/LICENSE
@@ -0,0 +1,284 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+------------------
+Files: third_party/compute_library/...
+
+MIT License
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+
+------------------
+Files: ACKNOWLEDGEMENTS
+LICENSE
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+------------------
+Files: third_party/hexagon
+
+Copyright (c) 2016-2019, The Linux Foundation. All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted (subject to the limitations in the
+disclaimer below) provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+
+ * Neither the name of The Linux Foundation nor the names of its
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
+GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
+HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/TensorFlow2/built-in/keras_sample/knowledge_disti_ID2517_for_TensorFlow2.X/ReadMe.md b/TensorFlow2/built-in/keras_sample/knowledge_disti_ID2517_for_TensorFlow2.X/ReadMe.md
new file mode 100644
index 0000000000000000000000000000000000000000..6bda4da8b18bb4ca652480a823d78f9eb2e553ec
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/knowledge_disti_ID2517_for_TensorFlow2.X/ReadMe.md
@@ -0,0 +1,26 @@
+## 一、基础信息
+
+### 网络名称
+
+```shell
+knowledge_distillation_ID2517_for_TensorFlow2.X
+```
+
+### github地址
+
+```shell
+https://github.com/keras-team/keras-io/tree/master/examples/vision
+```
+
+### 数据集
+
+```
+MNIST
+```
+
+### 程序运行
+
+```
+train_performance_1p_static_eval.sh --data_path=/MNIST/mnist.npz
+```
+
diff --git a/TensorFlow2/built-in/keras_sample/knowledge_disti_ID2517_for_TensorFlow2.X/knowledge_distillation.py b/TensorFlow2/built-in/keras_sample/knowledge_disti_ID2517_for_TensorFlow2.X/knowledge_distillation.py
new file mode 100644
index 0000000000000000000000000000000000000000..71938b428ca77637f63321f11613d32d0f7c783b
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/knowledge_disti_ID2517_for_TensorFlow2.X/knowledge_distillation.py
@@ -0,0 +1,332 @@
+#
+# Copyright 2017 The TensorFlow Authors. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============================================================================
+# Copyright 2021 Huawei Technologies Co., Ltd
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+"""
+Title: Knowledge Distillation
+Author: [Kenneth Borup](https://twitter.com/Kennethborup)
+Date created: 2020/09/01
+Last modified: 2020/09/01
+Description: Implementation of classical Knowledge Distillation.
+"""
+
+"""
+## Introduction to Knowledge Distillation
+
+Knowledge Distillation is a procedure for model
+compression, in which a small (student) model is trained to match a large pre-trained
+(teacher) model. Knowledge is transferred from the teacher model to the student
+by minimizing a loss function, aimed at matching softened teacher logits as well as
+ground-truth labels.
+
+The logits are softened by applying a "temperature" scaling function in the softmax,
+effectively smoothing out the probability distribution and revealing
+inter-class relationships learned by the teacher.
+
+**Reference:**
+
+- [Hinton et al. (2015)](https://arxiv.org/abs/1503.02531)
+"""
+
+"""
+## Setup
+"""
+
+import npu_device
+npu_device.open().as_default()
+
+import ast
+import argparse
+
+import tensorflow as tf
+from tensorflow import keras
+from tensorflow.keras import layers
+import numpy as np
+
+
+"""
+## Construct `Distiller()` class
+
+The custom `Distiller()` class, overrides the `Model` methods `train_step`, `test_step`,
+and `compile()`. In order to use the distiller, we need:
+
+- A trained teacher model
+- A student model to train
+- A student loss function on the difference between student predictions and ground-truth
+- A distillation loss function, along with a `temperature`, on the difference between the
+soft student predictions and the soft teacher labels
+- An `alpha` factor to weight the student and distillation loss
+- An optimizer for the student and (optional) metrics to evaluate performance
+
+In the `train_step` method, we perform a forward pass of both the teacher and student,
+calculate the loss with weighting of the `student_loss` and `distillation_loss` by `alpha` and
+`1 - alpha`, respectively, and perform the backward pass. Note: only the student weights are updated,
+and therefore we only calculate the gradients for the student weights.
+
+In the `test_step` method, we evaluate the student model on the provided dataset.
+"""
+
+parser = argparse.ArgumentParser()
+parser.add_argument('--data_path', default="/home/data", type=str,
+ help='the path to train data')
+parser.add_argument('--epoch', default=2, type=int,
+ help='the path to train data')
+parser.add_argument('--eval_static', dest="eval_static", type=ast.literal_eval,
+ help='the path to train data')
+args = parser.parse_args()
+
+class Distiller(keras.Model):
+ def __init__(self, student, teacher):
+ super(Distiller, self).__init__()
+ self.teacher = teacher
+ self.student = student
+
+ def compile(
+ self,
+ optimizer,
+ metrics,
+ student_loss_fn,
+ distillation_loss_fn,
+ alpha=0.1,
+ temperature=3,
+ ):
+ """ Configure the distiller.
+
+ Args:
+ optimizer: Keras optimizer for the student weights
+ metrics: Keras metrics for evaluation
+ student_loss_fn: Loss function of difference between student
+ predictions and ground-truth
+ distillation_loss_fn: Loss function of difference between soft
+ student predictions and soft teacher predictions
+ alpha: weight to student_loss_fn and 1-alpha to distillation_loss_fn
+ temperature: Temperature for softening probability distributions.
+ Larger temperature gives softer distributions.
+ """
+ super(Distiller, self).compile(optimizer=optimizer, metrics=metrics)
+ self.student_loss_fn = student_loss_fn
+ self.distillation_loss_fn = distillation_loss_fn
+ self.alpha = alpha
+ self.temperature = temperature
+
+ def train_step(self, data):
+ # Unpack data
+ x, y = data
+
+ # Forward pass of teacher
+ teacher_predictions = self.teacher(x, training=False)
+
+ with tf.GradientTape() as tape:
+ # Forward pass of student
+ student_predictions = self.student(x, training=True)
+
+ # Compute losses
+ student_loss = self.student_loss_fn(y, student_predictions)
+ distillation_loss = self.distillation_loss_fn(
+ tf.nn.softmax(teacher_predictions / self.temperature, axis=1),
+ tf.nn.softmax(student_predictions / self.temperature, axis=1),
+ )
+ loss = self.alpha * student_loss + (1 - self.alpha) * distillation_loss
+
+ # Compute gradients
+ trainable_vars = self.student.trainable_variables
+ gradients = tape.gradient(loss, trainable_vars)
+
+ # Update weights
+ self.optimizer.apply_gradients(zip(gradients, trainable_vars))
+
+ # Update the metrics configured in `compile()`.
+ self.compiled_metrics.update_state(y, student_predictions)
+
+ # Return a dict of performance
+ results = {m.name: m.result() for m in self.metrics}
+ results.update(
+ {"student_loss": student_loss, "distillation_loss": distillation_loss}
+ )
+ return results
+
+ def test_step(self, data):
+ # Unpack the data
+ x, y = data
+
+ # Compute predictions
+ y_prediction = self.student(x, training=False)
+
+ # Calculate the loss
+ student_loss = self.student_loss_fn(y, y_prediction)
+
+ # Update the metrics.
+ self.compiled_metrics.update_state(y, y_prediction)
+
+ # Return a dict of performance
+ results = {m.name: m.result() for m in self.metrics}
+ results.update({"student_loss": student_loss})
+ return results
+
+
+"""
+## Create student and teacher models
+
+Initialy, we create a teacher model and a smaller student model. Both models are
+convolutional neural networks and created using `Sequential()`,
+but could be any Keras model.
+"""
+
+# Create the teacher
+teacher = keras.Sequential(
+ [
+ keras.Input(shape=(28, 28, 1)),
+ layers.Conv2D(256, (3, 3), strides=(2, 2), padding="same"),
+ layers.LeakyReLU(alpha=0.2),
+ layers.MaxPooling2D(pool_size=(2, 2), strides=(1, 1), padding="same"),
+ layers.Conv2D(512, (3, 3), strides=(2, 2), padding="same"),
+ layers.Flatten(),
+ layers.Dense(10),
+ ],
+ name="teacher",
+)
+
+# Create the student
+student = keras.Sequential(
+ [
+ keras.Input(shape=(28, 28, 1)),
+ layers.Conv2D(16, (3, 3), strides=(2, 2), padding="same"),
+ layers.LeakyReLU(alpha=0.2),
+ layers.MaxPooling2D(pool_size=(2, 2), strides=(1, 1), padding="same"),
+ layers.Conv2D(32, (3, 3), strides=(2, 2), padding="same"),
+ layers.Flatten(),
+ layers.Dense(10),
+ ],
+ name="student",
+)
+
+# Clone student for later comparison
+student_scratch = keras.models.clone_model(student)
+
+"""
+## Prepare the dataset
+
+The dataset used for training the teacher and distilling the teacher is
+[MNIST](https://keras.io/api/datasets/mnist/), and the procedure would be equivalent for any other
+dataset, e.g. [CIFAR-10](https://keras.io/api/datasets/cifar10/), with a suitable choice
+of models. Both the student and teacher are trained on the training set and evaluated on
+the test set.
+"""
+
+# Prepare the train and test dataset.
+batch_size = 32
+# (x_train, y_train), (x_test, y_test) = keras.datasets.mnist.load_data()
+
+path = args.data_path + '/mnist.npz'
+f = np.load(path)
+x_train, y_train = f['x_train'], f['y_train']
+x_test, y_test = f['x_test'], f['y_test']
+f.close()
+
+if args.eval_static:
+ x_test = x_test[:9984]
+ y_test = y_test[:9984]
+
+# Normalize data
+x_train = x_train.astype("float32") / 255.0
+x_train = np.reshape(x_train, (-1, 28, 28, 1))
+
+x_test = x_test.astype("float32") / 255.0
+x_test = np.reshape(x_test, (-1, 28, 28, 1))
+
+
+"""
+## Train the teacher
+
+In knowledge distillation we assume that the teacher is trained and fixed. Thus, we start
+by training the teacher model on the training set in the usual way.
+"""
+
+# Train teacher as usual
+teacher.compile(
+ optimizer=keras.optimizers.Adam(),
+ loss=keras.losses.SparseCategoricalCrossentropy(from_logits=True),
+ metrics=[keras.metrics.SparseCategoricalAccuracy()],
+)
+
+# Train and evaluate teacher on data.
+teacher.fit(x_train, y_train, epochs=args.epoch, verbose=2)
+teacher.evaluate(x_test, y_test, verbose=2)
+
+"""
+## Distill teacher to student
+
+We have already trained the teacher model, and we only need to initialize a
+`Distiller(student, teacher)` instance, `compile()` it with the desired losses,
+hyperparameters and optimizer, and distill the teacher to the student.
+"""
+
+# Initialize and compile distiller
+distiller = Distiller(student=student, teacher=teacher)
+distiller.compile(
+ optimizer=keras.optimizers.Adam(),
+ metrics=[keras.metrics.SparseCategoricalAccuracy()],
+ student_loss_fn=keras.losses.SparseCategoricalCrossentropy(from_logits=True),
+ distillation_loss_fn=keras.losses.KLDivergence(),
+ alpha=0.1,
+ temperature=10,
+)
+
+# Distill teacher to student
+distiller.fit(x_train, y_train, epochs=args.epoch, verbose=2)
+
+# Evaluate student on test dataset
+distiller.evaluate(x_test, y_test, verbose=2)
+
+"""
+## Train student from scratch for comparison
+
+We can also train an equivalent student model from scratch without the teacher, in order
+to evaluate the performance gain obtained by knowledge distillation.
+"""
+
+# Train student as doen usually
+student_scratch.compile(
+ optimizer=keras.optimizers.Adam(),
+ loss=keras.losses.SparseCategoricalCrossentropy(from_logits=True),
+ metrics=[keras.metrics.SparseCategoricalAccuracy()],
+)
+
+# Train and evaluate student trained from scratch.
+student_scratch.fit(x_train, y_train, epochs=args.epoch, verbose=2)
+student_scratch.evaluate(x_test, y_test, verbose=2)
+
+"""
+If the teacher is trained for 5 full epochs and the student is distilled on this teacher
+for 3 full epochs, you should in this example experience a performance boost compared to
+training the same student model from scratch, and even compared to the teacher itself.
+You should expect the teacher to have accuracy around 97.6%, the student trained from
+scratch should be around 97.6%, and the distilled student should be around 98.1%. Remove
+or try out different seeds to use different weight initializations.
+"""
diff --git a/TensorFlow2/built-in/keras_sample/knowledge_disti_ID2517_for_TensorFlow2.X/modelzoo_level.txt b/TensorFlow2/built-in/keras_sample/knowledge_disti_ID2517_for_TensorFlow2.X/modelzoo_level.txt
new file mode 100644
index 0000000000000000000000000000000000000000..0b49b4fb26c2694a86567bea1b462e7dcb03cc31
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/knowledge_disti_ID2517_for_TensorFlow2.X/modelzoo_level.txt
@@ -0,0 +1,3 @@
+FuncStatus:OK
+PerfStatus:OK
+PrecisionStatus:OK
\ No newline at end of file
diff --git a/TensorFlow2/built-in/keras_sample/knowledge_disti_ID2517_for_TensorFlow2.X/requirements.txt b/TensorFlow2/built-in/keras_sample/knowledge_disti_ID2517_for_TensorFlow2.X/requirements.txt
new file mode 100644
index 0000000000000000000000000000000000000000..662fa34ad41e9dbc895eeaecf624aad2902b8b76
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/knowledge_disti_ID2517_for_TensorFlow2.X/requirements.txt
@@ -0,0 +1,2 @@
+tensorflow>=2.4.0
+numpy
\ No newline at end of file
diff --git a/TensorFlow2/built-in/keras_sample/knowledge_disti_ID2517_for_TensorFlow2.X/test/train_full_1p.sh b/TensorFlow2/built-in/keras_sample/knowledge_disti_ID2517_for_TensorFlow2.X/test/train_full_1p.sh
new file mode 100644
index 0000000000000000000000000000000000000000..83871f46436be04a92b896730cfb311e6fecd811
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/knowledge_disti_ID2517_for_TensorFlow2.X/test/train_full_1p.sh
@@ -0,0 +1,103 @@
+#!/bin/bash
+cur_path=`pwd`/../
+
+#基础参数,需要模型审视修改
+#Batch Size
+batch_size=32
+#网络名称,同目录名称
+Network="knowledge_distillation_ID2517_for_TensorFlow2.X"
+#Device数量,单卡默认为1
+RANK_SIZE=1
+#训练epoch,可选
+train_epochs=5
+#训练step
+train_steps=60000
+#学习率
+#learning_rate=1e-5
+
+#参数配置
+data_path=""
+
+if [[ $1 == --help || $1 == --h ]];then
+ echo "usage: ./train_performance_1p.sh"
+ exit 1
+fi
+
+for para in $*
+do
+ if [[ $para == --data_path* ]];then
+ data_path=`echo ${para#*=}`
+ fi
+done
+
+if [[ $data_path == "" ]];then
+ echo "[Error] para \"data_path \" must be config"
+ exit 1
+fi
+
+##############执行训练##########
+cd $cur_path
+
+if [ -d $cur_path/test/output ];then
+ rm -rf $cur_path/test/output/*
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+else
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+fi
+wait
+
+start=$(date +%s)
+nohup python3 knowledge_distillation.py --data_path=$data_path \
+ --epoch=$train_epochs \
+ --eval_static=True > $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 &
+wait
+
+end=$(date +%s)
+e2e_time=$(( $end - $start ))
+
+#echo "Final Performance ms/step : $average_perf"
+echo "Final Training Duration sec : $e2e_time"
+
+#结果打印,不需要修改
+echo "------------------ Final result ------------------"
+#输出性能FPS,需要模型审视修改
+TrainingTime=`grep 1875/1875 $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk '{print $3}'|awk 'NR==2'|tr -cd "[0-9]"`
+wait
+FPS=`awk 'BEGIN{printf "%.2f\n",'1875'*'${batch_size}'/'${TrainingTime}'}'`
+#打印,不需要修改
+echo "Final Performance images/sec : $FPS"
+
+#输出训练精度,需要模型审视修改
+train_accuracy=`grep sparse_categorical_accuracy $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log |awk 'END {print $NF}'`
+#打印,不需要修改
+echo "Final Train Accuracy : ${train_accuracy}"
+
+
+#精度看护结果汇总
+#训练用例信息,不需要修改
+BatchSize=${batch_size}
+DeviceType=`uname -m`
+CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc'
+
+##获取性能数据,不需要修改
+#吞吐量
+ActualFPS=${FPS}
+#单迭代训练时长
+TrainingTime=${TrainingTime}
+
+#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视
+grep student_loss $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk '{print $9}' >> $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt
+#最后一个迭代loss值,不需要修改
+ActualLoss=`awk 'END {print $1}' $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt`
+
+#关键信息打印到${CaseName}.log中,不需要修改
+echo "Network = ${Network}" > $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "RankSize = ${RANK_SIZE}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "BatchSize = ${BatchSize}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "DeviceType = ${DeviceType}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "CaseName = ${CaseName}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualFPS = ${ActualFPS}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainingTime = ${TrainingTime}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualLoss = ${ActualLoss}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
diff --git a/TensorFlow2/built-in/keras_sample/knowledge_disti_ID2517_for_TensorFlow2.X/test/train_performance_1p_dynamic_eval.sh b/TensorFlow2/built-in/keras_sample/knowledge_disti_ID2517_for_TensorFlow2.X/test/train_performance_1p_dynamic_eval.sh
new file mode 100644
index 0000000000000000000000000000000000000000..11b1581695d372328a47a786612056e339f9981c
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/knowledge_disti_ID2517_for_TensorFlow2.X/test/train_performance_1p_dynamic_eval.sh
@@ -0,0 +1,114 @@
+#!/bin/bash
+cur_path=`pwd`/../
+
+#基础参数,需要模型审视修改
+#Batch Size
+batch_size=32
+#网络名称,同目录名称
+Network="knowledge_disti_ID2517_for_TensorFlow2.X"
+#Device数量,单卡默认为1
+RANK_SIZE=1
+#训练epoch,可选
+train_epochs=2
+#训练step
+train_steps=60000
+#学习率
+#learning_rate=1e-5
+
+#参数配置
+data_path=""
+
+if [[ $1 == --help || $1 == --h ]];then
+ echo "usage: ./train_performance_1p.sh"
+ exit 1
+fi
+
+for para in $*
+do
+ if [[ $para == --data_path* ]];then
+ data_path=`echo ${para#*=}`
+ fi
+done
+
+if [[ $data_path == "" ]];then
+ echo "[Error] para \"data_path \" must be config"
+ exit 1
+fi
+
+##############执行训练##########
+cd $cur_path
+
+if [ -d $cur_path/test/output ];then
+ rm -rf $cur_path/test/output/*
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+else
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+fi
+wait
+
+start=$(date +%s)
+nohup python3 knowledge_distillation.py --data_path=$data_path \
+ --epoch=$train_epochs \
+ --eval_static=False > $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 &
+wait
+
+end=$(date +%s)
+e2e_time=$(( $end - $start ))
+
+#echo "Final Performance ms/step : $average_perf"
+echo "Final Training Duration sec : $e2e_time"
+
+#结果打印,不需要修改
+echo "------------------ Final result ------------------"
+#输出性能FPS,需要模型审视修改
+TrainingTime=`grep 1875/1875 $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk '{print $3}'|awk 'NR==2'|tr -cd "[0-9]"`
+wait
+FPS=`awk 'BEGIN{printf "%.2f\n",'1000'*'${batch_size}'/'${TrainingTime}'}'`
+#打印,不需要修改
+echo "Final Performance images/sec : $FPS"
+
+#输出训练精度,需要模型审视修改
+#train_accuracy=`grep sparse_categorical_accuracy $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log |awk 'END {print $NF}'`
+#打印,不需要修改
+#echo "Final Train Accuracy : ${train_accuracy}"
+
+
+#精度看护结果汇总
+#训练用例信息,不需要修改
+BatchSize=${batch_size}
+DeviceType=`uname -m`
+CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'dynamic'_'eval'_'perf'
+
+##获取性能数据,不需要修改
+#吞吐量
+ActualFPS=${FPS}
+#单迭代训练时长
+TrainingTime=${TrainingTime}
+
+#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视
+grep student_loss $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk '{print $9}' > $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt
+#最后一个迭代loss值,不需要修改
+ActualLoss=`awk 'END {print $1}' $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt`
+
+#ModelStatus="图执行FAIL"
+#DTS_Number="DTS2022010611495"
+# error_msg="E19999"
+#error_msg="Output shape is still unknown after shape inference. shape = \[-1\]."
+#Status=`grep "${error_msg}" $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|wc -l`
+# error_msg="Graph engine process graph failed: E19999: Inner Error! Output shape is still unknown after shape inference. shape = [-1]."
+
+#关键信息打印到${CaseName}.log中,不需要修改
+echo "Network = ${Network}" > $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "RankSize = ${RANK_SIZE}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "BatchSize = ${BatchSize}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "DeviceType = ${DeviceType}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "CaseName = ${CaseName}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+#echo "ModelStatus = ${ModelStatus}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+#echo "DTS_Number = ${DTS_Number}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+#echo "Status = ${Status}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+#echo "error_msg = ${error_msg}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualFPS = ${ActualFPS}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainingTime = ${TrainingTime}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+#echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualLoss = ${ActualLoss}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
\ No newline at end of file
diff --git a/TensorFlow2/built-in/keras_sample/knowledge_disti_ID2517_for_TensorFlow2.X/test/train_performance_1p_static_eval.sh b/TensorFlow2/built-in/keras_sample/knowledge_disti_ID2517_for_TensorFlow2.X/test/train_performance_1p_static_eval.sh
new file mode 100644
index 0000000000000000000000000000000000000000..43e81d466ae2e39237d7f08126fe736e0f9c5036
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/knowledge_disti_ID2517_for_TensorFlow2.X/test/train_performance_1p_static_eval.sh
@@ -0,0 +1,103 @@
+#!/bin/bash
+cur_path=`pwd`/../
+
+#基础参数,需要模型审视修改
+#Batch Size
+batch_size=32
+#网络名称,同目录名称
+Network="knowledge_disti_ID2517_for_TensorFlow2.X"
+#Device数量,单卡默认为1
+RANK_SIZE=1
+#训练epoch,可选
+train_epochs=2
+#训练step
+train_steps=60000
+#学习率
+#learning_rate=1e-5
+
+#参数配置
+data_path=""
+
+if [[ $1 == --help || $1 == --h ]];then
+ echo "usage: ./train_performance_1p.sh"
+ exit 1
+fi
+
+for para in $*
+do
+ if [[ $para == --data_path* ]];then
+ data_path=`echo ${para#*=}`
+ fi
+done
+
+if [[ $data_path == "" ]];then
+ echo "[Error] para \"data_path \" must be config"
+ exit 1
+fi
+
+##############执行训练##########
+cd $cur_path
+
+if [ -d $cur_path/test/output ];then
+ rm -rf $cur_path/test/output/*
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+else
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+fi
+wait
+
+start=$(date +%s)
+nohup python3 knowledge_distillation.py --data_path=$data_path \
+ --epoch=$train_epochs \
+ --eval_static=True > $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 &
+wait
+
+end=$(date +%s)
+e2e_time=$(( $end - $start ))
+
+#echo "Final Performance ms/step : $average_perf"
+echo "Final Training Duration sec : $e2e_time"
+
+#结果打印,不需要修改
+echo "------------------ Final result ------------------"
+#输出性能FPS,需要模型审视修改
+TrainingTime=`grep 1875/1875 $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk '{print $3}'|awk 'NR==2'|tr -cd "[0-9]"`
+wait
+FPS=`awk 'BEGIN{printf "%.2f\n",'1875'*'${batch_size}'/'${TrainingTime}'}'`
+#打印,不需要修改
+echo "Final Performance images/sec : $FPS"
+
+#输出训练精度,需要模型审视修改
+train_accuracy=`grep sparse_categorical_accuracy $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log |awk 'END {print $NF}'`
+#打印,不需要修改
+echo "Final Train Accuracy : ${train_accuracy}"
+
+
+#精度看护结果汇总
+#训练用例信息,不需要修改
+BatchSize=${batch_size}
+DeviceType=`uname -m`
+CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf'
+
+##获取性能数据,不需要修改
+#吞吐量
+ActualFPS=${FPS}
+#单迭代训练时长
+TrainingTime=${TrainingTime}
+
+#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视
+grep student $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk '{print $9}' >> $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt
+#最后一个迭代loss值,不需要修改
+ActualLoss=`awk 'END {print $1}' $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt`
+
+#关键信息打印到${CaseName}.log中,不需要修改
+echo "Network = ${Network}" > $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "RankSize = ${RANK_SIZE}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "BatchSize = ${BatchSize}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "DeviceType = ${DeviceType}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "CaseName = ${CaseName}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualFPS = ${ActualFPS}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainingTime = ${TrainingTime}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualLoss = ${ActualLoss}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
diff --git a/TensorFlow2/built-in/keras_sample/learnable_resizer_ID2518_for_TensorFlow2.X/LICENSE b/TensorFlow2/built-in/keras_sample/learnable_resizer_ID2518_for_TensorFlow2.X/LICENSE
new file mode 100644
index 0000000000000000000000000000000000000000..ab652360b248f2947c2e3ccf306ca128660ea731
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/learnable_resizer_ID2518_for_TensorFlow2.X/LICENSE
@@ -0,0 +1,284 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+------------------
+Files: third_party/compute_library/...
+
+MIT License
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+
+------------------
+Files: ACKNOWLEDGEMENTS
+LICENSE
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+------------------
+Files: third_party/hexagon
+
+Copyright (c) 2016-2019, The Linux Foundation. All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted (subject to the limitations in the
+disclaimer below) provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+
+ * Neither the name of The Linux Foundation nor the names of its
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
+GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
+HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/TensorFlow2/built-in/keras_sample/learnable_resizer_ID2518_for_TensorFlow2.X/README.md b/TensorFlow2/built-in/keras_sample/learnable_resizer_ID2518_for_TensorFlow2.X/README.md
new file mode 100644
index 0000000000000000000000000000000000000000..f6f12e1ef4a901b70e05f7f60fdf99fdb0c20c7b
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/learnable_resizer_ID2518_for_TensorFlow2.X/README.md
@@ -0,0 +1,202 @@
+- [基本信息](#基本信息.md)
+- [概述](#概述.md)
+- [训练环境准备](#训练环境准备.md)
+- [快速上手](#快速上手.md)
+- [迁移学习指导](#迁移学习指导.md)
+- [高级参考](#高级参考.md)
+基本信息
+
+**发布者(Publisher):Huawei**
+
+**应用领域(Application Domain):Image Classification**
+
+**版本(Version):1.1**
+
+**修改时间(Modified) :2022.4.8**
+
+**大小(Size):51KB**
+
+**框架(Framework):TensorFlow_2.6.2**
+
+**模型格式(Model Format):ckpt**
+
+**精度(Precision):Mixed**
+
+**处理器(Processor):昇腾910**
+
+**应用级别(Categories):Official**
+
+**描述(Description):对于给定的图像分辨率和模型,如何最好地调整给定图像的大小,基于TensorFlow框架的训练代码**
+
+概述
+
+## 简述
+
+
+人们普遍认为,如果我们将视觉模型限制为像人类一样感知事物,他们的表现可以提高。人类大多使用形状描述符来开发共同的认知。但是这种信念是否始终适用,尤其是在改进方面视觉模型的表现?
+事实证明,情况可能并非总是如此。在训练视觉模型时,通常将图像大小调整为较低尺寸((224 x 224)、(299 x 299)等)以允许小批量学习并保持计算限制。我们一般使用图像此步骤的调整大小方法,如 双线性插值和调整大小的图像不会在人眼中失去太多的感性特征。在 [Learning to Resize Images for Computer Vision Tasks ], Talebi et al. 中显示如果我们尝试优化视觉模型的图像感知质量而不是人眼,它们的性能可以进一步提高。他们调查以下问题:
+**对于给定的图像分辨率和模型,如何最好地调整给定图像的大小?**
+如论文所示,这个想法有助于持续提高常见的视觉模型(在 ImageNet-1k 上预训练),如 DenseNet-121、ResNet-50、MobileNetV2 和 EfficientNets。在这个例子中,我们将实现可学习的图像按照论文中的建议调整模块大小,并使用Cats and Dogs数据集和DenseNet-121结构。
+
+- 参考论文:
+
+ https://arxiv.org/abs/2103.09950v1
+
+- 参考实现:
+
+ https://github.com/keras-team/keras-io/blob/master/examples/vision/learnable_resizer.py
+
+- 适配昇腾 AI 处理器的实现:
+
+ skip
+
+- 通过Git获取对应commit\_id的代码方法如下:
+
+ git clone {repository_url} # 克隆仓库的代码
+ cd {repository_name} # 切换到模型的代码仓目录
+ git checkout {branch} # 切换到对应分支
+ git reset --hard {commit_id} # 代码设置到对应的commit_id
+ cd {code_path} # 切换到模型代码所在路径,若仓库下只有该模型,则无需切换
+
+
+## 默认配置
+
+- 网络结构:
+ - DenseNet-121
+
+- 训练超参(单卡):
+ - Batch size: 64
+ - Input size: (300, 300)
+ - Target size: (150, 150)
+ - Interpolation: "bilinear"
+ - Train epoch: 5
+
+
+## 支持特性
+
+| 特性列表 | 是否支持 |
+| ---------- | -------- |
+| 分布式训练 | 否 |
+| 混合精度 | 是 |
+| 数据并行 | 否 |
+
+
+## 混合精度训练
+
+昇腾910 AI处理器提供自动混合精度功能,可以针对全网中float32数据类型的算子,按照内置的优化策略,自动将部分float32的算子降低精度到float16,从而在精度损失很小的情况下提升系统性能并减少内存使用。
+
+## 开启混合精度
+
+拉起脚本中,传入--precision_mode='allow_mix_precision'
+
+```
+ ./train_performance_1p_16bs.sh --help
+
+parameter explain:
+ --precision_mode precision mode(allow_fp32_to_fp16/force_fp16/must_keep_origin_dtype/allow_mix_precision)
+ --over_dump if or not over detection, default is False
+ --data_dump_flag data dump flag, default is False
+ --data_dump_step data dump step, default is 10
+ --profiling if or not profiling for performance debug, default is False
+ --data_path source data of training
+ -h/--help show help message
+```
+
+相关代码示例:
+
+```
+flags.DEFINE_string(name='precision_mode', default= 'allow_fp32_to_fp16',
+ help='allow_fp32_to_fp16/force_fp16/ '
+ 'must_keep_origin_dtype/allow_mix_precision.')
+
+npu_device.global_options().precision_mode=FLAGS.precision_mode
+```
+
+训练环境准备
+
+- 硬件环境和运行环境准备请参见《[CANN软件安装指南](https://support.huawei.com/enterprise/zh/ascend-computing/cann-pid-251168373?category=installation-update)》
+- 运行以下命令安装依赖。
+```
+pip3 install requirements.txt
+```
+说明:依赖配置文件requirements.txt文件位于模型的根目录
+
+快速上手
+
+## 数据集准备
+
+1、用户自行准备好数据集,本网络使用的数据集是Cats and Dogs数据集
+
+数据集目录参考如下:
+
+```
+├── cats_vs_dogs
+│ ├──4.0.0
+│ │ ├──cats_vs_dogs-train.tfrecord-00000-of-00008
+│ │ │ ......
+│ │ ├──cats_vs_dogs-train.tfrecord-00007-of-00008
+│ │ ├──dataset_info.json
+│ │ ├──features.json
+│ │ ├──label.labels.txt
+```
+
+
+
+## 模型训练
+
+- 单击“立即下载”,并选择合适的下载方式下载源码包。
+- 开始训练。
+
+ 1. 启动训练之前,首先要配置程序运行相关环境变量。
+
+ 环境变量配置信息参见:
+
+ [Ascend 910训练平台环境变量设置](https://gitee.com/ascend/modelzoo/wikis/Ascend%20910%E8%AE%AD%E7%BB%83%E5%B9%B3%E5%8F%B0%E7%8E%AF%E5%A2%83%E5%8F%98%E9%87%8F%E8%AE%BE%E7%BD%AE?sort_id=3148819)
+
+ 2. 单卡训练
+
+ 2. 1单卡训练指令(脚本位于learnable_resizer_ID2518_for_TensorFlow2.X/test/train_full.sh),需要先使用cd命令进入test目录下,再使用下面的命令启动训练。请确保下面例子中的“--data_path”修改为用户的数据路径,这里选择将cats_vs_dogs文件夹放在home目录下。
+
+ bash train_full_1p.sh --data_path=/home
+
+
+
+高级参考
+
+## 脚本和示例代码
+
+```
+|--LICENSE
+|--README.md #说明文档
+|--learnable_resizer.py #训练代码
+|--requirements.txt #所需依赖
+|--test #训练脚本目录
+| |--train_full_1p.sh #全量训练脚本
+| |--train_performance_1p_dynamic_eval.sh #performance动态shape训练脚本
+| |--train_performance_1p_static_eval.sh #performance静态shape训练脚本
+```
+
+## 脚本参数
+
+```
+--data_path # the path to train data
+--epoch # epochs of training
+--static # Whether it is a static shape
+--log_steps # TimeHis log Step
+--precision_mode # the path to save over dump data
+--over_dump # if or not over detection, default is False
+--data_dump_flag # data dump flag, default is False
+--data_dump_step # data dump step, default is 10
+--profiling # if or not profiling for performance debug, default is False
+--profiling_dump_path # the path to save profiling data
+--over_dump_path # the path to save over dump data
+--data_dump_path # the path to save dump data
+--use_mixlist # use_mixlist flag, default is False
+--fusion_off_flag # fusion_off flag, default is False
+--mixlist_file # mixlist file name, default is ops_info.json
+--fusion_off_file # fusion_off file name, default is fusion_switch.cfg
+```
+
+## 训练过程
+
+通过“模型训练”中的训练指令启动单卡或者多卡训练。单卡和多卡通过运行不同脚本,支持单卡,8卡网络训练。模型存储路径为${cur_path}/output/$ASCEND_DEVICE_ID,包括训练的log以及checkpoints文件。以8卡训练为例,loss信息在文件${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log中。
\ No newline at end of file
diff --git a/TensorFlow2/built-in/keras_sample/learnable_resizer_ID2518_for_TensorFlow2.X/learnable_resizer.py b/TensorFlow2/built-in/keras_sample/learnable_resizer_ID2518_for_TensorFlow2.X/learnable_resizer.py
new file mode 100644
index 0000000000000000000000000000000000000000..c12f04cadd13bb39ea5d098a2eecda54c7ac0822
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/learnable_resizer_ID2518_for_TensorFlow2.X/learnable_resizer.py
@@ -0,0 +1,414 @@
+#
+# Copyright 2017 The TensorFlow Authors. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============================================================================
+# Copyright 2021 Huawei Technologies Co., Ltd
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+
+
+"""
+Title: Learning to Resize in Computer Vision
+Author: [Sayak Paul](https://twitter.com/RisingSayak)
+Date created: 2021/04/30
+Last modified: 2021/05/13
+Description: How to optimally learn representations of images for a given resolution.
+"""
+"""
+It is a common belief that if we constrain vision models to perceive things as humans do,
+their performance can be improved. For example, in [this work](https://arxiv.org/abs/1811.12231),
+Geirhos et al. showed that the vision models pre-trained on the ImageNet-1k dataset are
+biased toward texture whereas human beings mostly use the shape descriptor to develop a
+common perception. But does this belief always apply especially when it comes to improving
+the performance of vision models?
+
+It turns out it may not always be the case. When training vision models, it is common to
+resize images to a lower dimension ((224 x 224), (299 x 299), etc.) to allow mini-batch
+learning and also to keep up the compute limitations. We generally make use of image
+resizing methods like **bilinear interpolation** for this step and the resized images do
+not lose much of their perceptual character to the human eyes. In
+[Learning to Resize Images for Computer Vision Tasks](https://arxiv.org/abs/2103.09950v1), Talebi et al. show
+that if we try to optimize the perceptual quality of the images for the vision models
+rather than the human eyes, their performance can further be improved. They investigate
+the following question:
+
+**For a given image resolution and a model, how to best resize the given images?**
+
+As shown in the paper, this idea helps to consistently improve the performance of the
+common vision models (pre-trained on ImageNet-1k) like DenseNet-121, ResNet-50,
+MobileNetV2, and EfficientNets. In this example, we will implement the learnable image
+resizing module as proposed in the paper and demonstrate that on the
+[Cats and Dogs dataset](https://www.microsoft.com/en-us/download/details.aspx?id=54765)
+using the [DenseNet-121](https://arxiv.org/abs/1608.06993) architecture.
+
+This example requires TensorFlow 2.4 or higher.
+"""
+
+"""
+## Setup
+"""
+
+import npu_device
+import time
+import ast
+import argparse
+
+from tensorflow.keras import layers
+from tensorflow import keras
+import tensorflow as tf
+
+import tensorflow_datasets as tfds
+
+tfds.disable_progress_bar()
+
+import numpy as np
+#===============================NPU Migration=========================================
+parser = argparse.ArgumentParser()
+parser.add_argument('--data_path', default="/home/data", type=str,
+ help='the path to train data')
+parser.add_argument('--epoch', default=2, type=int,
+ help='the epoch tos train ')
+parser.add_argument('--static', dest="static", type=ast.literal_eval,
+ help='Whether it is a static shape')
+parser.add_argument("--log_steps", default=145, type=int,
+ help="TimeHis log Step.")
+parser.add_argument('--precision_mode', default="allow_mix_precision", type=str,help='the path to save over dump data')
+parser.add_argument('--over_dump', dest='over_dump', type=ast.literal_eval,
+ help='if or not over detection, default is False')
+parser.add_argument('--data_dump_flag', dest='data_dump_flag', type=ast.literal_eval,
+ help='data dump flag, default is False')
+parser.add_argument('--data_dump_step', default="10",
+ help='data dump step, default is 10')
+parser.add_argument('--profiling', dest='profiling', type=ast.literal_eval,help='if or not profiling for performance debug, default is False')
+parser.add_argument('--profiling_dump_path', default="/home/data", type=str,help='the path to save profiling data')
+parser.add_argument('--over_dump_path', default="/home/data", type=str,help='the path to save over dump data')
+parser.add_argument('--data_dump_path', default="/home/data", type=str,help='the path to save dump data')
+parser.add_argument('--use_mixlist', dest='use_mixlist', type=ast.literal_eval,
+ help='use_mixlist flag, default is False')
+parser.add_argument('--fusion_off_flag', dest='fusion_off_flag', type=ast.literal_eval,
+ help='fusion_off flag, default is False')
+parser.add_argument('--mixlist_file', default="ops_info.json", type=str,help='mixlist file name, default is ops_info.json')
+parser.add_argument('--fusion_off_file', default="fusion_switch.cfg", type=str,help='fusion_off file name, default is fusion_switch.cfg')
+parser.add_argument('--auto_tune', dest='auto_tune', type=ast.literal_eval,help='auto_tune flag, default is False')
+args = parser.parse_args()
+
+def npu_config():
+ if args.data_dump_flag:
+ npu_device.global_options().dump_config.enable_dump = True
+ npu_device.global_options().dump_config.dump_path = args.data_dump_path
+ npu_device.global_options().dump_config.dump_step = args.data_dump_step
+ npu_device.global_options().dump_config.dump_mode = "all"
+
+ if args.over_dump:
+ npu_device.global_options().dump_config.enable_dump_debug = True
+ npu_device.global_options().dump_config.dump_path = args.over_dump_path
+ npu_device.global_options().dump_config.dump_debug_mode = "all"
+
+ if args.profiling:
+ npu_device.global_options().profiling_config.enable_profiling = True
+ profiling_options = '{"output":"' + args.profiling_dump_path + '", \
+ "training_trace":"on", \
+ "task_trace":"on", \
+ "aicpu":"on", \
+ "aic_metrics":"PipeUtilization",\
+ "fp_point":"", \
+ "bp_point":""}'
+ npu_device.global_options().profiling_config.profiling_options = profiling_options
+ npu_device.global_options().precision_mode = args.precision_mode
+ if args.use_mixlist and args.precision_mode=='allow_mix_precision':
+ npu_device.global_options().modify_mixlist=args.mixlist_file
+ if args.fusion_off_flag:
+ npu_device.global_options().fusion_switch_file=args.fusion_off_file
+ if args.auto_tune:
+ npu_device.global_options().auto_tune_mode="RL,GA"
+ npu_device.open().as_default()
+#===============================NPU Migration=========================================
+
+npu_config()
+
+"""
+## Define hyperparameters
+"""
+
+"""
+In order to facilitate mini-batch learning, we need to have a fixed shape for the images
+inside a given batch. This is why an initial resizing is required. We first resize all
+the images to (300 x 300) shape and then learn their optimal representation for the
+(150 x 150) resolution.
+"""
+
+INP_SIZE = (300, 300)
+TARGET_SIZE = (150, 150)
+INTERPOLATION = "bilinear"
+
+AUTO = tf.data.AUTOTUNE
+BATCH_SIZE = 64
+EPOCHS = args.epoch
+
+"""
+In this example, we will use the bilinear interpolation but the learnable image resizer
+module is not dependent on any specific interpolation method. We can also use others,
+such as bicubic.
+"""
+
+"""
+## Load and prepare the dataset
+
+For this example, we will only use 40% of the total training dataset.
+"""
+
+train_ds, validation_ds = tfds.load(
+ "cats_vs_dogs",
+ download=False,
+ data_dir=args.data_path,
+ split=["train[:40%]", "train[40%:50%]"],
+ as_supervised=True,
+)
+
+def preprocess_dataset(image, label):
+ image = tf.image.resize(image, (INP_SIZE[0], INP_SIZE[1]))
+ label = tf.one_hot(label, depth=2)
+ return (image, label)
+
+
+train_ds = (
+ train_ds.shuffle(BATCH_SIZE * 100)
+ .map(preprocess_dataset, num_parallel_calls=AUTO)
+ .batch(BATCH_SIZE, drop_remainder=args.static)
+ .prefetch(AUTO)
+)
+validation_ds = (
+ validation_ds.map(preprocess_dataset, num_parallel_calls=AUTO)
+ .batch(BATCH_SIZE, drop_remainder=args.static)
+ .prefetch(AUTO)
+)
+
+"""
+## Define the learnable resizer utilities
+
+The figure below (courtesy: [Learning to Resize Images for Computer Vision Tasks](https://arxiv.org/abs/2103.09950v1))
+presents the structure of the learnable resizing module:
+
+
+"""
+
+
+def conv_block(x, filters, kernel_size, strides, activation=layers.LeakyReLU(0.2)):
+ x = layers.Conv2D(filters, kernel_size, strides, padding="same", use_bias=False)(x)
+ x = layers.BatchNormalization()(x)
+ if activation:
+ x = activation(x)
+ return x
+
+
+def res_block(x):
+ inputs = x
+ x = conv_block(x, 16, 3, 1)
+ x = conv_block(x, 16, 3, 1, activation=None)
+ return layers.Add()([inputs, x])
+
+
+def get_learnable_resizer(filters=16, num_res_blocks=1, interpolation=INTERPOLATION):
+ inputs = layers.Input(shape=[None, None, 3])
+
+ # First, perform naive resizing.
+ naive_resize = layers.Resizing(*TARGET_SIZE, interpolation=interpolation)(inputs)
+
+ # First convolution block without batch normalization.
+ x = layers.Conv2D(filters=filters, kernel_size=7, strides=1, padding="same")(inputs)
+ x = layers.LeakyReLU(0.2)(x)
+
+ # Second convolution block with batch normalization.
+ x = layers.Conv2D(filters=filters, kernel_size=1, strides=1, padding="same")(x)
+ x = layers.LeakyReLU(0.2)(x)
+ x = layers.BatchNormalization()(x)
+
+ # Intermediate resizing as a bottleneck.
+ bottleneck = layers.Resizing(*TARGET_SIZE, interpolation=interpolation)(x)
+
+ # Residual passes.
+ for _ in range(num_res_blocks):
+ x = res_block(bottleneck)
+
+ # Projection.
+ x = layers.Conv2D(
+ filters=filters, kernel_size=3, strides=1, padding="same", use_bias=False
+ )(x)
+ x = layers.BatchNormalization()(x)
+
+ # Skip connection.
+ x = layers.Add()([bottleneck, x])
+
+ # Final resized image.
+ x = layers.Conv2D(filters=3, kernel_size=7, strides=1, padding="same")(x)
+ final_resize = layers.Add()([naive_resize, x])
+
+ return tf.keras.Model(inputs, final_resize, name="learnable_resizer")
+
+
+learnable_resizer = get_learnable_resizer()
+
+
+"""
+## Model building utility
+"""
+
+
+def get_model():
+ backbone = tf.keras.applications.DenseNet121(
+ weights=None,
+ include_top=True,
+ classes=2,
+ input_shape=((TARGET_SIZE[0], TARGET_SIZE[1], 3)),
+ )
+ backbone.trainable = True
+
+ inputs = layers.Input((INP_SIZE[0], INP_SIZE[1], 3))
+ x = layers.Rescaling(scale=1.0 / 255)(inputs)
+ x = learnable_resizer(x)
+ outputs = backbone(x)
+
+ return tf.keras.Model(inputs, outputs)
+
+
+"""
+The structure of the learnable image resizer module allows for flexible integrations with
+different vision models.
+"""
+
+"""
+## Compile and train our model with learnable resizer
+"""
+
+model = get_model()
+model.compile(
+ loss=keras.losses.CategoricalCrossentropy(label_smoothing=0.1),
+ optimizer="sgd",
+ metrics=["accuracy"],
+)
+
+class TimeHistory(tf.keras.callbacks.Callback):
+ def __init__(self, batch_size, log_steps, initial_step=0):
+ self.batch_size = batch_size
+ super(TimeHistory, self).__init__()
+ self.steps_before_epoch = initial_step
+ self.last_log_step = initial_step
+ self.log_steps = log_steps
+ self.steps_in_epoch = 0
+ #self.opt = optimizer
+ self.start_time = None
+
+ @property
+ def global_steps(self):
+ """The current 1-indexed global step."""
+ return self.steps_before_epoch + self.steps_in_epoch
+
+ def on_epoch_begin(self, epoch, logs=None):
+ if not self.start_time:
+ self.start_time = time.time()
+ self.epoch_start = time.time()
+
+ def on_batch_begin(self, batch, logs=None):
+ if not self.start_time:
+ self.start_time = time.time()
+
+ def on_batch_end(self, batch, logs=None):
+ self.steps_in_epoch = batch + 1
+ steps_since_last_log = self.global_steps - self.last_log_step
+ if steps_since_last_log >= self.log_steps:
+ now = time.time()
+ elapsed_time = now - self.start_time
+ steps_per_second = steps_since_last_log / elapsed_time
+ examples_per_second = steps_per_second * self.batch_size
+ print(
+ 'TimeHistory: %.2f seconds, %.2f examples/second between steps %d '
+ 'and %d'%(elapsed_time, examples_per_second, self.last_log_step,
+ self.global_steps),flush=True)
+ self.last_log_step = self.global_steps
+ self.start_time = None
+
+ def on_epoch_end(self, epoch, logs=None):
+ epoch_run_time = time.time() - self.epoch_start
+ self.steps_before_epoch += self.steps_in_epoch
+ self.steps_in_epoch = 0
+
+model.fit(train_ds, validation_data=validation_ds, epochs=EPOCHS, verbose=2, callbacks=[TimeHistory(BATCH_SIZE,args.log_steps)])
+
+"""
+The plot shows that the visuals of the images have improved with training. The following
+table shows the benefits of using the resizing module in comparison to using the bilinear
+interpolation:
+
+| Model | Number of parameters (Million) | Top-1 accuracy |
+|:-------------------------: |:-------------------------------: |:--------------: |
+| With the learnable resizer | 7.051717 | 67.67% |
+| Without the learnable resizer | 7.039554 | 60.19% |
+
+For more details, you can check out [this repository](https://github.com/sayakpaul/Learnable-Image-Resizing).
+Note the above-reported models were trained for 10 epochs on 90% of the training set of
+Cats and Dogs unlike this example. Also, note that the increase in the number of
+parameters due to the resizing module is very negligible. To ensure that the improvement
+in the performance is not due to stochasticity, the models were trained using the same
+initial random weights.
+
+Now, a question worth asking here is - _isn't the improved accuracy simply a consequence
+of adding more layers (the resizer is a mini network after all) to the model, compared to
+the baseline?_
+
+To show that it is not the case, the authors conduct the following experiment:
+
+* Take a pre-trained model trained some size, say (224 x 224).
+
+* Now, first, use it to infer predictions on images resized to a lower resolution. Record
+the performance.
+
+* For the second experiment, plug in the resizer module at the top of the pre-trained
+model and warm-start the training. Record the performance.
+
+Now, the authors argue that using the second option is better because it helps the model
+learn how to adjust the representations better with respect to the given resolution.
+Since the results purely are empirical, a few more experiments such as analyzing the
+cross-channel interaction would have been even better. It is worth noting that elements
+like [Squeeze and Excitation (SE) blocks](https://arxiv.org/abs/1709.01507), [Global Context (GC) blocks](https://arxiv.org/pdf/1904.11492) also add a few
+parameters to an existing network but they are known to help a network process
+information in systematic ways to improve the overall performance.
+"""
+
+"""
+## Notes
+
+* To impose shape bias inside the vision models, Geirhos et al. trained them with a
+combination of natural and stylized images. It might be interesting to investigate if
+this learnable resizing module could achieve something similar as the outputs seem to
+discard the texture information.
+
+* The resizer module can handle arbitrary resolutions and aspect ratios which is very
+important for tasks like object detection and segmentation.
+
+* There is another closely related topic on ***adaptive image resizing*** that attempts
+to resize images/feature maps adaptively during training. [EfficientV2](https://arxiv.org/pdf/2104.00298)
+uses this idea.
+"""
diff --git a/TensorFlow2/built-in/keras_sample/learnable_resizer_ID2518_for_TensorFlow2.X/modelzoo_level.txt b/TensorFlow2/built-in/keras_sample/learnable_resizer_ID2518_for_TensorFlow2.X/modelzoo_level.txt
new file mode 100644
index 0000000000000000000000000000000000000000..41666def85dde1920b31cd2284279cd465d60b91
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/learnable_resizer_ID2518_for_TensorFlow2.X/modelzoo_level.txt
@@ -0,0 +1,3 @@
+FuncStatus:OK
+PerfStatus:PERFECT
+PrecisionStatus:OK
\ No newline at end of file
diff --git a/TensorFlow2/built-in/keras_sample/learnable_resizer_ID2518_for_TensorFlow2.X/requirements.txt b/TensorFlow2/built-in/keras_sample/learnable_resizer_ID2518_for_TensorFlow2.X/requirements.txt
new file mode 100644
index 0000000000000000000000000000000000000000..662fa34ad41e9dbc895eeaecf624aad2902b8b76
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/learnable_resizer_ID2518_for_TensorFlow2.X/requirements.txt
@@ -0,0 +1,2 @@
+tensorflow>=2.4.0
+numpy
\ No newline at end of file
diff --git a/TensorFlow2/built-in/keras_sample/learnable_resizer_ID2518_for_TensorFlow2.X/test/train_full_1p.sh b/TensorFlow2/built-in/keras_sample/learnable_resizer_ID2518_for_TensorFlow2.X/test/train_full_1p.sh
new file mode 100644
index 0000000000000000000000000000000000000000..619ea5eca20e8461b4e3771cd33e49b9f6524c88
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/learnable_resizer_ID2518_for_TensorFlow2.X/test/train_full_1p.sh
@@ -0,0 +1,158 @@
+#!/bin/bash
+cur_path=`pwd`/../
+
+#基础参数,需要模型审视修改
+#Batch Size
+batch_size=64
+#网络名称,同目录名称
+Network="learnable_resizer_ID2518_for_TensorFlow2.X"
+#Device数量,单卡默认为1
+RANK_SIZE=1
+#训练epoch,可选
+train_epochs=5
+#训练step
+train_steps=60000
+#学习率
+#learning_rate=1e-5
+
+#参数配置
+data_path=""
+
+############维测参数##############
+precision_mode="allow_mix_precision"
+#维持参数,以下不需要修改
+over_dump=False
+if [[ $over_dump == True ]];then
+ over_dump_path=$cur_path/test/overflow_dump #此处cur_path为代码根目录
+ mkdir -p ${over_dump_path}
+fi
+data_dump_flag=False
+data_dump_step="10"
+profiling=False
+use_mixlist=False
+mixlist_file="./configs/ops_info.json"
+fusion_off_flag=False
+fusion_off_file="./configs/fusion_switch.cfg"
+############维测参数##############
+
+if [[ $1 == --help || $1 == --h ]];then
+ echo "usage: ./train_performance_1p.sh"
+ exit 1
+fi
+
+for para in $*
+do
+ if [[ $para == --data_path* ]];then
+ data_path=`echo ${para#*=}`
+ elif [[ $para == --precision_mode* ]];then
+ precision_mode=`echo ${para#*=}`
+ elif [[ $para == --over_dump* ]];then
+ over_dump=`echo ${para#*=}`
+ over_dump_path=${cur_path}/output/overflow_dump
+ mkdir -p ${over_dump_path}
+ elif [[ $para == --data_dump_flag* ]];then
+ data_dump_flag=`echo ${para#*=}`
+ data_dump_path=${cur_path}/output/data_dump
+ mkdir -p ${data_dump_path}
+ elif [[ $para == --data_dump_step* ]];then
+ data_dump_step=`echo ${para#*=}`
+ elif [[ $para == --profiling* ]];then
+ profiling=`echo ${para#*=}`
+ profiling_dump_path=${cur_path}/output/profiling
+ mkdir -p ${profiling_dump_path}
+ elif [[ $para == --data_path* ]];then
+ data_path=`echo ${para#*=}`
+ elif [[ $para == --use_mixlist* ]];then
+ use_mixlist=`echo ${para#*=}`
+ elif [[ $para == --mixlist_file* ]];then
+ mixlist_file=`echo ${para#*=}`
+ elif [[ $para == --fusion_off_flag* ]];then
+ fusion_off_flag=`echo ${para#*=}`
+ elif [[ $para == --fusion_off_file* ]];then
+ fusion_off_file=`echo ${para#*=}`
+ fi
+done
+
+if [[ $data_path == "" ]];then
+ echo "[Error] para \"data_path \" must be config"
+ exit 1
+fi
+
+##############执行训练##########
+cd $cur_path
+
+if [ -d $cur_path/test/output ];then
+ rm -rf $cur_path/test/output/*
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+else
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+fi
+wait
+
+start=$(date +%s)
+nohup python3 learnable_resizer.py --data_path=$data_path \
+ --epoch=$train_epochs \
+ --static=True \
+ --precision_mode=${precision_mode} \
+ --over_dump=${over_dump} \
+ --over_dump_path=${over_dump_path} \
+ --data_dump_flag=${data_dump_flag} \
+ --data_dump_step=${data_dump_step} \
+ --data_dump_path=${data_dump_path} \
+ --profiling=${profiling} \
+ --use_mixlist=${use_mixlist} \
+ --fusion_off_flag=${fusion_off_flag} \
+ --mixlist_file=${mixlist_file} \
+ --fusion_off_file=${fusion_off_file} \
+ --profiling_dump_path=${profiling_dump_path} > $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 &
+wait
+
+end=$(date +%s)
+e2e_time=$(( $end - $start ))
+
+echo "Final Training Duration sec : $e2e_time"
+
+#结果打印,不需要修改
+echo "------------------ Final result ------------------"
+#输出性能FPS,需要模型审视修改
+single_batch_step_sec=`grep TimeHistory $cur_path/test/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk 'END {print $4}'`
+FPS=`awk 'BEGIN{printf "%.2f\n",'${single_batch_step_sec}'}'`
+wait
+
+#打印,不需要修改
+echo "Final Performance images/sec : $FPS"
+
+#输出训练精度,需要模型审视修改
+train_accuracy=`grep val_loss $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | awk 'END {print$9}'`
+#打印,不需要修改
+echo "Final Train Accuracy : ${train_accuracy}"
+
+
+#精度看护结果汇总
+#训练用例信息,不需要修改
+BatchSize=${batch_size}
+DeviceType=`uname -m`
+CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc'
+
+##获取性能数据,不需要修改
+#吞吐量
+ActualFPS=${FPS}
+#单迭代训练时长
+TrainingTime=`awk 'BEGIN{printf "%.2f\n",'${BatchSize}'*'${RANK_SIZE}'*1000/'${FPS}'}'`
+
+#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视
+cat $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log| grep val_loss | awk -F " " '{print $6}' > $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt
+#最后一个迭代loss值,不需要修改
+ActualLoss=`awk 'END {print $1}' $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt`
+
+#关键信息打印到${CaseName}.log中,不需要修改
+echo "Network = ${Network}" > $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "RankSize = ${RANK_SIZE}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "BatchSize = ${BatchSize}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "DeviceType = ${DeviceType}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "CaseName = ${CaseName}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualFPS = ${ActualFPS}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainingTime = ${TrainingTime}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualLoss = ${ActualLoss}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
diff --git a/TensorFlow2/built-in/keras_sample/learnable_resizer_ID2518_for_TensorFlow2.X/test/train_performance_1p.sh b/TensorFlow2/built-in/keras_sample/learnable_resizer_ID2518_for_TensorFlow2.X/test/train_performance_1p.sh
new file mode 100644
index 0000000000000000000000000000000000000000..32d6f14b8ba9327c744eb52e9597146ccfd45a39
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/learnable_resizer_ID2518_for_TensorFlow2.X/test/train_performance_1p.sh
@@ -0,0 +1,158 @@
+#!/bin/bash
+cur_path=`pwd`/../
+
+#基础参数,需要模型审视修改
+#Batch Size
+batch_size=64
+#网络名称,同目录名称
+Network="learnable_resizer_ID2518_for_TensorFlow2.X"
+#Device数量,单卡默认为1
+RANK_SIZE=1
+#训练epoch,可选
+train_epochs=2
+#训练step
+train_steps=60000
+#学习率
+#learning_rate=1e-5
+
+#参数配置
+data_path=""
+
+############维测参数##############
+precision_mode="allow_mix_precision"
+#维持参数,以下不需要修改
+over_dump=False
+if [[ $over_dump == True ]];then
+ over_dump_path=$cur_path/test/overflow_dump #此处cur_path为代码根目录
+ mkdir -p ${over_dump_path}
+fi
+data_dump_flag=False
+data_dump_step="10"
+profiling=False
+use_mixlist=False
+mixlist_file="./configs/ops_info.json"
+fusion_off_flag=False
+fusion_off_file="./configs/fusion_switch.cfg"
+############维测参数##############
+
+if [[ $1 == --help || $1 == --h ]];then
+ echo "usage: ./train_performance_1p.sh"
+ exit 1
+fi
+
+for para in $*
+do
+ if [[ $para == --data_path* ]];then
+ data_path=`echo ${para#*=}`
+ elif [[ $para == --precision_mode* ]];then
+ precision_mode=`echo ${para#*=}`
+ elif [[ $para == --over_dump* ]];then
+ over_dump=`echo ${para#*=}`
+ over_dump_path=${cur_path}/output/overflow_dump
+ mkdir -p ${over_dump_path}
+ elif [[ $para == --data_dump_flag* ]];then
+ data_dump_flag=`echo ${para#*=}`
+ data_dump_path=${cur_path}/output/data_dump
+ mkdir -p ${data_dump_path}
+ elif [[ $para == --data_dump_step* ]];then
+ data_dump_step=`echo ${para#*=}`
+ elif [[ $para == --profiling* ]];then
+ profiling=`echo ${para#*=}`
+ profiling_dump_path=${cur_path}/output/profiling
+ mkdir -p ${profiling_dump_path}
+ elif [[ $para == --data_path* ]];then
+ data_path=`echo ${para#*=}`
+ elif [[ $para == --use_mixlist* ]];then
+ use_mixlist=`echo ${para#*=}`
+ elif [[ $para == --mixlist_file* ]];then
+ mixlist_file=`echo ${para#*=}`
+ elif [[ $para == --fusion_off_flag* ]];then
+ fusion_off_flag=`echo ${para#*=}`
+ elif [[ $para == --fusion_off_file* ]];then
+ fusion_off_file=`echo ${para#*=}`
+ fi
+done
+
+if [[ $data_path == "" ]];then
+ echo "[Error] para \"data_path \" must be config"
+ exit 1
+fi
+
+##############执行训练##########
+cd $cur_path
+
+if [ -d $cur_path/test/output ];then
+ rm -rf $cur_path/test/output/*
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+else
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+fi
+wait
+
+start=$(date +%s)
+nohup python3 learnable_resizer.py --data_path=$data_path \
+ --epoch=$train_epochs \
+ --static=False \
+ --precision_mode=${precision_mode} \
+ --over_dump=${over_dump} \
+ --over_dump_path=${over_dump_path} \
+ --data_dump_flag=${data_dump_flag} \
+ --data_dump_step=${data_dump_step} \
+ --data_dump_path=${data_dump_path} \
+ --profiling=${profiling} \
+ --use_mixlist=${use_mixlist} \
+ --fusion_off_flag=${fusion_off_flag} \
+ --mixlist_file=${mixlist_file} \
+ --fusion_off_file=${fusion_off_file} \
+ --profiling_dump_path=${profiling_dump_path} > $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 &
+wait
+
+end=$(date +%s)
+e2e_time=$(( $end - $start ))
+
+echo "Final Training Duration sec : $e2e_time"
+
+#结果打印,不需要修改
+echo "------------------ Final result ------------------"
+#输出性能FPS,需要模型审视修改
+single_batch_step_sec=`grep TimeHistory $cur_path/test/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk 'END {print $4}'`
+FPS=`awk 'BEGIN{printf "%.2f\n",'${single_batch_step_sec}'}'`
+wait
+
+#打印,不需要修改
+echo "Final Performance images/sec : $FPS"
+
+#输出训练精度,需要模型审视修改
+train_accuracy=`grep val_loss $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | awk 'END {print$9}'`
+#打印,不需要修改
+echo "Final Train Accuracy : ${train_accuracy}"
+
+
+#精度看护结果汇总
+#训练用例信息,不需要修改
+BatchSize=${batch_size}
+DeviceType=`uname -m`
+CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf'
+
+##获取性能数据,不需要修改
+#吞吐量
+ActualFPS=${FPS}
+#单迭代训练时长
+TrainingTime=`awk 'BEGIN{printf "%.2f\n",'${BatchSize}'*'${RANK_SIZE}'*1000/'${FPS}'}'`
+
+#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视
+cat $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log| grep val_loss | awk -F " " '{print $6}' > $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt
+#最后一个迭代loss值,不需要修改
+ActualLoss=`awk 'END {print $1}' $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt`
+
+#关键信息打印到${CaseName}.log中,不需要修改
+echo "Network = ${Network}" > $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "RankSize = ${RANK_SIZE}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "BatchSize = ${BatchSize}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "DeviceType = ${DeviceType}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "CaseName = ${CaseName}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualFPS = ${ActualFPS}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainingTime = ${TrainingTime}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualLoss = ${ActualLoss}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
diff --git a/TensorFlow2/built-in/keras_sample/learnable_resizer_ID2518_for_TensorFlow2.X/test/train_performance_1p_dynamic_eval.sh b/TensorFlow2/built-in/keras_sample/learnable_resizer_ID2518_for_TensorFlow2.X/test/train_performance_1p_dynamic_eval.sh
new file mode 100644
index 0000000000000000000000000000000000000000..0216a8edbaae3a6625099330f90b9efd39dfecab
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/learnable_resizer_ID2518_for_TensorFlow2.X/test/train_performance_1p_dynamic_eval.sh
@@ -0,0 +1,168 @@
+#!/bin/bash
+cur_path=`pwd`/../
+
+#基础参数,需要模型审视修改
+#Batch Size
+batch_size=64
+#网络名称,同目录名称
+Network="learnable_resizer_ID2518_for_TensorFlow2.X"
+#Device数量,单卡默认为1
+RANK_SIZE=1
+#训练epoch,可选
+train_epochs=1
+#训练step
+train_steps=60000
+#学习率
+#learning_rate=1e-5
+
+#参数配置
+data_path=""
+
+############维测参数##############
+precision_mode="allow_mix_precision"
+#维持参数,以下不需要修改
+over_dump=False
+if [[ $over_dump == True ]];then
+ over_dump_path=$cur_path/test/overflow_dump #此处cur_path为代码根目录
+ mkdir -p ${over_dump_path}
+fi
+data_dump_flag=False
+data_dump_step="10"
+profiling=False
+use_mixlist=False
+mixlist_file="./configs/ops_info.json"
+fusion_off_flag=False
+fusion_off_file="./configs/fusion_switch.cfg"
+############维测参数##############
+
+if [[ $1 == --help || $1 == --h ]];then
+ echo "usage: ./train_performance_1p.sh"
+ exit 1
+fi
+
+for para in $*
+do
+ if [[ $para == --data_path* ]];then
+ data_path=`echo ${para#*=}`
+ elif [[ $para == --precision_mode* ]];then
+ precision_mode=`echo ${para#*=}`
+ elif [[ $para == --over_dump* ]];then
+ over_dump=`echo ${para#*=}`
+ over_dump_path=${cur_path}/output/overflow_dump
+ mkdir -p ${over_dump_path}
+ elif [[ $para == --data_dump_flag* ]];then
+ data_dump_flag=`echo ${para#*=}`
+ data_dump_path=${cur_path}/output/data_dump
+ mkdir -p ${data_dump_path}
+ elif [[ $para == --data_dump_step* ]];then
+ data_dump_step=`echo ${para#*=}`
+ elif [[ $para == --profiling* ]];then
+ profiling=`echo ${para#*=}`
+ profiling_dump_path=${cur_path}/output/profiling
+ mkdir -p ${profiling_dump_path}
+ elif [[ $para == --data_path* ]];then
+ data_path=`echo ${para#*=}`
+ elif [[ $para == --use_mixlist* ]];then
+ use_mixlist=`echo ${para#*=}`
+ elif [[ $para == --mixlist_file* ]];then
+ mixlist_file=`echo ${para#*=}`
+ elif [[ $para == --fusion_off_flag* ]];then
+ fusion_off_flag=`echo ${para#*=}`
+ elif [[ $para == --fusion_off_file* ]];then
+ fusion_off_file=`echo ${para#*=}`
+ fi
+done
+
+if [[ $data_path == "" ]];then
+ echo "[Error] para \"data_path \" must be config"
+ exit 1
+fi
+
+##############执行训练##########
+cd $cur_path
+
+if [ -d $cur_path/test/output ];then
+ rm -rf $cur_path/test/output/*
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+else
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+fi
+wait
+
+start=$(date +%s)
+nohup python3 learnable_resizer.py --data_path=$data_path \
+ --epoch=$train_epochs \
+ --static=False \
+ --precision_mode=${precision_mode} \
+ --over_dump=${over_dump} \
+ --over_dump_path=${over_dump_path} \
+ --data_dump_flag=${data_dump_flag} \
+ --data_dump_step=${data_dump_step} \
+ --data_dump_path=${data_dump_path} \
+ --profiling=${profiling} \
+ --use_mixlist=${use_mixlist} \
+ --fusion_off_flag=${fusion_off_flag} \
+ --mixlist_file=${mixlist_file} \
+ --fusion_off_file=${fusion_off_file} \
+ --profiling_dump_path=${profiling_dump_path} > $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 &
+wait
+
+end=$(date +%s)
+e2e_time=$(( $end - $start ))
+
+echo "Final Training Duration sec : $e2e_time"
+
+#结果打印,不需要修改
+echo "------------------ Final result ------------------"
+#输出性能FPS,需要模型审视修改
+single_batch_step_sec=`grep TimeHistory $cur_path/test/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk 'END {print $4}'`
+FPS=`awk 'BEGIN{printf "%.2f\n",'${single_batch_step_sec}'}'`
+wait
+
+#打印,不需要修改
+echo "Final Performance images/sec : $FPS"
+
+#输出训练精度,需要模型审视修改
+train_accuracy=`grep val_loss $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | awk 'END {print$9}'`
+#打印,不需要修改
+echo "Final Train Accuracy : ${train_accuracy}"
+
+
+#精度看护结果汇总
+#训练用例信息,不需要修改
+BatchSize=${batch_size}
+DeviceType=`uname -m`
+CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf'
+
+##获取性能数据,不需要修改
+#吞吐量
+ActualFPS=${FPS}
+#单迭代训练时长
+TrainingTime=`awk 'BEGIN{printf "%.2f\n",'${BatchSize}'*'${RANK_SIZE}'*1000/'${FPS}'}'`
+
+#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视
+cat $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log| grep val_loss | awk -F " " '{print $6}' > $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt
+#最后一个迭代loss值,不需要修改
+ActualLoss=`awk 'END {print $1}' $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt`
+
+ModelStatus="图执行FAIL"
+DTS_Number="DTS2022010611495"
+# error_msg="E19999"
+error_msg="Optype \[Conv2DBackpropFilter\] of Ops kernel \[AIcoreEngine\] is unsupported."
+Status=`grep "${error_msg}" $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|wc -l`
+
+#关键信息打印到${CaseName}.log中,不需要修改
+echo "Network = ${Network}" > $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "RankSize = ${RANK_SIZE}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "BatchSize = ${BatchSize}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "DeviceType = ${DeviceType}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "CaseName = ${CaseName}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ModelStatus = ${ModelStatus}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "DTS_Number = ${DTS_Number}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "Status = ${Status}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "error_msg = ${error_msg}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+#echo "ActualFPS = ${ActualFPS}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+#echo "TrainingTime = ${TrainingTime}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+#echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+#echo "ActualLoss = ${ActualLoss}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
diff --git a/TensorFlow2/built-in/keras_sample/learnable_resizer_ID2518_for_TensorFlow2.X/test/train_performance_1p_static_eval.sh b/TensorFlow2/built-in/keras_sample/learnable_resizer_ID2518_for_TensorFlow2.X/test/train_performance_1p_static_eval.sh
new file mode 100644
index 0000000000000000000000000000000000000000..f753b1e10553b192261d565a7e5e17328fc95a5b
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/learnable_resizer_ID2518_for_TensorFlow2.X/test/train_performance_1p_static_eval.sh
@@ -0,0 +1,158 @@
+#!/bin/bash
+cur_path=`pwd`/../
+
+#基础参数,需要模型审视修改
+#Batch Size
+batch_size=64
+#网络名称,同目录名称
+Network="learnable_resizer_ID2518_for_TensorFlow2.X"
+#Device数量,单卡默认为1
+RANK_SIZE=1
+#训练epoch,可选
+train_epochs=3
+#训练step
+train_steps=60000
+#学习率
+#learning_rate=1e-5
+
+#参数配置
+data_path=""
+
+############维测参数##############
+precision_mode="allow_mix_precision"
+#维持参数,以下不需要修改
+over_dump=False
+if [[ $over_dump == True ]];then
+ over_dump_path=$cur_path/test/overflow_dump #此处cur_path为代码根目录
+ mkdir -p ${over_dump_path}
+fi
+data_dump_flag=False
+data_dump_step="10"
+profiling=False
+use_mixlist=False
+mixlist_file="./configs/ops_info.json"
+fusion_off_flag=False
+fusion_off_file="./configs/fusion_switch.cfg"
+############维测参数##############
+
+if [[ $1 == --help || $1 == --h ]];then
+ echo "usage: ./train_performance_1p.sh"
+ exit 1
+fi
+
+for para in $*
+do
+ if [[ $para == --data_path* ]];then
+ data_path=`echo ${para#*=}`
+ elif [[ $para == --precision_mode* ]];then
+ precision_mode=`echo ${para#*=}`
+ elif [[ $para == --over_dump* ]];then
+ over_dump=`echo ${para#*=}`
+ over_dump_path=${cur_path}/output/overflow_dump
+ mkdir -p ${over_dump_path}
+ elif [[ $para == --data_dump_flag* ]];then
+ data_dump_flag=`echo ${para#*=}`
+ data_dump_path=${cur_path}/output/data_dump
+ mkdir -p ${data_dump_path}
+ elif [[ $para == --data_dump_step* ]];then
+ data_dump_step=`echo ${para#*=}`
+ elif [[ $para == --profiling* ]];then
+ profiling=`echo ${para#*=}`
+ profiling_dump_path=${cur_path}/output/profiling
+ mkdir -p ${profiling_dump_path}
+ elif [[ $para == --data_path* ]];then
+ data_path=`echo ${para#*=}`
+ elif [[ $para == --use_mixlist* ]];then
+ use_mixlist=`echo ${para#*=}`
+ elif [[ $para == --mixlist_file* ]];then
+ mixlist_file=`echo ${para#*=}`
+ elif [[ $para == --fusion_off_flag* ]];then
+ fusion_off_flag=`echo ${para#*=}`
+ elif [[ $para == --fusion_off_file* ]];then
+ fusion_off_file=`echo ${para#*=}`
+ fi
+done
+
+if [[ $data_path == "" ]];then
+ echo "[Error] para \"data_path \" must be config"
+ exit 1
+fi
+
+##############执行训练##########
+cd $cur_path
+
+if [ -d $cur_path/test/output ];then
+ rm -rf $cur_path/test/output/*
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+else
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+fi
+wait
+
+start=$(date +%s)
+nohup python3 learnable_resizer.py --data_path=$data_path \
+ --epoch=$train_epochs \
+ --static=True \
+ --precision_mode=${precision_mode} \
+ --over_dump=${over_dump} \
+ --over_dump_path=${over_dump_path} \
+ --data_dump_flag=${data_dump_flag} \
+ --data_dump_step=${data_dump_step} \
+ --data_dump_path=${data_dump_path} \
+ --profiling=${profiling} \
+ --use_mixlist=${use_mixlist} \
+ --fusion_off_flag=${fusion_off_flag} \
+ --mixlist_file=${mixlist_file} \
+ --fusion_off_file=${fusion_off_file} \
+ --profiling_dump_path=${profiling_dump_path} > $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 &
+wait
+
+end=$(date +%s)
+e2e_time=$(( $end - $start ))
+
+echo "Final Training Duration sec : $e2e_time"
+
+#结果打印,不需要修改
+echo "------------------ Final result ------------------"
+#输出性能FPS,需要模型审视修改
+single_batch_step_sec=`grep TimeHistory $cur_path/test/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk 'END {print $4}'`
+FPS=`awk 'BEGIN{printf "%.2f\n",'${single_batch_step_sec}'}'`
+wait
+
+#打印,不需要修改
+echo "Final Performance images/sec : $FPS"
+
+#输出训练精度,需要模型审视修改
+train_accuracy=`grep val_loss $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | awk 'END {print$9}'`
+#打印,不需要修改
+echo "Final Train Accuracy : ${train_accuracy}"
+
+
+#精度看护结果汇总
+#训练用例信息,不需要修改
+BatchSize=${batch_size}
+DeviceType=`uname -m`
+CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf'
+
+##获取性能数据,不需要修改
+#吞吐量
+ActualFPS=${FPS}
+#单迭代训练时长
+TrainingTime=`awk 'BEGIN{printf "%.2f\n",'${BatchSize}'*'${RANK_SIZE}'*1000/'${FPS}'}'`
+
+#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视
+cat $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log| grep val_loss | awk -F " " '{print $6}' > $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt
+#最后一个迭代loss值,不需要修改
+ActualLoss=`awk 'END {print $1}' $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt`
+
+#关键信息打印到${CaseName}.log中,不需要修改
+echo "Network = ${Network}" > $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "RankSize = ${RANK_SIZE}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "BatchSize = ${BatchSize}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "DeviceType = ${DeviceType}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "CaseName = ${CaseName}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualFPS = ${ActualFPS}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainingTime = ${TrainingTime}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualLoss = ${ActualLoss}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
diff --git a/TensorFlow2/built-in/keras_sample/mnist_convnet_ID2524_for_TensorFlow2.X/LICENSE b/TensorFlow2/built-in/keras_sample/mnist_convnet_ID2524_for_TensorFlow2.X/LICENSE
new file mode 100644
index 0000000000000000000000000000000000000000..ab652360b248f2947c2e3ccf306ca128660ea731
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/mnist_convnet_ID2524_for_TensorFlow2.X/LICENSE
@@ -0,0 +1,284 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+------------------
+Files: third_party/compute_library/...
+
+MIT License
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+
+------------------
+Files: ACKNOWLEDGEMENTS
+LICENSE
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+------------------
+Files: third_party/hexagon
+
+Copyright (c) 2016-2019, The Linux Foundation. All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted (subject to the limitations in the
+disclaimer below) provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+
+ * Neither the name of The Linux Foundation nor the names of its
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
+GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
+HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/TensorFlow2/built-in/keras_sample/mnist_convnet_ID2524_for_TensorFlow2.X/README.md b/TensorFlow2/built-in/keras_sample/mnist_convnet_ID2524_for_TensorFlow2.X/README.md
new file mode 100644
index 0000000000000000000000000000000000000000..f65d8b44cda30b2f6b4775fbbc1b58a018a8b3b0
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/mnist_convnet_ID2524_for_TensorFlow2.X/README.md
@@ -0,0 +1,175 @@
+- [基本信息](#基本信息.md)
+- [概述](#概述.md)
+- [训练环境准备](#训练环境准备.md)
+- [快速上手](#快速上手.md)
+- [迁移学习指导](#迁移学习指导.md)
+- [高级参考](#高级参考.md)
+
+基本信息
+
+**发布者(Publisher):Huawei**
+
+**应用领域(Application Domain):Image Classification**
+
+**版本(Version):1.1**
+
+**修改时间(Modified) :2021.10.01**
+
+**大小(Size)**_**:324KB**
+
+**框架(Framework):TensorFlow 2.4.1**
+
+**模型格式(Model Format):ckpt**
+
+**精度(Precision):Mixed**
+
+**处理器(Processor):昇腾910**
+
+**应用级别(Categories):Benchmark**
+
+**描述(Description):基于TensorFlow框架的计算机视觉网络训练代码**
+
+概述
+
+- keras官方的vision网络。
+
+- 参考论文:
+ skip
+- 参考实现:
+
+ [https://github.com/keras-team/keras-io/tree/master/examples/vision](https://github.com/keras-team/keras-io/tree/master/examples/vision)
+
+- 适配昇腾 AI 处理器的实现:
+
+ skip
+
+- 通过Git获取对应commit\_id的代码方法如下:
+
+ ```
+ git clone {repository_url} # 克隆仓库的代码
+ cd {repository_name} # 切换到模型的代码仓目录
+ git checkout {branch} # 切换到对应分支
+ git reset --hard {commit_id} # 代码设置到对应的commit_id
+ cd {code_path} # 切换到模型代码所在路径,若仓库下只有该模型,则无需切换
+ ```
+
+## 默认配置
+- 网络结构
+
+- 训练超参(单卡):
+ - Batch size:128
+ - Train epochs:15
+
+
+## 支持特性
+
+| 特性列表 | 是否支持 |
+| ---------- | -------- |
+| 分布式训练 | 否 |
+| 混合精度 | 是 |
+| 数据并行 | 否 |
+
+
+## 混合精度训练
+
+昇腾910 AI处理器提供自动混合精度功能,可以针对全网中float32数据类型的算子,按照内置的优化策略,自动将部分float32的算子降低精度到float16,从而在精度损失很小的情况下提升系统性能并减少内存使用。
+
+## 开启混合精度
+相关代码示例。
+
+```
+config_proto = tf.ConfigProto(allow_soft_placement=True)
+ custom_op = config_proto.graph_options.rewrite_options.custom_optimizers.add()
+ custom_op.name = 'NpuOptimizer'
+ custom_op.parameter_map["use_off_line"].b = True
+ custom_op.parameter_map["precision_mode"].s = tf.compat.as_bytes("allow_mix_precision")
+ config_proto.graph_options.rewrite_options.remapping = RewriterConfig.OFF
+ session_config = npu_config_proto(config_proto=config_proto)
+```
+
+训练环境准备
+
+- 硬件环境和运行环境准备请参见《[CANN软件安装指南](https://support.huawei.com/enterprise/zh/ascend-computing/cann-pid-251168373?category=installation-update)》
+- 运行以下命令安装依赖。
+```
+pip3 install requirements.txt
+```
+说明:依赖配置文件requirements.txt文件位于模型的根目录
+
+
+快速上手
+
+## 数据集准备
+
+1. 模型训练使用百度魅族深度学习比赛初赛数据集,数据集请用户自行获取。
+2. 数据集下载完毕后,请用户使用代码目录下helper.py修改相关路径后生成训练所需文件。
+
+## 模型训练
+- 单击“立即下载”,并选择合适的下载方式下载源码包。
+- 开始训练。
+
+ 1. 启动训练之前,首先要配置程序运行相关环境变量。
+
+ 环境变量配置信息参见:
+
+ [Ascend 910训练平台环境变量设置](https://gitee.com/ascend/modelzoo/wikis/Ascend%20910%E8%AE%AD%E7%BB%83%E5%B9%B3%E5%8F%B0%E7%8E%AF%E5%A2%83%E5%8F%98%E9%87%8F%E8%AE%BE%E7%BD%AE?sort_id=3148819)
+
+
+ 2. 单卡训练
+
+ 2.1 设置单卡训练参数(脚本位于DIN_ID2641_for_TensorFlow2.X/test/train_performance_1p.sh),示例如下。
+
+
+ ```
+ batch_size=128
+ #训练step
+ train_epochs=15
+ ```
+
+ 2.2 单卡训练指令(脚本位于DIN_ID2641_for_TensorFlow2.X/test)
+
+ ```
+ 于终端中运行export ASCEND_DEVICE_ID=0 (0~7)以指定单卡训练时使用的卡
+ bash train_full_1p.sh --data_path=xx
+ 数据集应有如下结构(数据切分可能不同)
+ |
+ ├─mnist.npz
+
+ ```
+
+迁移学习指导
+
+- 数据集准备。
+
+ 1. 获取数据。
+ 请参见“快速上手”中的数据集准备
+
+- 模型训练
+
+ 请参考“快速上手”章节
+
+高级参考
+
+## 脚本和示例代码
+
+ ├── README.md //说明文档
+ ├── requirements.txt //依赖
+ ├── mnist_convnet.py
+ ├── npu_convnet_dropout.py
+ ├── npu_ops.py
+ ├── test
+ | |—— train_full_1p.sh //单卡训练脚本
+ | |—— train_performance_1p.sh //单卡训练脚本
+
+## 脚本参数
+
+```
+batch_size 训练batch_size
+train_epochs 总训练epoch数
+其余参数请在utils.py中配置flag默认值
+```
+
+## 训练过程
+
+通过“模型训练”中的训练指令启动单卡训练。
+将训练脚本(train_full_1p.sh)中的data_path设置为训练数据集的路径。具体的流程参见“模型训练”的示例。
\ No newline at end of file
diff --git a/TensorFlow2/built-in/keras_sample/mnist_convnet_ID2524_for_TensorFlow2.X/mnist_convnet.py b/TensorFlow2/built-in/keras_sample/mnist_convnet_ID2524_for_TensorFlow2.X/mnist_convnet.py
new file mode 100644
index 0000000000000000000000000000000000000000..9d955f89ba9531792426298b8955af741148b90e
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/mnist_convnet_ID2524_for_TensorFlow2.X/mnist_convnet.py
@@ -0,0 +1,259 @@
+#
+# Copyright 2017 The TensorFlow Authors. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============================================================================
+# Copyright 2021 Huawei Technologies Co., Ltd
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+"""
+Title: Simple MNIST convnet
+Author: [fchollet](https://twitter.com/fchollet)
+Date created: 2015/06/19
+Last modified: 2020/04/21
+Description: A simple convnet that achieves ~99% test accuracy on MNIST.
+"""
+
+"""
+## Setup
+"""
+import os
+import ast
+import argparse
+import numpy as np
+import tensorflow as tf
+from tensorflow import keras
+from tensorflow.keras import layers
+import npu_convert_dropout
+import npu_device
+import time
+# npu_device.open().as_default()
+
+"""
+## Prepare the data
+"""
+def parse_args():
+ parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
+ parser.add_argument('--data_path', default='./',
+ help="""directory to data""")
+ parser.add_argument('--batch_size', default=64, type=int,
+ help="""batch size for 1p""")
+ parser.add_argument('--epochs', default=50, type=int,
+ help="""epochs""")
+ parser.add_argument("--log_steps", default=50, type=int,
+ help="TimeHis log Step.")
+ parser.add_argument('--precision_mode', default="allow_mix_precision", type=str,
+ help='the path to save over dump data')
+ parser.add_argument('--over_dump', dest='over_dump', type=ast.literal_eval,
+ help='if or not over detection, default is False')
+ parser.add_argument('--data_dump_flag', dest='data_dump_flag', type=ast.literal_eval,
+ help='data dump flag, default is False')
+ parser.add_argument('--data_dump_step', default="10",
+ help='data dump step, default is 10')
+ parser.add_argument('--profiling', dest='profiling', type=ast.literal_eval,
+ help='if or not profiling for performance debug, default is False')
+ parser.add_argument('--profiling_dump_path', default="/home/data", type=str, help='the path to save profiling data')
+ parser.add_argument('--over_dump_path', default="/home/data", type=str, help='the path to save over dump data')
+ parser.add_argument('--data_dump_path', default="/home/data", type=str, help='the path to save dump data')
+ parser.add_argument('--use_mixlist', dest='use_mixlist', type=ast.literal_eval,
+ help='use_mixlist flag, default is False')
+ parser.add_argument('--fusion_off_flag', dest='fusion_off_flag', type=ast.literal_eval,
+ help='fusion_off flag, default is False')
+ parser.add_argument('--mixlist_file', default="ops_info.json", type=str,
+ help='mixlist file name, default is ops_info.json')
+ parser.add_argument('--fusion_off_file', default="fusion_switch.cfg", type=str,
+ help='fusion_off file name, default is fusion_switch.cfg')
+ parser.add_argument('--auto_tune', dest="auto_tune", type=ast.literal_eval,
+ help='auto_tune flag')
+ parser.add_argument('--static', dest="static", type=ast.literal_eval,
+ help="""judgement dynamic or static shape""")
+ '''
+ args, unknown_args = parser.parse_known_args()
+ if len(unknown_args) > 0:
+ for bad_arg in unknown_args:
+ print("ERROR: Unknown command line arg: %s" % bad_arg)
+ raise ValueError("Invalid command line arg(s)")
+ '''
+ return parser.parse_args()
+
+args = parse_args()
+#===============================NPU Migration=========================================
+def npu_config():
+ if args.data_dump_flag:
+ npu_device.global_options().dump_config.enable_dump = True
+ npu_device.global_options().dump_config.dump_path = args.data_dump_path
+ npu_device.global_options().dump_config.dump_step = args.data_dump_step
+ npu_device.global_options().dump_config.dump_mode = "all"
+
+ if args.over_dump:
+ npu_device.global_options().dump_config.enable_dump_debug = True
+ npu_device.global_options().dump_config.dump_path = args.over_dump_path
+ npu_device.global_options().dump_config.dump_debug_mode = "all"
+
+ if args.profiling:
+ npu_device.global_options().profiling_config.enable_profiling = True
+ profiling_options = '{"output":"' + args.profiling_dump_path + '", \
+ "training_trace":"on", \
+ "task_trace":"on", \
+ "aicpu":"on", \
+ "aic_metrics":"PipeUtilization",\
+ "fp_point":"", \
+ "bp_point":""}'
+ npu_device.global_options().profiling_config.profiling_options = profiling_options
+ npu_device.global_options().precision_mode = args.precision_mode
+ if args.use_mixlist and args.precision_mode=='allow_mix_precision':
+ npu_device.global_options().modify_mixlist="../configs/"+args.mixlist_file
+ if args.fusion_off_flag:
+ npu_device.global_options().fusion_switch_file="../configs/"+args.fusion_off_file
+ if args.auto_tune:
+ npu_device.global_options().auto_tune_mode="RL,GA"
+ npu_device.open().as_default()
+#===============================NPU Migration=========================================
+npu_config()
+data_dir = args.data_path
+
+# Model / data parameters
+num_classes = 10
+input_shape = (28, 28, 1)
+
+class TimeHistory(tf.keras.callbacks.Callback):
+ def __init__(self, batch_size, log_steps, initial_step=0):
+ self.batch_size = batch_size
+ super(TimeHistory, self).__init__()
+ self.steps_before_epoch = initial_step
+ self.last_log_step = initial_step
+ self.log_steps = log_steps
+ self.steps_in_epoch = 0
+ #self.opt = optimizer
+ self.start_time = None
+
+ @property
+ def global_steps(self):
+ """The current 1-indexed global step."""
+ return self.steps_before_epoch + self.steps_in_epoch
+
+ def on_epoch_begin(self, epoch, logs=None):
+ if not self.start_time:
+ self.start_time = time.time()
+ self.epoch_start = time.time()
+
+ def on_batch_begin(self, batch, logs=None):
+ if not self.start_time:
+ self.start_time = time.time()
+
+ def on_batch_end(self, batch, logs=None):
+ self.steps_in_epoch = batch + 1
+ steps_since_last_log = self.global_steps - self.last_log_step
+ if steps_since_last_log >= self.log_steps:
+ now = time.time()
+ elapsed_time = now - self.start_time
+ steps_per_second = steps_since_last_log / elapsed_time
+ examples_per_second = steps_per_second * self.batch_size
+ print(
+ 'TimeHistory: %.2f seconds, %.2f examples/second between steps %d '
+ 'and %d'%(elapsed_time, examples_per_second, self.last_log_step,
+ self.global_steps),flush=True)
+ self.last_log_step = self.global_steps
+ self.start_time = None
+
+# the data, split between train and test sets
+#(x_train, y_train), (x_test, y_test) = keras.datasets.mnist.load_data()
+def load_data(data_dir):
+ origin_folder = 'https://storage.googleapis.com/tensorflow/tf-keras-datasets/'
+ dirname = 'mnist.npz'
+ path = os.path.join(data_dir, dirname)
+ with np.load(path, allow_pickle=True) as f:
+ x_train, y_train = f['x_train'], f['y_train']
+ x_test, y_test = f['x_test'], f['y_test']
+ return (x_train, y_train), (x_test, y_test)
+(x_train, y_train), (x_test, y_test) = load_data(data_dir)
+
+#if args.eval_static:
+# x_train = x_train[:59968]
+# y_train = y_train[:59968]
+# x_test = x_test[:9984]
+# y_test = y_test[:9984]
+
+# Scale images to the [0, 1] range
+x_train = x_train.astype("float32") / 255
+x_test = x_test.astype("float32") / 255
+# Make sure images have shape (28, 28, 1)
+x_train = np.expand_dims(x_train, -1)
+x_test = np.expand_dims(x_test, -1)
+print("x_train shape:", x_train.shape)
+print(x_train.shape[0], "train samples")
+print(x_test.shape[0], "test samples")
+
+
+# convert class vectors to binary class matrices
+y_train = keras.utils.to_categorical(y_train, num_classes)
+y_test = keras.utils.to_categorical(y_test, num_classes)
+
+"""
+## Build the model
+"""
+
+model = keras.Sequential(
+ [
+ keras.Input(shape=input_shape),
+ layers.Conv2D(32, kernel_size=(3, 3), activation="relu"),
+ layers.MaxPooling2D(pool_size=(2, 2)),
+ layers.Conv2D(64, kernel_size=(3, 3), activation="relu"),
+ layers.MaxPooling2D(pool_size=(2, 2)),
+ layers.Flatten(),
+ layers.Dropout(0.5),
+ layers.Dense(num_classes, activation="softmax"),
+ ]
+)
+
+model.summary()
+
+"""
+## Train the model
+"""
+
+#batch_size = 128
+batch_size = args.batch_size
+#epochs = 15
+epochs = args.epochs
+
+model.compile(loss="categorical_crossentropy", optimizer="adam", metrics=["accuracy"])
+if args.static:
+ train_ds = (tf.data.Dataset.from_tensor_slices((x_train, y_train))
+ .shuffle(args.batch_size)
+ .batch(args.batch_size, drop_remainder=args.static)
+ )
+ model.fit(train_ds, batch_size=batch_size, epochs=epochs, callbacks=[TimeHistory(batch_size,844)], verbose=2)
+else:
+ model.fit(x_train, y_train, batch_size=batch_size, epochs=epochs, validation_split=0.1, callbacks=[TimeHistory(batch_size,844)], verbose=2)
+#model.fit(x_train, y_train, batch_size=batch_size, epochs=epochs, validation_split=0.1)
+model.save_weights(filepath="mnist_convnet", save_format="tf")
+
+
+## Evaluate the trained model
+
+
+score = model.evaluate(x_test, y_test, verbose=0)
+print("Test loss:", score[0])
+print("Test accuracy:", score[1])
diff --git a/TensorFlow2/built-in/keras_sample/mnist_convnet_ID2524_for_TensorFlow2.X/modelzoo_level.txt b/TensorFlow2/built-in/keras_sample/mnist_convnet_ID2524_for_TensorFlow2.X/modelzoo_level.txt
new file mode 100644
index 0000000000000000000000000000000000000000..a829ab59b97a1022dd6fc33b59b7ae0d55009432
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/mnist_convnet_ID2524_for_TensorFlow2.X/modelzoo_level.txt
@@ -0,0 +1,3 @@
+FuncStatus:OK
+PerfStatus:NOK
+PrecisionStatus:OK
\ No newline at end of file
diff --git a/TensorFlow2/built-in/keras_sample/mnist_convnet_ID2524_for_TensorFlow2.X/npu_convert_dropout.py b/TensorFlow2/built-in/keras_sample/mnist_convnet_ID2524_for_TensorFlow2.X/npu_convert_dropout.py
new file mode 100644
index 0000000000000000000000000000000000000000..95f8689ce4da26c08f18a0fcb49c42eb7f1c8b06
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/mnist_convnet_ID2524_for_TensorFlow2.X/npu_convert_dropout.py
@@ -0,0 +1,54 @@
+#!/usr/bin/env python3
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============================================================================
+# Copyright 2021 Huawei Technologies Co., Ltd
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+from keras import backend
+from keras.utils import control_flow_util
+from keras.layers.core import Dropout
+from tensorflow.python.ops import array_ops
+from tensorflow.python.ops import nn
+import npu_ops
+
+def dropout_call(self, inputs, training=None):
+ """Make Keras Dropout to execute NPU dropout"""
+ if training is None:
+ training = backend.learning_phase()
+
+ def dropped_inputs():
+ return npu_ops.dropout(
+ inputs,
+ noise_shape=self._get_noise_shape(inputs),
+ seed=self.seed,
+ keep_prob=1 - self.rate)
+
+ output = control_flow_util.smart_cond(training,
+ dropped_inputs,
+ lambda : array_ops.identity(inputs))
+
+ return output
+
+Dropout.call = dropout_call
diff --git a/TensorFlow2/built-in/keras_sample/mnist_convnet_ID2524_for_TensorFlow2.X/npu_ops.py b/TensorFlow2/built-in/keras_sample/mnist_convnet_ID2524_for_TensorFlow2.X/npu_ops.py
new file mode 100644
index 0000000000000000000000000000000000000000..fa6f8f211c19e1bce9d78a90c7c11b6121efdbd7
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/mnist_convnet_ID2524_for_TensorFlow2.X/npu_ops.py
@@ -0,0 +1,256 @@
+# Copyright 2016 The TensorFlow Authors. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ==============================================================================
+# ============================================================================
+# Copyright 2021 Huawei Technologies Co., Ltd
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============================================================================
+
+"""Ops for collective operations implemented using hccl."""
+from __future__ import absolute_import
+from __future__ import division
+from __future__ import print_function
+
+
+import numbers
+from tensorflow.python.ops import array_ops
+from tensorflow.python.framework import tensor_shape
+from tensorflow.python.framework import ops
+from tensorflow.python.eager import context
+
+from npu_device import gen_npu_ops
+
+
+DEFAULT_GRAPH_SEED = 87654321
+_MAXINT32 = 2**31 - 1
+def LARSV2(input_weight,
+ input_grad,
+ weight_decay,
+ learning_rate,
+ hyperpara=0.001,
+ epsilon=0.00001,
+ use_clip=False,
+ name=None):
+ if context.executing_eagerly():
+ raise RuntimeError("tf.LARSV2() is not compatible with "
+ "eager execution.")
+
+ return gen_npu_ops.lars_v2(input_weight=input_weight,
+ input_grad=input_grad,
+ weight_decay=weight_decay,
+ learning_rate=learning_rate,
+ hyperpara=hyperpara,
+ epsilon=epsilon,
+ use_clip=use_clip,
+ name=name)
+
+
+def _truncate_seed(seed):
+ return seed % _MAXINT32 # Truncate to fit into 32-bit integer
+
+def get_seed(op_seed):
+ global_seed = ops.get_default_graph().seed
+
+ if global_seed is not None:
+ if op_seed is None:
+ op_seed = ops.get_default_graph()._last_id
+
+ seeds = _truncate_seed(global_seed), _truncate_seed(op_seed)
+ else:
+ if op_seed is not None:
+ seeds = DEFAULT_GRAPH_SEED, _truncate_seed(op_seed)
+ else:
+ seeds = None, None
+ # Avoid (0, 0) as the C++ ops interpret it as nondeterminism, which would
+ # be unexpected since Python docs say nondeterminism is (None, None).
+ if seeds == (0, 0):
+ return (0, _MAXINT32)
+ return seeds
+
+def _get_noise_shape(x, noise_shape):
+ # If noise_shape is none return immediately.
+ if noise_shape is None:
+ return array_ops.shape(x)
+
+ try:
+ # Best effort to figure out the intended shape.
+ # If not possible, let the op to handle it.
+ # In eager mode exception will show up.
+ noise_shape_ = tensor_shape.as_shape(noise_shape)
+ except (TypeError, ValueError):
+ return noise_shape
+
+ if x.shape.dims is not None and len(x.shape.dims) == len(noise_shape_.dims):
+ new_dims = []
+ for i, dim in enumerate(x.shape.dims):
+ if noise_shape_.dims[i].value is None and dim.value is not None:
+ new_dims.append(dim.value)
+ else:
+ new_dims.append(noise_shape_.dims[i].value)
+ return tensor_shape.TensorShape(new_dims)
+
+ return noise_shape
+
+def dropout(x, keep_prob, noise_shape=None, seed=None, name=None):
+ """The gradient for `gelu`.
+
+ Args:
+ x: A tensor with type is float.
+ keep_prob: A tensor, float, rate of every element reserved.
+ noise_shape: A 1-D tensor, with type int32, shape of keep/drop what random
+ generated.
+ seed: Random seed.
+ name: Layer name.
+
+ Returns:
+ A tensor.
+ """
+ if context.executing_eagerly():
+ raise RuntimeError("tf.dropout() is not compatible with "
+ "eager execution.")
+ x = ops.convert_to_tensor(x, name="x")
+ if not x.dtype.is_floating:
+ raise ValueError("x has to be a floating point tensor since it's going to"
+ " be scaled. Got a %s tensor instead." % x.dtype)
+ if isinstance(keep_prob, numbers.Real) and not 0 < keep_prob <= 1:
+ raise ValueError("keep_prob must be a scalar tensor or a float in the "
+ "range (0, 1], got %g" % keep_prob)
+ if isinstance(keep_prob, float) and keep_prob == 1:
+ return x
+ seed, seed2 = get_seed(seed)
+ noise_shape = _get_noise_shape(x, noise_shape)
+ gen_out = gen_npu_ops.drop_out_gen_mask(noise_shape, keep_prob, seed, seed2, name)
+ result = gen_npu_ops.drop_out_do_mask(x, gen_out, keep_prob, name)
+ return result
+
+@ops.RegisterGradient("DropOutDoMask")
+def _DropOutDoMaskGrad(op, grad):
+ result = gen_npu_ops.drop_out_do_mask(grad, op.inputs[1], op.inputs[2])
+ return [result, None, None]
+
+def basic_lstm_cell(x, h, c, w, b, keep_prob, forget_bias, state_is_tuple,
+ activation, name=None):
+ if context.executing_eagerly():
+ raise RuntimeError("tf.basic_lstm_cell() is not compatible with "
+ "eager execution.")
+ x = ops.convert_to_tensor(x, name="x")
+ h = ops.convert_to_tensor(h, name="h")
+ c = ops.convert_to_tensor(c, name="c")
+ w = ops.convert_to_tensor(w, name="w")
+ b = ops.convert_to_tensor(b, name="b")
+ result = gen_npu_ops.basic_lstm_cell(x, h, c, w, b, keep_prob, forget_bias, state_is_tuple,
+ activation, name)
+ return result
+
+@ops.RegisterGradient("BasicLSTMCell")
+def basic_lstm_cell_grad(op, dct, dht, dit, djt, dft, dot, dtanhct):
+
+ dgate, dct_1 = gen_npu_ops.basic_lstm_cell_c_state_grad(op.inputs[2], dht, dct, op.outputs[2], op.outputs[3], op.outputs[4], op.outputs[5], op.outputs[6], forget_bias=op.get_attr("forget_bias"), activation=op.get_attr("activation"))
+ dw, db = gen_npu_ops.basic_lstm_cell_weight_grad(op.inputs[0], op.inputs[1], dgate)
+ dxt, dht = gen_npu_ops.basic_lstm_cell_input_grad(dgate, op.inputs[3], keep_prob=op.get_attr("keep_prob"))
+
+ return [dxt, dht, dct_1, dw, db]
+
+def adam_apply_one_assign(input0, input1, input2, input3, input4,
+ mul0_x, mul1_x, mul2_x, mul3_x, add2_y, name=None):
+ if context.executing_eagerly():
+ raise RuntimeError("tf.adam_apply_one_assign() is not compatible with "
+ "eager execution.")
+ result = gen_npu_ops.adam_apply_one_assign(input0, input1, input2, input3, input4,
+ mul0_x, mul1_x, mul2_x, mul3_x, add2_y,name)
+ return result
+
+def adam_apply_one_with_decay_assign(input0, input1, input2, input3, input4,
+ mul0_x, mul1_x, mul2_x, mul3_x, mul4_x, add2_y, name=None):
+ if context.executing_eagerly():
+ raise RuntimeError("tf.adam_apply_one_with_decay_assign() is not compatible with "
+ "eager execution.")
+ result = gen_npu_ops.adam_apply_one_with_decay_assign(input0, input1, input2, input3, input4,
+ mul0_x, mul1_x, mul2_x, mul3_x, mul4_x, add2_y, name)
+ return result
+
+@ops.RegisterGradient("DynamicGruV2")
+def dynamic_gru_v2_grad(op, dy, doutput_h, dupdate, dreset, dnew, dhidden_new):
+ (x, weight_input, weight_hidden, bias_input, bias_hidden, seq_length, init_h) = op.inputs
+ (y, output_h, update, reset, new, hidden_new) = op.outputs
+ (dw_input, dw_hidden, db_input, db_hidden, dx, dh_prev) = gen_npu_ops.dynamic_gru_v2_grad(x, weight_input, weight_hidden, y, init_h, output_h, dy, doutput_h, update, reset, new, hidden_new, direction=op.get_attr("direction"), cell_depth=op.get_attr("cell_depth"), keep_prob=op.get_attr("keep_prob"), cell_clip=op.get_attr("cell_clip"), num_proj=op.get_attr("num_proj"), time_major=op.get_attr("time_major"), gate_order=op.get_attr("gate_order"), reset_after=op.get_attr("reset_after"))
+
+ return (dx, dw_input, dw_hidden, db_input, db_hidden, seq_length, dh_prev)
+
+@ops.RegisterGradient("DynamicRnn")
+def dynamic_rnn_grad(op, dy, dh, dc, di, dj, df, do, dtanhc):
+ (x, w, b, seq_length, init_h, init_c) = op.inputs
+ (y, output_h, output_c, i, j, f, o, tanhc) = op.outputs
+ (dw, db, dx, dh_prev, dc_prev) = gen_npu_ops.dynamic_rnn_grad(x, w, b, y, init_h[-1], init_c[-1], output_h, output_c, dy, dh[-1], dc[-1], i, j, f, o, tanhc, cell_type=op.get_attr("cell_type"), direction=op.get_attr("direction"), cell_depth=op.get_attr("cell_depth"), use_peephole=op.get_attr("use_peephole"), keep_prob=op.get_attr("keep_prob"), cell_clip=op.get_attr("cell_clip"), num_proj=op.get_attr("num_proj"), time_major=op.get_attr("time_major"), forget_bias=op.get_attr("forget_bias"))
+
+ return (dx, dw, db, seq_length, dh_prev, dc_prev)
+
+def lamb_apply_optimizer_assign(input0,input1,input2,input3,mul0_x,mul1_x,mul2_x,
+ mul3_x,add2_y,steps,do_use_weight,weight_decay_rate,name=None):
+ if context.executing_eagerly():
+ raise RuntimeError("tf.lamb_apply_optimizer_assign() is not compatible with eager execution")
+ update,nextv,nextm=gen_npu_ops.lamb_apply_optimizer_assign(input0,input1,input2,input3,mul0_x,mul1_x,mul2_x,
+ mul3_x,add2_y,steps,do_use_weight,weight_decay_rate,name)
+ return update,nextv,nextm
+
+def lamb_apply_weight_assign(input0,input1,input2,input3,input4,name=None):
+ if context.executing_eagerly():
+ raise RuntimeError("tf.lamb_apply_weight_assign() is not compatible with eager execution")
+ result = gen_npu_ops.lamb_apply_weight_assign(input0,input1,input2,input3,input4,name)
+ return result
+
+def dropout_v3(x, keep_prob, noise_shape=None, seed=None, name=None):
+ """ The gradient for gelu
+
+ Args:
+ x: A tensor with type is float
+ keep_prob: A tensor, float, rate of every element reserved
+ noise_shape: A 1-D tensor, with type int32, shape of keep/drop what random generated.
+ seed: Random seed.
+ name: Layer name.
+
+ Returns:
+ A tensor.
+ """
+ x = ops.convert_to_tensor(x,name="x")
+ if not x.dtype.is_floating:
+ raise ValueError("x has to be a floating point tensor since it's going to be scaled. Got a %s tensor instead." % x.dtype)
+
+ if isinstance(keep_prob,numbers.Real) and not 0 < keep_prob <=1:
+ raise ValueError("Keep_prob must be a scalar tensor or a float in the range (0,1], got %g" % keep_prob)
+
+ if isinstance(keep_prob,float) and keep_prob==1:
+ return x
+
+ seed, seed2 = get_seed(seed)
+ noise_shape = _get_noise_shape(x,noise_shape)
+ gen_out = gen_npu_ops.drop_out_gen_mask_v3(noise_shape,keep_prob,seed,seed2,name)
+ result = gen_npu_ops.drop_out_do_mask_v3(x, gen_out, keep_prob, name)
+ return result
+
+@ops.RegisterGradient("DropOutDoMaskV3")
+def _DropOutDoMaskV3Grad(op,grad):
+ result = gen_npu_ops.drop_out_do_mask_v3(grad, op.inputs[1], op.inputs[2])
+ return [result, None, None]
\ No newline at end of file
diff --git a/TensorFlow2/built-in/keras_sample/mnist_convnet_ID2524_for_TensorFlow2.X/requirements.txt b/TensorFlow2/built-in/keras_sample/mnist_convnet_ID2524_for_TensorFlow2.X/requirements.txt
new file mode 100644
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
diff --git a/TensorFlow2/built-in/keras_sample/mnist_convnet_ID2524_for_TensorFlow2.X/run_1p.sh b/TensorFlow2/built-in/keras_sample/mnist_convnet_ID2524_for_TensorFlow2.X/run_1p.sh
new file mode 100644
index 0000000000000000000000000000000000000000..00e54b0e394c5c436e137ec2ae626a485e51d154
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/mnist_convnet_ID2524_for_TensorFlow2.X/run_1p.sh
@@ -0,0 +1,2 @@
+cur_path='pwd'
+python3 ${cur_path}/mnist_convnet.py > loss+perf_gpu.txt 2>&1
\ No newline at end of file
diff --git a/TensorFlow2/built-in/keras_sample/mnist_convnet_ID2524_for_TensorFlow2.X/test/train_full_1p.sh b/TensorFlow2/built-in/keras_sample/mnist_convnet_ID2524_for_TensorFlow2.X/test/train_full_1p.sh
new file mode 100644
index 0000000000000000000000000000000000000000..2e80a6a89ee2d33ebeb7894045e458de2c4cedc2
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/mnist_convnet_ID2524_for_TensorFlow2.X/test/train_full_1p.sh
@@ -0,0 +1,193 @@
+#!/bin/bash
+#当前路径,不需要修改
+cur_path=`pwd`/../
+
+#基础参数,需要模型审视修改
+#Batch Size
+batch_size=64
+#网络名称,同目录名称
+Network="mnist_convnet_ID2524_for_TensorFlow2.X"
+#Device数量,单卡默认为1
+RankSize=1
+#训练epoch,可选
+train_epochs=50
+#训练step
+#train_steps=5
+#学习率
+#learning_rate=1e-4
+#ckpt_path=""
+#参数配置
+data_path=""
+
+############维测参数##############
+precision_mode="allow_mix_precision"
+#维持参数,以下不需要修改
+over_dump=False
+if [[ $over_dump == True ]];then
+ over_dump_path=${cur_path}/overflow_dump
+ mkdir -p ${over_dump_path}
+fi
+data_dump_flag=False
+data_dump_step="10"
+profiling=False
+use_mixlist=False
+mixlist_file=${cur_path}/../configs/ops_info.json
+fusion_off_flag=False
+auto_tune=False
+fusion_off_file=${cur_path}/../configs/fusion_switch.cfg
+############维测参数##############
+############维测参数##############
+for para in $*
+do
+ if [[ $para == --precision_mode* ]];then
+ precision_mode=`echo ${para#*=}`
+ elif [[ $para == --over_dump* ]];then
+ over_dump=`echo ${para#*=}`
+ over_dump_path=${cur_path}/output/overflow_dump
+ mkdir -p ${over_dump_path}
+ elif [[ $para == --data_dump_flag* ]];then
+ data_dump_flag=`echo ${para#*=}`
+ data_dump_path=${cur_path}/output/data_dump
+ mkdir -p ${data_dump_path}
+ elif [[ $para == --data_dump_step* ]];then
+ data_dump_step=`echo ${para#*=}`
+ elif [[ $para == --profiling* ]];then
+ profiling=`echo ${para#*=}`
+ profiling_dump_path=${cur_path}/output/profiling
+ mkdir -p ${profiling_dump_path}
+ elif [[ $para == --data_path* ]];then
+ data_path=`echo ${para#*=}`
+ elif [[ $para == --use_mixlist* ]];then
+ use_mixlist=`echo ${para#*=}`
+ elif [[ $para == --mixlist_file* ]];then
+ mixlist_file=`echo ${para#*=}`
+ elif [[ $para == --fusion_off_flag* ]];then
+ fusion_off_flag=`echo ${para#*=}`
+ elif [[ $para == --fusion_off_file* ]];then
+ fusion_off_file=`echo ${para#*=}`
+ elif [[ $para == --auto_tune* ]];then
+ auto_tune=`echo ${para#*=}`
+ fi
+done
+############维测参数##############
+
+
+if [[ $1 == --help || $1 == --h ]];then
+ echo "usage:./train_performance_1p.sh"
+ exit 1
+fi
+
+for para in $*
+do
+ if [[ $para == --data_path* ]];then
+ data_path=`echo ${para#*=}`
+ fi
+ if [[ $para == --ckpt_path* ]];then
+ ckpt_path=`echo ${para#*=}`
+ fi
+done
+
+if [[ $data_path == "" ]];then
+ echo "[Error] para \"data_path\" must be config"
+ exit 1
+fi
+
+##############执行训练##########
+cd $cur_path/
+if [ -d $cur_path/test/output ];then
+ rm -rf $cur_path/test/output/*
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+else
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+fi
+wait
+
+start=$(date +%s)
+nohup python3 mnist_convnet.py --data_path=$data_path \
+ --epochs=$train_epochs \
+ --batch_size=$batch_size \
+ --precision_mode=${precision_mode} \
+ --over_dump=${over_dump} \
+ --over_dump_path=${over_dump_path} \
+ --data_dump_flag=${data_dump_flag} \
+ --data_dump_step=${data_dump_step} \
+ --data_dump_path=${data_dump_path} \
+ --profiling=${profiling} \
+ --use_mixlist=${use_mixlist} \
+ --fusion_off_flag=${fusion_off_flag} \
+ --mixlist_file=${mixlist_file} \
+ --fusion_off_file=${fusion_off_file} \
+ --auto_tune=${auto_tune} \
+ --profiling_dump_path=${profiling_dump_path} > $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 &
+wait
+end=$(date +%s)
+e2etime=$(( $end - $start ))
+
+#结果打印,不需要修改
+echo "------------------ Final result ------------------"
+#输出性能FPS,需要模型审视修改
+#Time=`grep loss: $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | grep -v 'Test' | grep -v 'ETA' | awk '{print $5}' | tr -d ms/step | tail -n 2 | awk '{sum+=$1} END {print sum/NR}'`
+#输出FPS
+#FPS=`awk 'BEGIN{printf "%.2f\n",'1000'*'${batch_size}'/'${Time}'}'`
+
+#由于loss和性能取值不连续,所以每次只取每个Epoch的最后一个loss和性能值
+Step=`grep 844/844 $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | tail -n +2 | awk '{print $1}' | awk -F "/" '{print $1}' |awk '{sum+=$1} END {print sum/NR}'`
+Time=`grep 844/844 $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | tail -n +2 | awk '{print $3}' | tr -d s | awk '{sum+=$1} END {print sum/NR}'`
+TrainingTime=`awk 'BEGIN{printf "%.6f\n",'${Time}'/'${Step}'}'`
+FPS=`awk 'BEGIN{printf "%.2f\n",'${batch_size}'/'${TrainingTime}'}'`
+#打印,不需要修改
+echo "Final Performance images/sec : $FPS"
+
+#输出训练精度,需要模型审视修改
+#train_accuracy=`grep accuracy: $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | grep -v 'ETA' | awk '{print $11}' | awk '{sum+=$1} END {print sum/NR}'`
+train_accuracy=`grep 844/844 $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | awk '{print $9}' | awk '{sum+=$1} END {print sum/NR}'`
+#打印,不需要修改
+echo "Final Train Accuracy : ${train_accuracy}"
+
+#echo "Final Performance ms/step : $average_perf"
+echo "Final Training Duration sec : $e2etime"
+
+###下面字段用于冒烟看护
+BatchSize=${batch_size}
+#设备类型,自动获取
+DeviceType=`uname -m`
+#用例名称,自动获取
+CaseName=${Network}_bs${BatchSize}_${RankSize}'p'_'acc'
+
+##获取性能数据,不需要修改
+#吞吐量
+ActualFPS=${FPS}
+#单迭代训练时长
+#TrainingTime=${Time}
+
+#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视
+#grep loss $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | grep -v 'Test' | awk '{print $8}' > $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt
+grep 844/844 $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | awk '{print $(NF-9)}' > $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt
+#最后一个迭代loss值,不需要修改
+ActualLoss=`awk 'END {print $1}' $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt`
+
+##获取错误信息
+#系统错误信息
+#ModelStatus="图执行FAIL"
+# error_msg="EZ3002"
+#判断错误信息是否和历史状态一致,此处无需修改
+#error_msg="Graph engine process graph failed: EZ3002: Optype \[Conv2DBackpropFilter\] of Ops kernel"
+#Status=`grep "${error_msg}" $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|wc -l`
+#DTS单号或者issue链接
+#DTS_Number="DTS2021090622224"
+
+#关键信息打印到CaseName.log中,此处无需修改
+echo "Network = ${Network}" > $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "RankSize = ${RankSize}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "BatchSize = ${BatchSize}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "DeviceType = ${DeviceType}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "CaseName = ${CaseName}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+#echo "ModelStatus = ${ModelStatus}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+#echo "DTS_Number = ${DTS_Number}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+#echo "Status = ${Status}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+#echo "error_msg = ${error_msg}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualFPS = ${ActualFPS}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainingTime = ${TrainingTime}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualLoss = ${ActualLoss}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "E2ETrainingTime = ${e2etime}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
diff --git a/TensorFlow2/built-in/keras_sample/mnist_convnet_ID2524_for_TensorFlow2.X/test/train_performance_1p.sh b/TensorFlow2/built-in/keras_sample/mnist_convnet_ID2524_for_TensorFlow2.X/test/train_performance_1p.sh
new file mode 100644
index 0000000000000000000000000000000000000000..966a742d3d98be2f8ac3b2367d8ee90e4d96f952
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/mnist_convnet_ID2524_for_TensorFlow2.X/test/train_performance_1p.sh
@@ -0,0 +1,194 @@
+#!/bin/bash
+#当前路径,不需要修改
+cur_path=`pwd`/../
+
+#基础参数,需要模型审视修改
+#Batch Size
+batch_size=64
+#网络名称,同目录名称
+Network="mnist_convnet_ID2524_for_TensorFlow2.X"
+#Device数量,单卡默认为1
+RankSize=1
+#训练epoch,可选
+train_epochs=3
+#训练step
+#train_steps=5
+#学习率
+#learning_rate=1e-4
+#ckpt_path=""
+#参数配置
+data_path=""
+
+############维测参数##############
+precision_mode="allow_mix_precision"
+#维持参数,以下不需要修改
+over_dump=False
+if [[ $over_dump == True ]];then
+ over_dump_path=${cur_path}/overflow_dump
+ mkdir -p ${over_dump_path}
+fi
+data_dump_flag=False
+data_dump_step="10"
+profiling=False
+use_mixlist=False
+mixlist_file=${cur_path}/../configs/ops_info.json
+fusion_off_flag=False
+auto_tune=False
+fusion_off_file=${cur_path}/../configs/fusion_switch.cfg
+############维测参数##############
+############维测参数##############
+for para in $*
+do
+ if [[ $para == --precision_mode* ]];then
+ precision_mode=`echo ${para#*=}`
+ elif [[ $para == --over_dump* ]];then
+ over_dump=`echo ${para#*=}`
+ over_dump_path=${cur_path}/output/overflow_dump
+ mkdir -p ${over_dump_path}
+ elif [[ $para == --data_dump_flag* ]];then
+ data_dump_flag=`echo ${para#*=}`
+ data_dump_path=${cur_path}/output/data_dump
+ mkdir -p ${data_dump_path}
+ elif [[ $para == --data_dump_step* ]];then
+ data_dump_step=`echo ${para#*=}`
+ elif [[ $para == --profiling* ]];then
+ profiling=`echo ${para#*=}`
+ profiling_dump_path=${cur_path}/output/profiling
+ mkdir -p ${profiling_dump_path}
+ elif [[ $para == --data_path* ]];then
+ data_path=`echo ${para#*=}`
+ elif [[ $para == --use_mixlist* ]];then
+ use_mixlist=`echo ${para#*=}`
+ elif [[ $para == --mixlist_file* ]];then
+ mixlist_file=`echo ${para#*=}`
+ elif [[ $para == --fusion_off_flag* ]];then
+ fusion_off_flag=`echo ${para#*=}`
+ elif [[ $para == --fusion_off_file* ]];then
+ fusion_off_file=`echo ${para#*=}`
+ elif [[ $para == --auto_tune* ]];then
+ auto_tune=`echo ${para#*=}`
+ fi
+done
+############维测参数##############
+
+
+if [[ $1 == --help || $1 == --h ]];then
+ echo "usage:./train_performance_1p.sh"
+ exit 1
+fi
+
+for para in $*
+do
+ if [[ $para == --data_path* ]];then
+ data_path=`echo ${para#*=}`
+ fi
+ if [[ $para == --ckpt_path* ]];then
+ ckpt_path=`echo ${para#*=}`
+ fi
+done
+
+if [[ $data_path == "" ]];then
+ echo "[Error] para \"data_path\" must be config"
+ exit 1
+fi
+
+##############执行训练##########
+cd $cur_path/
+if [ -d $cur_path/test/output ];then
+ rm -rf $cur_path/test/output/*
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+else
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+fi
+wait
+
+start=$(date +%s)
+nohup python3 mnist_convnet.py --data_path=$data_path \
+ --epochs=$train_epochs \
+ --batch_size=$batch_size \
+ --precision_mode=${precision_mode} \
+ --over_dump=${over_dump} \
+ --over_dump_path=${over_dump_path} \
+ --data_dump_flag=${data_dump_flag} \
+ --data_dump_step=${data_dump_step} \
+ --data_dump_path=${data_dump_path} \
+ --profiling=${profiling} \
+ --use_mixlist=${use_mixlist} \
+ --fusion_off_flag=${fusion_off_flag} \
+ --mixlist_file=${mixlist_file} \
+ --fusion_off_file=${fusion_off_file} \
+ --auto_tune=${auto_tune} \
+ --profiling_dump_path=${profiling_dump_path} \
+ --static=False > $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 &
+wait
+end=$(date +%s)
+e2etime=$(( $end - $start ))
+
+#结果打印,不需要修改
+echo "------------------ Final result ------------------"
+#输出性能FPS,需要模型审视修改
+#Time=`grep loss: $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | grep -v 'Test' | grep -v 'ETA' | awk '{print $5}' | tr -d ms/step | tail -n 2 | awk '{sum+=$1} END {print sum/NR}'`
+#输出FPS
+#FPS=`awk 'BEGIN{printf "%.2f\n",'1000'*'${batch_size}'/'${Time}'}'`
+
+#由于loss和性能取值不连续,所以每次只取每个Epoch的最后一个loss和性能值
+Step=`grep 844/844 $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | tail -n +2 | awk '{print $1}' | awk -F "/" '{print $1}' |awk '{sum+=$1} END {print sum/NR}'`
+Time=`grep 844/844 $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | tail -n +2 | awk '{print $3}' | tr -d s | awk '{sum+=$1} END {print sum/NR}'`
+TrainingTime=`awk 'BEGIN{printf "%.6f\n",'${Time}'/'${Step}'}'`
+FPS=`awk 'BEGIN{printf "%.2f\n",'${batch_size}'/'${TrainingTime}'}'`
+#打印,不需要修改
+echo "Final Performance images/sec : $FPS"
+
+#输出训练精度,需要模型审视修改
+#train_accuracy=`grep accuracy: $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | grep -v 'ETA' | awk '{print $11}' | awk '{sum+=$1} END {print sum/NR}'`
+train_accuracy=`grep 844/844 $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | awk '{print $9}' | awk '{sum+=$1} END {print sum/NR}'`
+#打印,不需要修改
+echo "Final Train Accuracy : ${train_accuracy}"
+
+#echo "Final Performance ms/step : $average_perf"
+echo "Final Training Duration sec : $e2etime"
+
+###下面字段用于冒烟看护
+BatchSize=${batch_size}
+#设备类型,自动获取
+DeviceType=`uname -m`
+#用例名称,自动获取
+CaseName=${Network}_bs${BatchSize}_${RankSize}'p'_'perf'
+
+##获取性能数据,不需要修改
+#吞吐量
+ActualFPS=${FPS}
+#单迭代训练时长
+#TrainingTime=${Time}
+
+#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视
+#grep loss $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | grep -v 'Test' | awk '{print $8}' > $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt
+grep 844/844 $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | awk '{print $(NF-9)}' > $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt
+#最后一个迭代loss值,不需要修改
+ActualLoss=`awk 'END {print $1}' $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt`
+
+##获取错误信息
+#系统错误信息
+#ModelStatus="图执行FAIL"
+# error_msg="EZ3002"
+#判断错误信息是否和历史状态一致,此处无需修改
+#error_msg="Graph engine process graph failed: EZ3002: Optype \[Conv2DBackpropFilter\] of Ops kernel"
+#Status=`grep "${error_msg}" $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|wc -l`
+#DTS单号或者issue链接
+#DTS_Number="DTS2021090622224"
+
+#关键信息打印到CaseName.log中,此处无需修改
+echo "Network = ${Network}" > $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "RankSize = ${RankSize}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "BatchSize = ${BatchSize}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "DeviceType = ${DeviceType}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "CaseName = ${CaseName}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+#echo "ModelStatus = ${ModelStatus}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+#echo "DTS_Number = ${DTS_Number}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+#echo "Status = ${Status}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+#echo "error_msg = ${error_msg}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualFPS = ${ActualFPS}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainingTime = ${TrainingTime}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualLoss = ${ActualLoss}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "E2ETrainingTime = ${e2etime}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
diff --git a/TensorFlow2/built-in/keras_sample/mnist_convnet_ID2524_for_TensorFlow2.X/test/train_performance_1p_static.sh b/TensorFlow2/built-in/keras_sample/mnist_convnet_ID2524_for_TensorFlow2.X/test/train_performance_1p_static.sh
new file mode 100644
index 0000000000000000000000000000000000000000..db30dc3ac6ef999630ff1a6c080eaa2dc2df4a64
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/mnist_convnet_ID2524_for_TensorFlow2.X/test/train_performance_1p_static.sh
@@ -0,0 +1,194 @@
+#!/bin/bash
+#当前路径,不需要修改
+cur_path=`pwd`/../
+
+#基础参数,需要模型审视修改
+#Batch Size
+batch_size=64
+#网络名称,同目录名称
+Network="mnist_convnet_ID2524_for_TensorFlow2.X"
+#Device数量,单卡默认为1
+RankSize=1
+#训练epoch,可选
+train_epochs=3
+#训练step
+#train_steps=5
+#学习率
+#learning_rate=1e-4
+#ckpt_path=""
+#参数配置
+data_path=""
+
+############维测参数##############
+precision_mode="allow_mix_precision"
+#维持参数,以下不需要修改
+over_dump=False
+if [[ $over_dump == True ]];then
+ over_dump_path=${cur_path}/overflow_dump
+ mkdir -p ${over_dump_path}
+fi
+data_dump_flag=False
+data_dump_step="10"
+profiling=False
+use_mixlist=False
+mixlist_file=${cur_path}/../configs/ops_info.json
+fusion_off_flag=False
+auto_tune=False
+fusion_off_file=${cur_path}/../configs/fusion_switch.cfg
+############维测参数##############
+############维测参数##############
+for para in $*
+do
+ if [[ $para == --precision_mode* ]];then
+ precision_mode=`echo ${para#*=}`
+ elif [[ $para == --over_dump* ]];then
+ over_dump=`echo ${para#*=}`
+ over_dump_path=${cur_path}/output/overflow_dump
+ mkdir -p ${over_dump_path}
+ elif [[ $para == --data_dump_flag* ]];then
+ data_dump_flag=`echo ${para#*=}`
+ data_dump_path=${cur_path}/output/data_dump
+ mkdir -p ${data_dump_path}
+ elif [[ $para == --data_dump_step* ]];then
+ data_dump_step=`echo ${para#*=}`
+ elif [[ $para == --profiling* ]];then
+ profiling=`echo ${para#*=}`
+ profiling_dump_path=${cur_path}/output/profiling
+ mkdir -p ${profiling_dump_path}
+ elif [[ $para == --data_path* ]];then
+ data_path=`echo ${para#*=}`
+ elif [[ $para == --use_mixlist* ]];then
+ use_mixlist=`echo ${para#*=}`
+ elif [[ $para == --mixlist_file* ]];then
+ mixlist_file=`echo ${para#*=}`
+ elif [[ $para == --fusion_off_flag* ]];then
+ fusion_off_flag=`echo ${para#*=}`
+ elif [[ $para == --fusion_off_file* ]];then
+ fusion_off_file=`echo ${para#*=}`
+ elif [[ $para == --auto_tune* ]];then
+ auto_tune=`echo ${para#*=}`
+ fi
+done
+############维测参数##############
+
+
+if [[ $1 == --help || $1 == --h ]];then
+ echo "usage:./train_performance_1p.sh"
+ exit 1
+fi
+
+for para in $*
+do
+ if [[ $para == --data_path* ]];then
+ data_path=`echo ${para#*=}`
+ fi
+ if [[ $para == --ckpt_path* ]];then
+ ckpt_path=`echo ${para#*=}`
+ fi
+done
+
+if [[ $data_path == "" ]];then
+ echo "[Error] para \"data_path\" must be config"
+ exit 1
+fi
+
+##############执行训练##########
+cd $cur_path/
+if [ -d $cur_path/test/output ];then
+ rm -rf $cur_path/test/output/*
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+else
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+fi
+wait
+
+start=$(date +%s)
+nohup python3 mnist_convnet.py --data_path=$data_path \
+ --epochs=$train_epochs \
+ --batch_size=$batch_size \
+ --precision_mode=${precision_mode} \
+ --over_dump=${over_dump} \
+ --over_dump_path=${over_dump_path} \
+ --data_dump_flag=${data_dump_flag} \
+ --data_dump_step=${data_dump_step} \
+ --data_dump_path=${data_dump_path} \
+ --profiling=${profiling} \
+ --use_mixlist=${use_mixlist} \
+ --fusion_off_flag=${fusion_off_flag} \
+ --mixlist_file=${mixlist_file} \
+ --fusion_off_file=${fusion_off_file} \
+ --auto_tune=${auto_tune} \
+ --profiling_dump_path=${profiling_dump_path} \
+ --static=True > $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 &
+wait
+end=$(date +%s)
+e2etime=$(( $end - $start ))
+
+#结果打印,不需要修改
+echo "------------------ Final result ------------------"
+#输出性能FPS,需要模型审视修改
+#Time=`grep loss: $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | grep -v 'Test' | grep -v 'ETA' | awk '{print $5}' | tr -d ms/step | tail -n 2 | awk '{sum+=$1} END {print sum/NR}'`
+#输出FPS
+#FPS=`awk 'BEGIN{printf "%.2f\n",'1000'*'${batch_size}'/'${Time}'}'`
+
+#由于loss和性能取值不连续,所以每次只取每个Epoch的最后一个loss和性能值
+Step=`grep loss $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | grep -v Test| tail -n +2 | awk '{print $1}' | awk -F "/" '{print $1}' |awk '{sum+=$1} END {print sum/NR}'`
+Time=`grep loss $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | grep -v Test| tail -n +2 | awk '{print $3}' | tr -d s | awk '{sum+=$1} END {print sum/NR}'`
+TrainingTime=`awk 'BEGIN{printf "%.6f\n",'${Time}'/'${Step}'}'`
+FPS=`awk 'BEGIN{printf "%.2f\n",'${batch_size}'/'${TrainingTime}'}'`
+#打印,不需要修改
+echo "Final Performance images/sec : $FPS"
+
+#输出训练精度,需要模型审视修改
+#train_accuracy=`grep accuracy: $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | grep -v 'ETA' | awk '{print $11}' | awk '{sum+=$1} END {print sum/NR}'`
+train_accuracy=`grep "Test accuracy" $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | awk '{print $3}' | awk '{sum+=$1} END {print sum/NR}'`
+#打印,不需要修改
+echo "Final Train Accuracy : ${train_accuracy}"
+
+#echo "Final Performance ms/step : $average_perf"
+echo "Final Training Duration sec : $e2etime"
+
+###下面字段用于冒烟看护
+BatchSize=${batch_size}
+#设备类型,自动获取
+DeviceType=`uname -m`
+#用例名称,自动获取
+CaseName=${Network}_bs${BatchSize}_${RankSize}'p'_'perf'
+
+##获取性能数据,不需要修改
+#吞吐量
+ActualFPS=${FPS}
+#单迭代训练时长
+#TrainingTime=${Time}
+
+#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视
+#grep loss $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | grep -v 'Test' | awk '{print $8}' > $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt
+grep loss $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | grep -v 'Test' | awk '{print $9}' > $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt
+#最后一个迭代loss值,不需要修改
+ActualLoss=`awk 'END {print $1}' $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt`
+
+##获取错误信息
+#系统错误信息
+#ModelStatus="图执行FAIL"
+# error_msg="EZ3002"
+#判断错误信息是否和历史状态一致,此处无需修改
+#error_msg="Graph engine process graph failed: EZ3002: Optype \[Conv2DBackpropFilter\] of Ops kernel"
+#Status=`grep "${error_msg}" $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|wc -l`
+#DTS单号或者issue链接
+#DTS_Number="DTS2021090622224"
+
+#关键信息打印到CaseName.log中,此处无需修改
+echo "Network = ${Network}" > $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "RankSize = ${RankSize}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "BatchSize = ${BatchSize}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "DeviceType = ${DeviceType}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "CaseName = ${CaseName}_static" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+#echo "ModelStatus = ${ModelStatus}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+#echo "DTS_Number = ${DTS_Number}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+#echo "Status = ${Status}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+#echo "error_msg = ${error_msg}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualFPS = ${ActualFPS}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainingTime = ${TrainingTime}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualLoss = ${ActualLoss}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "E2ETrainingTime = ${e2etime}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
diff --git a/TensorFlow2/built-in/keras_sample/modelzoo_level.txt b/TensorFlow2/built-in/keras_sample/modelzoo_level.txt
new file mode 100644
index 0000000000000000000000000000000000000000..31529da2e68f25b61e2a3e698a07537281443c03
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/modelzoo_level.txt
@@ -0,0 +1,3 @@
+FuncStatus:OK
+PerfStatus:OK
+PrecisionStatus:OK
\ No newline at end of file
diff --git a/TensorFlow2/built-in/keras_sample/pointnet_ID2531_for_TensorFlow2.X/LICENSE b/TensorFlow2/built-in/keras_sample/pointnet_ID2531_for_TensorFlow2.X/LICENSE
new file mode 100644
index 0000000000000000000000000000000000000000..ab652360b248f2947c2e3ccf306ca128660ea731
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/pointnet_ID2531_for_TensorFlow2.X/LICENSE
@@ -0,0 +1,284 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+------------------
+Files: third_party/compute_library/...
+
+MIT License
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+
+------------------
+Files: ACKNOWLEDGEMENTS
+LICENSE
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+------------------
+Files: third_party/hexagon
+
+Copyright (c) 2016-2019, The Linux Foundation. All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted (subject to the limitations in the
+disclaimer below) provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+
+ * Neither the name of The Linux Foundation nor the names of its
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
+GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
+HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/TensorFlow2/built-in/keras_sample/pointnet_ID2531_for_TensorFlow2.X/ReadME.md b/TensorFlow2/built-in/keras_sample/pointnet_ID2531_for_TensorFlow2.X/ReadME.md
new file mode 100644
index 0000000000000000000000000000000000000000..d844898a8b0db104aef7d840e8fcc7c838cdb7d1
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/pointnet_ID2531_for_TensorFlow2.X/ReadME.md
@@ -0,0 +1,29 @@
+# 一、基础信息
+
+网络名称:`pointnet_ID2531_for_TensorFlow2.X`
+
+github addr:https://github.com/keras-team/keras-io/tree/master/examples/vision
+
+# 二、代码修改
+
+# 三、程序运行
+
+```shell
+bash run_1p.sh
+```
+
+# 四、归档文件路径
+
+1、数据集
+pointnet_ID2531_for_TensorFlow2.X,10.248.93.131:Huawei@123,/train_output/turingDataset/00-CV/ID2531_CarPeting_TF2.X_pointnet:2292148
+
+
+2、归档文件
+
+3、迁移代码
+
+4、源代码
+
+5、源迁移代码
+
+# 五、NPU工作环境
\ No newline at end of file
diff --git a/TensorFlow2/built-in/keras_sample/pointnet_ID2531_for_TensorFlow2.X/modelzoo_level.txt b/TensorFlow2/built-in/keras_sample/pointnet_ID2531_for_TensorFlow2.X/modelzoo_level.txt
new file mode 100644
index 0000000000000000000000000000000000000000..0b49b4fb26c2694a86567bea1b462e7dcb03cc31
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/pointnet_ID2531_for_TensorFlow2.X/modelzoo_level.txt
@@ -0,0 +1,3 @@
+FuncStatus:OK
+PerfStatus:OK
+PrecisionStatus:OK
\ No newline at end of file
diff --git a/TensorFlow2/built-in/keras_sample/pointnet_ID2531_for_TensorFlow2.X/pointnet.py b/TensorFlow2/built-in/keras_sample/pointnet_ID2531_for_TensorFlow2.X/pointnet.py
new file mode 100644
index 0000000000000000000000000000000000000000..790f4d52b96a2ba8c7bea86bb221391b3d9b464d
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/pointnet_ID2531_for_TensorFlow2.X/pointnet.py
@@ -0,0 +1,355 @@
+#
+# Copyright 2017 The TensorFlow Authors. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============================================================================
+# Copyright 2021 Huawei Technologies Co., Ltd
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+"""
+Title: Point cloud classification with PointNet
+Author: [David Griffiths](https://dgriffiths3.github.io)
+Date created: 2020/05/25
+Last modified: 2020/05/26
+Description: Implementation of PointNet for ModelNet10 classification.
+"""
+"""
+# Point cloud classification
+"""
+
+"""
+## Introduction
+
+Classification, detection and segmentation of unordered 3D point sets i.e. point clouds
+is a core problem in computer vision. This example implements the seminal point cloud
+deep learning paper [PointNet (Qi et al., 2017)](https://arxiv.org/abs/1612.00593). For a
+detailed intoduction on PointNet see [this blog
+post](https://medium.com/@luis_gonzales/an-in-depth-look-at-pointnet-111d7efdaa1a).
+"""
+
+"""
+## Setup
+
+If using colab first install trimesh with `!pip install trimesh`.
+"""
+
+
+import os
+import argparse
+import ast
+import glob
+import trimesh
+import numpy as np
+import tensorflow as tf
+from tensorflow import keras
+from tensorflow.keras import layers
+from matplotlib import pyplot as plt
+
+import npu_device
+npu_device.open().as_default()
+
+tf.random.set_seed(1234)
+
+'''
+"""
+## Load dataset
+
+We use the ModelNet10 model dataset, the smaller 10 class version of the ModelNet40
+dataset. First download the data:
+"""
+
+DATA_DIR = tf.keras.utils.get_file(
+ "modelnet.zip",
+ "http://3dvision.princeton.edu/projects/2014/3DShapeNets/ModelNet10.zip",
+ extract=True,
+)
+DATA_DIR = os.path.join(os.path.dirname(DATA_DIR), "ModelNet10")
+
+"""
+We can use the `trimesh` package to read and visualize the `.off` mesh files.
+"""
+
+mesh = trimesh.load(os.path.join(DATA_DIR, "chair/train/chair_0001.off"))
+mesh.show()
+
+"""
+To convert a mesh file to a point cloud we first need to sample points on the mesh
+surface. `.sample()` performs a unifrom random sampling. Here we sample at 2048 locations
+and visualize in `matplotlib`.
+"""
+
+points = mesh.sample(2048)
+
+fig = plt.figure(figsize=(5, 5))
+ax = fig.add_subplot(111, projection="3d")
+ax.scatter(points[:, 0], points[:, 1], points[:, 2])
+ax.set_axis_off()
+plt.show()
+'''
+
+
+def parse_args():
+ parser = argparse.ArgumentParser(
+ formatter_class=argparse.ArgumentDefaultsHelpFormatter)
+ parser.add_argument('--data_path', default='./',
+ help="""directory to data""")
+ parser.add_argument('--batch_size', default=32, type=int,
+ help="""batch size for 1p""")
+ parser.add_argument('--epochs', default=20, type=int,
+ help="""epochs""")
+ parser.add_argument('--drop_remainder', default="True", type=ast.literal_eval,
+ help="""drop_remainder True or False remote dynamic or static input""")
+ args, unknown_args = parser.parse_known_args()
+ if len(unknown_args) > 0:
+ for bad_arg in unknown_args:
+ print("ERROR: Unknown command line arg: %s" % bad_arg)
+ raise ValueError("Invalid command line arg(s)")
+ return args
+
+
+"""
+Set the number of points to sample and batch size and parse the dataset. This can take
+~5minutes to complete.
+"""
+
+args = parse_args()
+DATA_DIR = os.path.join(args.data_path, "ModelNet10/")
+NUM_POINTS = 2048
+NUM_CLASSES = 10
+BATCH_SIZE = args.batch_size
+EPOCHS=args.epochs
+
+
+"""
+To generate a `tf.data.Dataset()` we need to first parse through the ModelNet data
+folders. Each mesh is loaded and sampled into a point cloud before being added to a
+standard python list and converted to a `numpy` array. We also store the current
+enumerate index value as the object label and use a dictionary to recall this later.
+"""
+
+
+def parse_dataset(num_points=2048):
+
+ train_points = []
+ train_labels = []
+ test_points = []
+ test_labels = []
+ class_map = {}
+ folders = glob.glob(os.path.join(DATA_DIR, "[!README]*"))
+
+ for i, folder in enumerate(folders):
+ print("processing class: {}".format(os.path.basename(folder)))
+ # store folder name with ID so we can retrieve later
+ class_map[i] = folder.split("/")[-1]
+ # gather all files
+ train_files = glob.glob(os.path.join(folder, "train/*"))
+ test_files = glob.glob(os.path.join(folder, "test/*"))
+
+ for f in train_files:
+ train_points.append(trimesh.load(f).sample(num_points))
+ train_labels.append(i)
+
+ for f in test_files:
+ test_points.append(trimesh.load(f).sample(num_points))
+ test_labels.append(i)
+
+ return (
+ np.array(train_points),
+ np.array(test_points),
+ np.array(train_labels),
+ np.array(test_labels),
+ class_map,
+ )
+
+train_points, test_points, train_labels, test_labels, CLASS_MAP = parse_dataset(
+ NUM_POINTS
+)
+
+"""
+Our data can now be read into a `tf.data.Dataset()` object. We set the shuffle buffer
+size to the entire size of the dataset as prior to this the data is ordered by class.
+Data augmentation is important when working with point cloud data. We create a
+augmentation function to jitter and shuffle the train dataset.
+"""
+
+
+def augment(points, label):
+ # jitter points
+ points += tf.random.uniform(points.shape, -0.005, 0.005, dtype=tf.float64)
+ # shuffle points
+ points = tf.random.shuffle(points)
+ return points, label
+
+
+train_dataset = tf.data.Dataset.from_tensor_slices((train_points, train_labels))
+test_dataset = tf.data.Dataset.from_tensor_slices((test_points, test_labels))
+
+train_dataset = train_dataset.shuffle(len(train_points)).map(augment).batch(BATCH_SIZE, drop_remainder=args.drop_remainder)
+test_dataset = test_dataset.shuffle(len(test_points)).batch(BATCH_SIZE, drop_remainder=args.drop_remainder)
+
+"""
+### Build a model
+
+Each convolution and fully-connected layer (with exception for end layers) consits of
+Convolution / Dense -> Batch Normalization -> ReLU Activation.
+"""
+
+
+def conv_bn(x, filters):
+ x = layers.Conv1D(filters, kernel_size=1, padding="valid")(x)
+ x = layers.BatchNormalization(momentum=0.0)(x)
+ return layers.Activation("relu")(x)
+
+
+def dense_bn(x, filters):
+ x = layers.Dense(filters)(x)
+ x = layers.BatchNormalization(momentum=0.0)(x)
+ return layers.Activation("relu")(x)
+
+
+"""
+PointNet consists of two core components. The primary MLP network, and the transformer
+net (T-net). The T-net aims to learn an affine transformation matrix by its own mini
+network. The T-net is used twice. The first time to transform the input features (n, 3)
+into a canonical representation. The second is an affine transformation for alignment in
+feature space (n, 3). As per the original paper we constrain the transformation to be
+close to an orthogonal matrix (i.e. ||X*X^T - I|| = 0).
+"""
+
+
+class OrthogonalRegularizer(keras.regularizers.Regularizer):
+ def __init__(self, num_features, l2reg=0.001):
+ self.num_features = num_features
+ self.l2reg = l2reg
+ self.eye = tf.eye(num_features)
+
+ def __call__(self, x):
+ x = tf.reshape(x, (-1, self.num_features, self.num_features))
+ xxt = tf.tensordot(x, x, axes=(2, 2))
+ xxt = tf.reshape(xxt, (-1, self.num_features, self.num_features))
+ return tf.reduce_sum(self.l2reg * tf.square(xxt - self.eye))
+
+
+"""
+ We can then define a general function to build T-net layers.
+"""
+
+
+def tnet(inputs, num_features):
+
+ # Initalise bias as the indentity matrix
+ bias = keras.initializers.Constant(np.eye(num_features).flatten())
+ reg = OrthogonalRegularizer(num_features)
+
+ x = conv_bn(inputs, 32)
+ x = conv_bn(x, 64)
+ x = conv_bn(x, 512)
+ x = layers.GlobalMaxPooling1D()(x)
+ x = dense_bn(x, 256)
+ x = dense_bn(x, 128)
+ x = layers.Dense(
+ num_features * num_features,
+ kernel_initializer="zeros",
+ bias_initializer=bias,
+ activity_regularizer=reg,
+ )(x)
+ feat_T = layers.Reshape((num_features, num_features))(x)
+ # Apply affine transformation to input features
+ return layers.Dot(axes=(2, 1))([inputs, feat_T])
+
+
+"""
+The main network can be then implemented in the same manner where the t-net mini models
+can be dropped in a layers in the graph. Here we replicate the network architecture
+published in the original paper but with half the number of weights at each layer as we
+are using the smaller 10 class ModelNet dataset.
+"""
+
+inputs = keras.Input(shape=(NUM_POINTS, 3))
+
+x = tnet(inputs, 3)
+x = conv_bn(x, 32)
+x = conv_bn(x, 32)
+x = tnet(x, 32)
+x = conv_bn(x, 32)
+x = conv_bn(x, 64)
+x = conv_bn(x, 512)
+x = layers.GlobalMaxPooling1D()(x)
+x = dense_bn(x, 256)
+x = layers.Dropout(0.3)(x)
+x = dense_bn(x, 128)
+x = layers.Dropout(0.3)(x)
+
+outputs = layers.Dense(NUM_CLASSES, activation="softmax")(x)
+
+model = keras.Model(inputs=inputs, outputs=outputs, name="pointnet")
+model.summary()
+
+"""
+### Train model
+
+Once the model is defined it can be trained like any other standard classification model
+using `.compile()` and `.fit()`.
+"""
+
+model.compile(
+ loss="sparse_categorical_crossentropy",
+ optimizer=keras.optimizers.Adam(learning_rate=0.001),
+ metrics=["sparse_categorical_accuracy"],
+)
+
+model.fit(train_dataset, epochs=EPOCHS, validation_data=test_dataset)
+model.save_weights(filepath="pointnet", save_format="tf")
+"""
+## Visualize predictions
+
+We can use matplotlib to visualize our trained model performance.
+"""
+
+'''
+data = test_dataset.take(1)
+
+points, labels = list(data)[0]
+points = points[:8, ...]
+labels = labels[:8, ...]
+
+# run test data through model
+preds = model.predict(points)
+preds = tf.math.argmax(preds, -1)
+
+points = points.numpy()
+
+# plot points with predicted class and label
+fig = plt.figure(figsize=(15, 10))
+for i in range(8):
+ ax = fig.add_subplot(2, 4, i + 1, projection="3d")
+ ax.scatter(points[i, :, 0], points[i, :, 1], points[i, :, 2])
+ ax.set_title(
+ "pred: {:}, label: {:}".format(
+ CLASS_MAP[preds[i].numpy()], CLASS_MAP[labels.numpy()[i]]
+ )
+ )
+ ax.set_axis_off()
+plt.show()
+'''
diff --git a/TensorFlow2/built-in/keras_sample/pointnet_ID2531_for_TensorFlow2.X/requirements.txt b/TensorFlow2/built-in/keras_sample/pointnet_ID2531_for_TensorFlow2.X/requirements.txt
new file mode 100644
index 0000000000000000000000000000000000000000..ac1db3b606d6aa2e78d3251f7e39947008790368
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/pointnet_ID2531_for_TensorFlow2.X/requirements.txt
@@ -0,0 +1 @@
+trimesh
\ No newline at end of file
diff --git a/TensorFlow2/built-in/keras_sample/pointnet_ID2531_for_TensorFlow2.X/test/train_full_1p.sh b/TensorFlow2/built-in/keras_sample/pointnet_ID2531_for_TensorFlow2.X/test/train_full_1p.sh
new file mode 100644
index 0000000000000000000000000000000000000000..9d57d09544f00dbf7aa9c7cc39cc0c432cebc496
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/pointnet_ID2531_for_TensorFlow2.X/test/train_full_1p.sh
@@ -0,0 +1,103 @@
+#!/bin/bash
+cur_path=`pwd`/../
+
+#基础参数,需要模型审视修改
+#Batch Size
+batch_size=32
+#网络名称,同目录名称
+Network="pointnet_ID2531_for_TensorFlow2.X"
+#Device数量,单卡默认为1
+RANK_SIZE=1
+#训练epoch,可选
+train_epochs=20
+#训练step
+train_steps=60000
+#学习率
+#learning_rate=1e-5
+
+#参数配置
+data_path=""
+
+if [[ $1 == --help || $1 == --h ]];then
+ echo "usage: ./train_performance_1p.sh"
+ exit 1
+fi
+
+for para in $*
+do
+ if [[ $para == --data_path* ]];then
+ data_path=`echo ${para#*=}`
+ fi
+done
+
+if [[ $data_path == "" ]];then
+ echo "[Error] para \"data_path \" must be config"
+ exit 1
+fi
+
+##############执行训练##########
+cd $cur_path
+
+if [ -d $cur_path/test/output ];then
+ rm -rf $cur_path/test/output/*
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+else
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+fi
+wait
+
+start=$(date +%s)
+nohup python3 pointnet.py --data_path=$data_path \
+ --epoch=$train_epochs \
+ --eval_static=True > $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 &
+wait
+
+end=$(date +%s)
+e2e_time=$(( $end - $start ))
+
+#echo "Final Performance ms/step : $average_perf"
+echo "Final Training Duration sec : $e2e_time"
+
+#结果打印,不需要修改
+echo "------------------ Final result ------------------"
+#输出性能FPS,需要模型审视修改
+TrainingTime=`grep ms/step $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | awk 'NR==1' | awk -F " " '{print$5}' | tr -cd "[0-9]"`
+wait
+FPS=`awk 'BEGIN{printf "%.2f\n",'1875'*'${batch_size}'/'${TrainingTime}'}'`
+#打印,不需要修改
+echo "Final Performance images/sec : $FPS"
+
+#输出训练精度,需要模型审视修改
+train_accuracy=`grep " val_sparse_categorical_accuracy:" $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | awk 'END {print $17}'`
+#打印,不需要修改
+echo "Final Train Accuracy : ${train_accuracy}"
+
+
+#精度看护结果汇总
+#训练用例信息,不需要修改
+BatchSize=${batch_size}
+DeviceType=`uname -m`
+CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc'
+
+##获取性能数据,不需要修改
+#吞吐量
+ActualFPS=${FPS}
+#单迭代训练时长
+TrainingTime=${TrainingTime}
+
+#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视
+grep " loss:" $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | awk '{print $8}' >> $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt
+#最后一个迭代loss值,不需要修改
+ActualLoss=`awk 'END {print $1}' $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt`
+
+#关键信息打印到${CaseName}.log中,不需要修改
+echo "Network = ${Network}" > $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "RankSize = ${RANK_SIZE}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "BatchSize = ${BatchSize}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "DeviceType = ${DeviceType}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "CaseName = ${CaseName}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualFPS = ${ActualFPS}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainingTime = ${TrainingTime}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualLoss = ${ActualLoss}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
diff --git a/TensorFlow2/built-in/keras_sample/pointnet_ID2531_for_TensorFlow2.X/test/train_performance_1p_dynamic_eval.sh b/TensorFlow2/built-in/keras_sample/pointnet_ID2531_for_TensorFlow2.X/test/train_performance_1p_dynamic_eval.sh
new file mode 100644
index 0000000000000000000000000000000000000000..2c68e2f749bdcb3110202f9b28a7950591e72754
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/pointnet_ID2531_for_TensorFlow2.X/test/train_performance_1p_dynamic_eval.sh
@@ -0,0 +1,115 @@
+#!/bin/bash
+cur_path=`pwd`/../
+
+#基础参数,需要模型审视修改
+#Batch Size
+batch_size=32
+#网络名称,同目录名称
+Network="pointnet_ID2531_for_TensorFlow2.X"
+#Device数量,单卡默认为1
+RANK_SIZE=1
+#训练epoch,可选
+train_epochs=1
+#训练step
+train_steps=60000
+#学习率
+#learning_rate=1e-5
+
+#参数配置
+data_path=""
+
+if [[ $1 == --help || $1 == --h ]];then
+ echo "usage: ./train_performance_1p.sh"
+ exit 1
+fi
+
+for para in $*
+do
+ if [[ $para == --data_path* ]];then
+ data_path=`echo ${para#*=}`
+ fi
+done
+
+if [[ $data_path == "" ]];then
+ echo "[Error] para \"data_path \" must be config"
+ exit 1
+fi
+
+##############执行训练##########
+cd $cur_path
+
+if [ -d $cur_path/test/output ];then
+ rm -rf $cur_path/test/output/*
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+else
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+fi
+wait
+
+start=$(date +%s)
+nohup python3 pointnet.py --data_path=$data_path \
+ --epochs=$train_epochs \
+ --batch_size=$batch_size \
+ --drop_remainder=False > $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 &
+wait
+
+end=$(date +%s)
+e2e_time=$(( $end - $start ))
+
+#echo "Final Performance ms/step : $average_perf"
+echo "Final Training Duration sec : $e2e_time"
+
+#结果打印,不需要修改
+echo "------------------ Final result ------------------"
+#输出性能FPS,需要模型审视修改
+TrainingTime=`grep 1875/1875 $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk '{print $3}'|awk 'NR==2'|tr -cd "[0-9]"`
+wait
+FPS=`awk 'BEGIN{printf "%.2f\n",'1875'*'${batch_size}'/'${TrainingTime}'}'`
+#打印,不需要修改
+echo "Final Performance images/sec : $FPS"
+
+#输出训练精度,需要模型审视修改
+train_accuracy=`grep sparse_categorical_accuracy $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log |awk 'END {print $NF}'`
+#打印,不需要修改
+echo "Final Train Accuracy : ${train_accuracy}"
+
+
+#精度看护结果汇总
+#训练用例信息,不需要修改
+BatchSize=${batch_size}
+DeviceType=`uname -m`
+CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf'
+
+##获取性能数据,不需要修改
+#吞吐量
+ActualFPS=${FPS}
+#单迭代训练时长
+TrainingTime=${TrainingTime}
+
+#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视
+grep student_loss $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk '{print $9}' >> $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt
+#最后一个迭代loss值,不需要修改
+ActualLoss=`awk 'END {print $1}' $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt`
+
+ModelStatus="图执行FAIL"
+DTS_Number="DTS2021090622224"
+# error_msg="E19999"
+error_msg="EZ3002: Optype \[Conv2DBackpropFilter\] of Ops kernel \[AIcoreEngine\] is unsupported"
+Status=`grep "${error_msg}" $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|wc -l`
+# error_msg="Graph engine process graph failed: E19999: Inner Error! Output shape is still unknown after shape inference. shape = [-1]."
+
+#关键信息打印到${CaseName}.log中,不需要修改
+echo "Network = ${Network}" > $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "RankSize = ${RANK_SIZE}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "BatchSize = ${BatchSize}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "DeviceType = ${DeviceType}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "CaseName = ${CaseName}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ModelStatus = ${ModelStatus}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "DTS_Number = ${DTS_Number}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "Status = ${Status}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "error_msg = ${error_msg}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+#echo "ActualFPS = ${ActualFPS}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+#echo "TrainingTime = ${TrainingTime}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+#echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+#echo "ActualLoss = ${ActualLoss}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
diff --git a/TensorFlow2/built-in/keras_sample/pointnet_ID2531_for_TensorFlow2.X/test/train_performance_1p_static_eval.sh b/TensorFlow2/built-in/keras_sample/pointnet_ID2531_for_TensorFlow2.X/test/train_performance_1p_static_eval.sh
new file mode 100644
index 0000000000000000000000000000000000000000..6b839114f95fa4a7c734c21acfe0eced43dec7de
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/pointnet_ID2531_for_TensorFlow2.X/test/train_performance_1p_static_eval.sh
@@ -0,0 +1,104 @@
+#!/bin/bash
+cur_path=`pwd`/../
+
+#基础参数,需要模型审视修改
+#Batch Size
+batch_size=32
+#网络名称,同目录名称
+Network="pointnet_ID2531_for_TensorFlow2.X"
+#Device数量,单卡默认为1
+RANK_SIZE=1
+#训练epoch,可选
+train_epochs=1
+#训练step
+train_steps=60000
+#学习率
+#learning_rate=1e-5
+
+#参数配置
+data_path=""
+
+if [[ $1 == --help || $1 == --h ]];then
+ echo "usage: ./train_performance_1p.sh"
+ exit 1
+fi
+
+for para in $*
+do
+ if [[ $para == --data_path* ]];then
+ data_path=`echo ${para#*=}`
+ fi
+done
+
+if [[ $data_path == "" ]];then
+ echo "[Error] para \"data_path \" must be config"
+ exit 1
+fi
+
+##############执行训练##########
+cd $cur_path
+
+if [ -d $cur_path/test/output ];then
+ rm -rf $cur_path/test/output/*
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+else
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+fi
+wait
+
+start=$(date +%s)
+nohup python3 pointnet.py --data_path=$data_path \
+ --epochs=$train_epochs \
+ --batch_size=$batch_size \
+ --drop_remainder=True > $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 &
+wait
+
+end=$(date +%s)
+e2e_time=$(( $end - $start ))
+
+#echo "Final Performance ms/step : $average_perf"
+echo "Final Training Duration sec : $e2e_time"
+
+#结果打印,不需要修改
+echo "------------------ Final result ------------------"
+#输出性能FPS,需要模型审视修改
+TrainingTime=`grep ms/step $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | awk 'NR==1' | awk -F " " '{print$5}' | tr -cd "[0-9]"`
+wait
+FPS=`awk 'BEGIN{printf "%.2f\n",'1000'*'${batch_size}'/'${TrainingTime}'}'`
+#打印,不需要修改
+echo "Final Performance images/sec : $FPS"
+
+#输出训练精度,需要模型审视修改
+train_accuracy=`grep " val_sparse_categorical_accuracy:" $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | awk 'END {print $17}'`
+#打印,不需要修改
+echo "Final Train Accuracy : ${train_accuracy}"
+
+
+#精度看护结果汇总
+#训练用例信息,不需要修改
+BatchSize=${batch_size}
+DeviceType=`uname -m`
+CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf'
+
+##获取性能数据,不需要修改
+#吞吐量
+ActualFPS=${FPS}
+#单迭代训练时长
+TrainingTime=${TrainingTime}
+
+#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视
+grep " loss:" $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | awk '{print $8}' >> $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt
+#最后一个迭代loss值,不需要修改
+ActualLoss=`awk 'END {print $1}' $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt`
+
+#关键信息打印到${CaseName}.log中,不需要修改
+echo "Network = ${Network}" > $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "RankSize = ${RANK_SIZE}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "BatchSize = ${BatchSize}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "DeviceType = ${DeviceType}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "CaseName = ${CaseName}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualFPS = ${ActualFPS}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainingTime = ${TrainingTime}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualLoss = ${ActualLoss}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
diff --git a/TensorFlow2/built-in/keras_sample/pointnet_segmentation_ID2532_for_TensorFlow2.X/LICENSE b/TensorFlow2/built-in/keras_sample/pointnet_segmentation_ID2532_for_TensorFlow2.X/LICENSE
new file mode 100644
index 0000000000000000000000000000000000000000..ab652360b248f2947c2e3ccf306ca128660ea731
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/pointnet_segmentation_ID2532_for_TensorFlow2.X/LICENSE
@@ -0,0 +1,284 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+------------------
+Files: third_party/compute_library/...
+
+MIT License
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+
+------------------
+Files: ACKNOWLEDGEMENTS
+LICENSE
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+------------------
+Files: third_party/hexagon
+
+Copyright (c) 2016-2019, The Linux Foundation. All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted (subject to the limitations in the
+disclaimer below) provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+
+ * Neither the name of The Linux Foundation nor the names of its
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
+GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
+HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/TensorFlow2/built-in/keras_sample/pointnet_segmentation_ID2532_for_TensorFlow2.X/ReadME.md b/TensorFlow2/built-in/keras_sample/pointnet_segmentation_ID2532_for_TensorFlow2.X/ReadME.md
new file mode 100644
index 0000000000000000000000000000000000000000..46f7d72e9c57f1d6ff149ee6b5babe67deaae219
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/pointnet_segmentation_ID2532_for_TensorFlow2.X/ReadME.md
@@ -0,0 +1,31 @@
+# 一、基础信息
+
+网络名称:`pointnet_segmentation_ID2532_for_TensorFlow2.X`
+
+github addr:https://github.com/keras-team/keras-io/tree/master/examples/vision
+
+# 二、代码修改
+
+# 三、程序运行
+
+```shell
+bash run_1p.sh
+```
+
+# 四、归档文件路径
+
+1、数据集
+原始数据集:https://github.com/soumik12345/point-cloud-segmentation/releases/download/v0.1/shapenet.zip
+根据代码,实际归档:
+ PartAnnotation/02691156/
+ PartAnnotation/metadata.json
+
+2、归档文件
+
+3、迁移代码
+
+4、源代码
+
+5、源迁移代码
+
+# 五、NPU工作环境
\ No newline at end of file
diff --git a/TensorFlow2/built-in/keras_sample/pointnet_segmentation_ID2532_for_TensorFlow2.X/pointnet_segmentation.py b/TensorFlow2/built-in/keras_sample/pointnet_segmentation_ID2532_for_TensorFlow2.X/pointnet_segmentation.py
new file mode 100644
index 0000000000000000000000000000000000000000..a90419dc0be4a464f2c5560dcff66ec7010ca054
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/pointnet_segmentation_ID2532_for_TensorFlow2.X/pointnet_segmentation.py
@@ -0,0 +1,666 @@
+#
+# Copyright 2017 The TensorFlow Authors. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============================================================================
+# Copyright 2021 Huawei Technologies Co., Ltd
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+"""
+Title: Point cloud segmentation with PointNet
+Author: [Soumik Rakshit](https://github.com/soumik12345), [Sayak Paul](https://github.com/sayakpaul)
+Date created: 2020/10/23
+Last modified: 2020/10/24
+Description: Implementation of a PointNet-based model for segmenting point clouds.
+"""
+"""
+## Introduction
+
+A "point cloud" is an important type of data structure for storing geometric shape data.
+Due to its irregular format, it's often transformed into
+regular 3D voxel grids or collections of images before being used in deep learning applications,
+a step which makes the data unnecessarily large.
+The PointNet family of models solves this problem by directly consuming point clouds, respecting
+the permutation-invariance property of the point data. The PointNet family of
+models provides a simple, unified architecture
+for applications ranging from **object classification**, **part segmentation**, to
+**scene semantic parsing**.
+
+In this example, we demonstrate the implementation of the PointNet architecture
+for shape segmentation.
+
+### References
+
+- [PointNet: Deep Learning on Point Sets for 3D Classification and Segmentation](https://arxiv.org/abs/1612.00593)
+- [Point cloud classification with PointNet](https://keras.io/examples/vision/pointnet/)
+- [Spatial Transformer Networks](https://arxiv.org/abs/1506.02025)
+"""
+
+"""
+## Imports
+"""
+
+import os
+import json
+import random
+import numpy as np
+import pandas as pd
+from tqdm import tqdm
+from glob import glob
+
+import tensorflow as tf
+from tensorflow import keras
+from tensorflow.keras import layers
+
+import npu_device
+npu_device.open().as_default()
+
+import matplotlib.pyplot as plt
+
+import argparse
+import ast
+
+
+def parse_args():
+ parser = argparse.ArgumentParser(
+ formatter_class=argparse.ArgumentDefaultsHelpFormatter)
+ parser.add_argument('--data_path', default='./',
+ help="""directory to data""")
+ parser.add_argument('--batch_size', default=32, type=int,
+ help="""batch size for 1p""")
+ parser.add_argument('--epochs', default=60, type=int,
+ help="""epochs""")
+ parser.add_argument('--drop_remainder', default="False", type=ast.literal_eval,
+ help="""drop_remainder True or False remote dynamic or static input""")
+ args, unknown_args = parser.parse_known_args()
+ if len(unknown_args) > 0:
+ for bad_arg in unknown_args:
+ print("ERROR: Unknown command line arg: %s" % bad_arg)
+ raise ValueError("Invalid command line arg(s)")
+ return args
+
+args = parse_args()
+
+"""
+## Downloading Dataset
+
+The [ShapeNet dataset](https://shapenet.org/) is an ongoing effort to establish a richly-annotated,
+large-scale dataset of 3D shapes. **ShapeNetCore** is a subset of the full ShapeNet
+dataset with clean single 3D models and manually verified category and alignment
+annotations. It covers 55 common object categories, with about 51,300 unique 3D models.
+
+For this example, we use one of the 12 object categories of
+[PASCAL 3D+](http://cvgl.stanford.edu/projects/pascal3d.html),
+included as part of the ShapenetCore dataset.
+"""
+
+# dataset_url = "https://github.com/soumik12345/point-cloud-segmentation/releases/download/v0.1/shapenet.zip"
+
+# dataset_path = keras.utils.get_file(
+ # fname="shapenet.zip",
+ # origin=dataset_url,
+ # cache_subdir="datasets",
+ # hash_algorithm="auto",
+ # extract=True,
+ # archive_format="auto",
+ # cache_dir="datasets",
+# )
+
+"""
+## Loading the dataset
+
+We parse the dataset metadata in order to easily map model categories to their
+respective directories and segmentation classes to colors for the purpose of
+visualization.
+"""
+
+metadata_file = os.path.join(args.data_path, "PartAnnotation/metadata.json")
+with open(metadata_file) as json_file:
+ metadata = json.load(json_file)
+
+print(metadata)
+
+"""
+In this example, we train PointNet to segment the parts of an `Airplane` model.
+"""
+
+points_dir = "{}/PartAnnotation/{}/points".format(args.data_path,
+ metadata["Airplane"]["directory"]
+)
+labels_dir = "{}/PartAnnotation/{}/points_label".format(args.data_path,
+ metadata["Airplane"]["directory"]
+)
+LABELS = metadata["Airplane"]["lables"]
+COLORS = metadata["Airplane"]["colors"]
+
+VAL_SPLIT = 0.2
+NUM_SAMPLE_POINTS = 1024
+BATCH_SIZE = args.batch_size
+EPOCHS = args.epochs
+INITIAL_LR = 1e-3
+
+"""
+## Structuring the dataset
+
+We generate the following in-memory data structures from the Airplane point clouds and
+their labels:
+
+- `point_clouds` is a list of `np.array` objects that represent the point cloud data in
+the form of x, y and z coordinates. Axis 0 represents the number of points in the
+point cloud, while axis 1 represents the coordinates. `all_labels` is the list
+that represents the label of each coordinate as a string (needed mainly for
+visualization purposes).
+- `test_point_clouds` is in the same format as `point_clouds`, but doesn't have
+corresponding the labels of the point clouds.
+- `all_labels` is a list of `np.array` objects that represent the point cloud labels
+for each coordinate, corresponding to the `point_clouds` list.
+- `point_cloud_labels` is a list of `np.array` objects that represent the point cloud
+labels for each coordinate in one-hot encoded form, corresponding to the `point_clouds`
+list.
+"""
+
+point_clouds, test_point_clouds = [], []
+point_cloud_labels, all_labels = [], []
+
+points_files = glob(os.path.join(points_dir, "*.pts"))
+for point_file in tqdm(points_files):
+ point_cloud = np.loadtxt(point_file)
+ if point_cloud.shape[0] < NUM_SAMPLE_POINTS:
+ continue
+
+ # Get the file-id of the current point cloud for parsing its
+ # labels.
+ file_id = point_file.split("/")[-1].split(".")[0]
+ label_data, num_labels = {}, 0
+ for label in LABELS:
+ label_file = os.path.join(labels_dir, label, file_id + ".seg")
+ if os.path.exists(label_file):
+ label_data[label] = np.loadtxt(label_file).astype("float32")
+ num_labels = len(label_data[label])
+
+ # Point clouds having labels will be our training samples.
+ try:
+ label_map = ["none"] * num_labels
+ for label in LABELS:
+ for i, data in enumerate(label_data[label]):
+ label_map[i] = label if data == 1 else label_map[i]
+ label_data = [
+ LABELS.index(label) if label != "none" else len(LABELS)
+ for label in label_map
+ ]
+ # Apply one-hot encoding to the dense label representation.
+ label_data = keras.utils.to_categorical(label_data, num_classes=len(LABELS) + 1)
+
+ point_clouds.append(point_cloud)
+ point_cloud_labels.append(label_data)
+ all_labels.append(label_map)
+ except KeyError:
+ test_point_clouds.append(point_cloud)
+
+"""
+Next, we take a look at some samples from the in-memory arrays we just generated:
+"""
+
+# for _ in range(5):
+ # i = random.randint(0, len(point_clouds) - 1)
+ # print(f"point_clouds[{i}].shape:", point_clouds[0].shape)
+ # print(f"point_cloud_labels[{i}].shape:", point_cloud_labels[0].shape)
+ # for j in range(5):
+ # print(
+ # f"all_labels[{i}][{j}]:",
+ # all_labels[i][j],
+ # f"\tpoint_cloud_labels[{i}][{j}]:",
+ # point_cloud_labels[i][j],
+ # "\n",
+ # )
+
+"""
+Now, let's visualize some of the point clouds along with their labels.
+"""
+
+
+# def visualize_data(point_cloud, labels):
+ # df = pd.DataFrame(
+ # data={
+ # "x": point_cloud[:, 0],
+ # "y": point_cloud[:, 1],
+ # "z": point_cloud[:, 2],
+ # "label": labels,
+ # }
+ # )
+ # fig = plt.figure(figsize=(15, 10))
+ # ax = plt.axes(projection="3d")
+ # for index, label in enumerate(LABELS):
+ # c_df = df[df["label"] == label]
+ # try:
+ # ax.scatter(
+ # c_df["x"], c_df["y"], c_df["z"], label=label, alpha=0.5, c=COLORS[index]
+ # )
+ # except IndexError:
+ # pass
+ # ax.legend()
+ # plt.show()
+
+
+# visualize_data(point_clouds[0], all_labels[0])
+# visualize_data(point_clouds[300], all_labels[300])
+
+
+"""
+### Preprocessing
+
+Note that all the point clouds that we have loaded consist of a variable number of points,
+which makes it difficult for us to batch them together. In order to overcome this problem, we
+randomly sample a fixed number of points from each point cloud. We also normalize the
+point clouds in order to make the data scale-invariant.
+"""
+
+for index in tqdm(range(len(point_clouds))):
+ current_point_cloud = point_clouds[index]
+ current_label_cloud = point_cloud_labels[index]
+ current_labels = all_labels[index]
+ num_points = len(current_point_cloud)
+ # Randomly sampling respective indices.
+ sampled_indices = random.sample(list(range(num_points)), NUM_SAMPLE_POINTS)
+ # Sampling points corresponding to sampled indices.
+ sampled_point_cloud = np.array([current_point_cloud[i] for i in sampled_indices])
+ # Sampling corresponding one-hot encoded labels.
+ sampled_label_cloud = np.array([current_label_cloud[i] for i in sampled_indices])
+ # Sampling corresponding labels for visualization.
+ sampled_labels = np.array([current_labels[i] for i in sampled_indices])
+ # Normalizing sampled point cloud.
+ norm_point_cloud = sampled_point_cloud - np.mean(sampled_point_cloud, axis=0)
+ norm_point_cloud /= np.max(np.linalg.norm(norm_point_cloud, axis=1))
+ point_clouds[index] = norm_point_cloud
+ point_cloud_labels[index] = sampled_label_cloud
+ all_labels[index] = sampled_labels
+
+"""
+Let's visualize the sampled and normalized point clouds along with their corresponding
+labels.
+"""
+
+# visualize_data(point_clouds[0], all_labels[0])
+# visualize_data(point_clouds[300], all_labels[300])
+
+"""
+### Creating TensorFlow datasets
+
+We create `tf.data.Dataset` objects for the training and validation data.
+We also augment the training point clouds by applying random jitter to them.
+"""
+
+
+def load_data(point_cloud_batch, label_cloud_batch):
+ point_cloud_batch.set_shape([NUM_SAMPLE_POINTS, 3])
+ label_cloud_batch.set_shape([NUM_SAMPLE_POINTS, len(LABELS) + 1])
+ return point_cloud_batch, label_cloud_batch
+
+
+def augment(point_cloud_batch, label_cloud_batch):
+ noise = tf.random.uniform(
+ tf.shape(label_cloud_batch), -0.005, 0.005, dtype=tf.float64
+ )
+ point_cloud_batch += noise[:, :, :3]
+ return point_cloud_batch, label_cloud_batch
+
+
+def generate_dataset(point_clouds, label_clouds, is_training=True):
+ dataset = tf.data.Dataset.from_tensor_slices((point_clouds, label_clouds))
+ dataset = dataset.shuffle(BATCH_SIZE * 100) if is_training else dataset
+ dataset = dataset.map(load_data, num_parallel_calls=tf.data.AUTOTUNE)
+ dataset = dataset.batch(batch_size=BATCH_SIZE, drop_remainder=args.drop_remainder)
+ dataset = (
+ dataset.map(augment, num_parallel_calls=tf.data.AUTOTUNE)
+ if is_training
+ else dataset
+ )
+ return dataset
+
+
+split_index = int(len(point_clouds) * (1 - VAL_SPLIT))
+train_point_clouds = point_clouds[:split_index]
+train_label_cloud = point_cloud_labels[:split_index]
+total_training_examples = len(train_point_clouds)
+
+val_point_clouds = point_clouds[split_index:]
+val_label_cloud = point_cloud_labels[split_index:]
+
+print("Num train point clouds:", len(train_point_clouds))
+print("Num train point cloud labels:", len(train_label_cloud))
+print("Num val point clouds:", len(val_point_clouds))
+print("Num val point cloud labels:", len(val_label_cloud))
+
+train_dataset = generate_dataset(train_point_clouds, train_label_cloud)
+val_dataset = generate_dataset(val_point_clouds, val_label_cloud, is_training=False)
+
+print("Train Dataset:", train_dataset)
+print("Validation Dataset:", val_dataset)
+
+"""
+## PointNet model
+
+The figure below depicts the internals of the PointNet model family:
+
+
+
+Given that PointNet is meant to consume an ***unordered set*** of coordinates as its input data,
+its architecture needs to match the following characteristic properties
+of point cloud data:
+
+### Permutation invariance
+
+Given the unstructured nature of point cloud data, a scan made up of `n` points has `n!`
+permutations. The subsequent data processing must be invariant to the different
+representations. In order to make PointNet invariant to input permutations, we use a
+symmetric function (such as max-pooling) once the `n` input points are mapped to
+higher-dimensional space. The result is a **global feature vector** that aims to capture
+an aggregate signature of the `n` input points. The global feature vector is used alongside
+local point features for segmentation.
+
+
+
+### Transformation invariance
+
+Segmentation outputs should be unchanged if the object undergoes certain transformations,
+such as translation or scaling. For a given input point cloud, we apply an appropriate
+rigid or affine transformation to achieve pose normalization. Because each of the `n` input
+points are represented as a vector and are mapped to the embedding spaces independently,
+applying a geometric transformation simply amounts to matrix multiplying each point with
+a transformation matrix. This is motivated by the concept of
+[Spatial Transformer Networks](https://arxiv.org/abs/1506.02025).
+
+The operations comprising the T-Net are motivated by the higher-level architecture of
+PointNet. MLPs (or fully-connected layers) are used to map the input points independently
+and identically to a higher-dimensional space; max-pooling is used to encode a global
+feature vector whose dimensionality is then reduced with fully-connected layers. The
+input-dependent features at the final fully-connected layer are then combined with
+globally trainable weights and biases, resulting in a 3-by-3 transformation matrix.
+
+
+
+### Point interactions
+
+The interaction between neighboring points often carries useful information (i.e., a
+single point should not be treated in isolation). Whereas classification need only make
+use of global features, segmentation must be able to leverage local point features along
+with global point features.
+
+
+**Note**: The figures presented in this section have been taken from the
+[original paper](https://arxiv.org/abs/1612.00593).
+"""
+
+"""
+Now that we know the pieces that compose the PointNet model, we can implement the model.
+We start by implementing the basic blocks i.e., the convolutional block and the multi-layer
+perceptron block.
+"""
+
+
+def conv_block(x: tf.Tensor, filters: int, name: str) -> tf.Tensor:
+ x = layers.Conv1D(filters, kernel_size=1, padding="valid", name=f"{name}_conv")(x)
+ x = layers.BatchNormalization(momentum=0.0, name=f"{name}_batch_norm")(x)
+ return layers.Activation("relu", name=f"{name}_relu")(x)
+
+
+def mlp_block(x: tf.Tensor, filters: int, name: str) -> tf.Tensor:
+ x = layers.Dense(filters, name=f"{name}_dense")(x)
+ x = layers.BatchNormalization(momentum=0.0, name=f"{name}_batch_norm")(x)
+ return layers.Activation("relu", name=f"{name}_relu")(x)
+
+
+"""
+We implement a regularizer (taken from
+[this example](https://keras.io/examples/vision/pointnet/#build-a-model))
+to enforce orthogonality in the feature space. This is needed to ensure
+that the magnitudes of the transformed features do not vary too much.
+"""
+
+
+class OrthogonalRegularizer(keras.regularizers.Regularizer):
+ """Reference: https://keras.io/examples/vision/pointnet/#build-a-model"""
+
+ def __init__(self, num_features, l2reg=0.001):
+ self.num_features = num_features
+ self.l2reg = l2reg
+ self.identity = tf.eye(num_features)
+
+ def __call__(self, x):
+ x = tf.reshape(x, (-1, self.num_features, self.num_features))
+ xxt = tf.tensordot(x, x, axes=(2, 2))
+ xxt = tf.reshape(xxt, (-1, self.num_features, self.num_features))
+ return tf.reduce_sum(self.l2reg * tf.square(xxt - self.identity))
+
+ def get_config(self):
+ config = super(TransformerEncoder, self).get_config()
+ config.update({"num_features": self.num_features, "l2reg_strength": self.l2reg})
+ return config
+
+
+"""
+The next piece is the transformation network which we explained earlier.
+"""
+
+
+def transformation_net(inputs: tf.Tensor, num_features: int, name: str) -> tf.Tensor:
+ """
+ Reference: https://keras.io/examples/vision/pointnet/#build-a-model.
+
+ The `filters` values come from the original paper:
+ https://arxiv.org/abs/1612.00593.
+ """
+ x = conv_block(inputs, filters=64, name=f"{name}_1")
+ x = conv_block(x, filters=128, name=f"{name}_2")
+ x = conv_block(x, filters=1024, name=f"{name}_3")
+ x = layers.GlobalMaxPooling1D()(x)
+ x = mlp_block(x, filters=512, name=f"{name}_1_1")
+ x = mlp_block(x, filters=256, name=f"{name}_2_1")
+ return layers.Dense(
+ num_features * num_features,
+ kernel_initializer="zeros",
+ bias_initializer=keras.initializers.Constant(np.eye(num_features).flatten()),
+ activity_regularizer=OrthogonalRegularizer(num_features),
+ name=f"{name}_final",
+ )(x)
+
+
+def transformation_block(inputs: tf.Tensor, num_features: int, name: str) -> tf.Tensor:
+ transformed_features = transformation_net(inputs, num_features, name=name)
+ transformed_features = layers.Reshape((num_features, num_features))(
+ transformed_features
+ )
+ return layers.Dot(axes=(2, 1), name=f"{name}_mm")([inputs, transformed_features])
+
+
+"""
+Finally, we piece the above blocks together and implement the segmentation model.
+"""
+
+
+def get_shape_segmentation_model(num_points: int, num_classes: int) -> keras.Model:
+ input_points = keras.Input(shape=(None, 3))
+
+ # PointNet Classification Network.
+ transformed_inputs = transformation_block(
+ input_points, num_features=3, name="input_transformation_block"
+ )
+ features_64 = conv_block(transformed_inputs, filters=64, name="features_64")
+ features_128_1 = conv_block(features_64, filters=128, name="features_128_1")
+ features_128_2 = conv_block(features_128_1, filters=128, name="features_128_2")
+ transformed_features = transformation_block(
+ features_128_2, num_features=128, name="transformed_features"
+ )
+ features_512 = conv_block(transformed_features, filters=512, name="features_512")
+ features_2048 = conv_block(features_512, filters=2048, name="pre_maxpool_block")
+ global_features = layers.MaxPool1D(pool_size=num_points, name="global_features")(
+ features_2048
+ )
+ global_features = tf.tile(global_features, [1, num_points, 1])
+
+ # Segmentation head.
+ segmentation_input = layers.Concatenate(name="segmentation_input")(
+ [
+ features_64,
+ features_128_1,
+ features_128_2,
+ transformed_features,
+ features_512,
+ global_features,
+ ]
+ )
+ segmentation_features = conv_block(
+ segmentation_input, filters=128, name="segmentation_features"
+ )
+ outputs = layers.Conv1D(
+ num_classes, kernel_size=1, activation="softmax", name="segmentation_head"
+ )(segmentation_features)
+ return keras.Model(input_points, outputs)
+
+
+"""
+## Instantiate the model
+"""
+
+x, y = next(iter(train_dataset))
+
+num_points = x.shape[1]
+num_classes = y.shape[-1]
+
+segmentation_model = get_shape_segmentation_model(num_points, num_classes)
+segmentation_model.summary()
+
+"""
+## Training
+
+For the training the authors recommend using a learning rate schedule that decays the
+initial learning rate by half every 20 epochs. In this example, we resort to 15 epochs.
+"""
+
+training_step_size = total_training_examples // BATCH_SIZE
+total_training_steps = training_step_size * EPOCHS
+print(f"Total training steps: {total_training_steps}.")
+
+lr_schedule = keras.optimizers.schedules.PiecewiseConstantDecay(
+ boundaries=[training_step_size * 15, training_step_size * 15],
+ values=[INITIAL_LR, INITIAL_LR * 0.5, INITIAL_LR * 0.25],
+)
+
+steps = tf.range(total_training_steps, dtype=tf.int32)
+lrs = [lr_schedule(step) for step in steps]
+
+# plt.plot(lrs)
+# plt.xlabel("Steps")
+# plt.ylabel("Learning Rate")
+# plt.show()
+
+"""
+Finally, we implement a utility for running our experiments and launch model training.
+"""
+
+def run_experiment(epochs):
+
+ segmentation_model = get_shape_segmentation_model(num_points, num_classes)
+ segmentation_model.compile(
+ optimizer=keras.optimizers.Adam(learning_rate=lr_schedule),
+ loss=keras.losses.CategoricalCrossentropy(),
+ metrics=["accuracy"],
+ )
+
+ checkpoint_filepath = "/tmp/checkpoint"
+ checkpoint_callback = keras.callbacks.ModelCheckpoint(
+ checkpoint_filepath,
+ monitor="val_loss",
+ save_best_only=True,
+ save_weights_only=True,
+ )
+
+ history = segmentation_model.fit(
+ train_dataset,
+ validation_data=val_dataset,
+ epochs=epochs,
+ callbacks=[checkpoint_callback],
+ )
+ segmentation_model.save_weights(filepath="pointnet_segmentation", save_format="tf")
+
+ segmentation_model.load_weights(checkpoint_filepath)
+
+ return segmentation_model, history
+
+
+segmentation_model, history = run_experiment(epochs=EPOCHS)
+
+"""
+## Visualize the training landscape
+"""
+
+
+# def plot_result(item):
+ # plt.plot(history.history[item], label=item)
+ # plt.plot(history.history["val_" + item], label="val_" + item)
+ # plt.xlabel("Epochs")
+ # plt.ylabel(item)
+ # plt.title("Train and Validation {} Over Epochs".format(item), fontsize=14)
+ # plt.legend()
+ # plt.grid()
+ # plt.show()
+
+
+# plot_result("loss")
+# plot_result("accuracy")
+
+"""
+## Inference
+"""
+
+"""
+validation_batch = next(iter(val_dataset))
+val_predictions = segmentation_model.predict(validation_batch[0])
+print(f"Validation prediction shape: {val_predictions.shape}")
+
+
+def visualize_single_point_cloud(point_clouds, label_clouds, idx):
+ label_map = LABELS + ["none"]
+ point_cloud = point_clouds[idx]
+ label_cloud = label_clouds[idx]
+ visualize_data(point_cloud, [label_map[np.argmax(label)] for label in label_cloud])
+
+
+idx = np.random.choice(len(validation_batch[0]))
+print(f"Index selected: {idx}")
+
+# Plotting with ground-truth.
+visualize_single_point_cloud(validation_batch[0], validation_batch[1], idx)
+
+# Plotting with predicted labels.
+visualize_single_point_cloud(validation_batch[0], val_predictions, idx)
+"""
+
+"""
+## Final notes
+
+If you are interested in learning more about this topic, you may find
+[this repository](https://github.com/soumik12345/point-cloud-segmentation)
+useful.
+"""
diff --git a/TensorFlow2/built-in/keras_sample/pointnet_segmentation_ID2532_for_TensorFlow2.X/requirements.txt b/TensorFlow2/built-in/keras_sample/pointnet_segmentation_ID2532_for_TensorFlow2.X/requirements.txt
new file mode 100644
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
diff --git a/TensorFlow2/built-in/keras_sample/pointnet_segmentation_ID2532_for_TensorFlow2.X/test/train_full_1p.sh b/TensorFlow2/built-in/keras_sample/pointnet_segmentation_ID2532_for_TensorFlow2.X/test/train_full_1p.sh
new file mode 100644
index 0000000000000000000000000000000000000000..7c84b7d201095c698c6361a4ac1057ac0b4fcb0a
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/pointnet_segmentation_ID2532_for_TensorFlow2.X/test/train_full_1p.sh
@@ -0,0 +1,104 @@
+#!/bin/bash
+cur_path=`pwd`/../
+
+#基础参数,需要模型审视修改
+#Batch Size
+batch_size=32
+#网络名称,同目录名称
+Network="pointnet_segmentation_ID2532_for_TensorFlow2.X"
+#Device数量,单卡默认为1
+RANK_SIZE=1
+#训练epoch,可选
+train_epochs=60
+#训练step
+train_steps=60000
+#学习率
+#learning_rate=1e-5
+
+#参数配置
+data_path=""
+
+if [[ $1 == --help || $1 == --h ]];then
+ echo "usage: ./train_performance_1p.sh"
+ exit 1
+fi
+
+for para in $*
+do
+ if [[ $para == --data_path* ]];then
+ data_path=`echo ${para#*=}`
+ fi
+done
+
+if [[ $data_path == "" ]];then
+ echo "[Error] para \"data_path \" must be config"
+ exit 1
+fi
+
+##############执行训练##########
+cd $cur_path
+
+if [ -d $cur_path/test/output ];then
+ rm -rf $cur_path/test/output/*
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+else
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+fi
+wait
+
+start=$(date +%s)
+nohup python3 pointnet_segmentation.py --data_path=$data_path \
+ --epochs=$train_epochs \
+ --batch_size=$batch_size \
+ --drop_remainder=True > $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 &
+wait
+
+end=$(date +%s)
+e2e_time=$(( $end - $start ))
+
+#echo "Final Performance ms/step : $average_perf"
+echo "Final Training Duration sec : $e2e_time"
+
+#结果打印,不需要修改
+echo "------------------ Final result ------------------"
+#输出性能FPS,需要模型审视修改
+TrainingTime=`grep "ms/step" $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | awk 'NR==1' | awk -F " " '{print$5}' | tr -cd "[0-9]"`
+wait
+FPS=`awk 'BEGIN{printf "%.2f\n",'1000'*'${batch_size}'/'${TrainingTime}'}'`
+#打印,不需要修改
+echo "Final Performance images/sec : $FPS"
+
+#输出训练精度,需要模型审视修改
+train_accuracy=`grep " val_accuracy:" $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | awk 'END {print $17}'`
+#打印,不需要修改
+echo "Final Train Accuracy : ${train_accuracy}"
+
+
+#精度看护结果汇总
+#训练用例信息,不需要修改
+BatchSize=${batch_size}
+DeviceType=`uname -m`
+CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc'
+
+##获取性能数据,不需要修改
+#吞吐量
+ActualFPS=${FPS}
+#单迭代训练时长
+TrainingTime=${TrainingTime}
+
+#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视
+grep " loss:" $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk '{print $8}' >> $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt
+#最后一个迭代loss值,不需要修改
+ActualLoss=`awk 'END {print $1}' $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt`
+
+#关键信息打印到${CaseName}.log中,不需要修改
+echo "Network = ${Network}" > $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "RankSize = ${RANK_SIZE}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "BatchSize = ${BatchSize}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "DeviceType = ${DeviceType}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "CaseName = ${CaseName}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualFPS = ${ActualFPS}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainingTime = ${TrainingTime}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualLoss = ${ActualLoss}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
diff --git a/TensorFlow2/built-in/keras_sample/pointnet_segmentation_ID2532_for_TensorFlow2.X/test/train_performance_1p_dynamic_eval.sh b/TensorFlow2/built-in/keras_sample/pointnet_segmentation_ID2532_for_TensorFlow2.X/test/train_performance_1p_dynamic_eval.sh
new file mode 100644
index 0000000000000000000000000000000000000000..bd71305f9a7689dfd4feab036f6e776d9bc33267
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/pointnet_segmentation_ID2532_for_TensorFlow2.X/test/train_performance_1p_dynamic_eval.sh
@@ -0,0 +1,115 @@
+#!/bin/bash
+cur_path=`pwd`/../
+
+#基础参数,需要模型审视修改
+#Batch Size
+batch_size=32
+#网络名称,同目录名称
+Network="pointnet_segmentation_ID2532_for_TensorFlow2.X"
+#Device数量,单卡默认为1
+RANK_SIZE=1
+#训练epoch,可选
+train_epochs=1
+#训练step
+train_steps=60000
+#学习率
+#learning_rate=1e-5
+
+#参数配置
+data_path=""
+
+if [[ $1 == --help || $1 == --h ]];then
+ echo "usage: ./train_performance_1p.sh"
+ exit 1
+fi
+
+for para in $*
+do
+ if [[ $para == --data_path* ]];then
+ data_path=`echo ${para#*=}`
+ fi
+done
+
+if [[ $data_path == "" ]];then
+ echo "[Error] para \"data_path \" must be config"
+ exit 1
+fi
+
+##############执行训练##########
+cd $cur_path
+
+if [ -d $cur_path/test/output ];then
+ rm -rf $cur_path/test/output/*
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+else
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+fi
+wait
+
+start=$(date +%s)
+nohup python3 pointnet_segmentation.py --data_path=$data_path \
+ --epochs=$train_epochs \
+ --batch_size=$batch_size \
+ --drop_remainder=False > $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 &
+wait
+
+end=$(date +%s)
+e2e_time=$(( $end - $start ))
+
+##echo "Final Performance ms/step : $average_perf"
+echo "Final Training Duration sec : $e2e_time"
+
+##结果打印,不需要修改
+#echo "------------------ Final result ------------------"
+##输出性能FPS,需要模型审视修改
+#TrainingTime=`grep 1875/1875 $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk '{print $3}'|awk 'NR==2'|tr -cd "[0-9]"`
+#wait
+#FPS=`awk 'BEGIN{printf "%.2f\n",'1875'*'${batch_size}'/'${TrainingTime}'}'`
+##打印,不需要修改
+#echo "Final Performance images/sec : $FPS"
+
+##输出训练精度,需要模型审视修改
+#train_accuracy=`grep sparse_categorical_accuracy $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log |awk 'END {print $NF}'`
+##打印,不需要修改
+#echo "Final Train Accuracy : ${train_accuracy}"
+
+
+#精度看护结果汇总
+#训练用例信息,不需要修改
+BatchSize=${batch_size}
+DeviceType=`uname -m`
+CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf'
+
+##获取性能数据,不需要修改
+##吞吐量
+#ActualFPS=${FPS}
+##单迭代训练时长
+#TrainingTime=${TrainingTime}
+
+##从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视
+#grep student_loss $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk '{print $9}' >> $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt
+##最后一个迭代loss值,不需要修改
+#ActualLoss=`awk 'END {print $1}' $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt`
+
+ModelStatus="图执行FAIL"
+DTS_Number="DTS2021090622224"
+# error_msg="E19999"
+error_msg="EZ3002: Optype \[Conv2DBackpropFilter\] of Ops kernel \[AIcoreEngine\] is unsupported"
+Status=`grep "${error_msg}" $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|wc -l`
+# error_msg="Graph engine process graph failed: E19999: Inner Error! Output shape is still unknown after shape inference. shape = [-1]."
+
+#关键信息打印到${CaseName}.log中,不需要修改
+echo "Network = ${Network}" > $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "RankSize = ${RANK_SIZE}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "BatchSize = ${BatchSize}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "DeviceType = ${DeviceType}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "CaseName = ${CaseName}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ModelStatus = ${ModelStatus}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "DTS_Number = ${DTS_Number}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "Status = ${Status}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "error_msg = ${error_msg}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+#echo "ActualFPS = ${ActualFPS}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+#echo "TrainingTime = ${TrainingTime}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+#echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+#echo "ActualLoss = ${ActualLoss}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
diff --git a/TensorFlow2/built-in/keras_sample/pointnet_segmentation_ID2532_for_TensorFlow2.X/test/train_performance_1p_static_eval.sh b/TensorFlow2/built-in/keras_sample/pointnet_segmentation_ID2532_for_TensorFlow2.X/test/train_performance_1p_static_eval.sh
new file mode 100644
index 0000000000000000000000000000000000000000..33d80ab04cb2b900bd9adb9d22183d875694e093
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/pointnet_segmentation_ID2532_for_TensorFlow2.X/test/train_performance_1p_static_eval.sh
@@ -0,0 +1,104 @@
+#!/bin/bash
+cur_path=`pwd`/../
+
+#基础参数,需要模型审视修改
+#Batch Size
+batch_size=32
+#网络名称,同目录名称
+Network="pointnet_segmentation_ID2532_for_TensorFlow2.X"
+#Device数量,单卡默认为1
+RANK_SIZE=1
+#训练epoch,可选
+train_epochs=1
+#训练step
+train_steps=60000
+#学习率
+#learning_rate=1e-5
+
+#参数配置
+data_path=""
+
+if [[ $1 == --help || $1 == --h ]];then
+ echo "usage: ./train_performance_1p.sh"
+ exit 1
+fi
+
+for para in $*
+do
+ if [[ $para == --data_path* ]];then
+ data_path=`echo ${para#*=}`
+ fi
+done
+
+if [[ $data_path == "" ]];then
+ echo "[Error] para \"data_path \" must be config"
+ exit 1
+fi
+
+##############执行训练##########
+cd $cur_path
+
+if [ -d $cur_path/test/output ];then
+ rm -rf $cur_path/test/output/*
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+else
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+fi
+wait
+
+start=$(date +%s)
+nohup python3 pointnet_segmentation.py --data_path=$data_path \
+ --epochs=$train_epochs \
+ --batch_size=$batch_size \
+ --drop_remainder=True > $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 &
+wait
+
+end=$(date +%s)
+e2e_time=$(( $end - $start ))
+
+#echo "Final Performance ms/step : $average_perf"
+echo "Final Training Duration sec : $e2e_time"
+
+#结果打印,不需要修改
+echo "------------------ Final result ------------------"
+#输出性能FPS,需要模型审视修改
+TrainingTime=`grep "ms/step" $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | awk 'NR==1' | awk -F " " '{print$5}' | tr -cd "[0-9]"`
+wait
+FPS=`awk 'BEGIN{printf "%.2f\n",'1000'*'${batch_size}'/'${TrainingTime}'}'`
+#打印,不需要修改
+echo "Final Performance images/sec : $FPS"
+
+#输出训练精度,需要模型审视修改
+train_accuracy=`grep " val_accuracy:" $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | awk 'END {print $17}'`
+#打印,不需要修改
+echo "Final Train Accuracy : ${train_accuracy}"
+
+
+#精度看护结果汇总
+#训练用例信息,不需要修改
+BatchSize=${batch_size}
+DeviceType=`uname -m`
+CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf'
+
+##获取性能数据,不需要修改
+#吞吐量
+ActualFPS=${FPS}
+#单迭代训练时长
+TrainingTime=${TrainingTime}
+
+#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视
+grep " loss:" $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | awk '{print $8}' >> $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt
+#最后一个迭代loss值,不需要修改
+ActualLoss=`awk 'END {print $1}' $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt`
+
+#关键信息打印到${CaseName}.log中,不需要修改
+echo "Network = ${Network}" > $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "RankSize = ${RANK_SIZE}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "BatchSize = ${BatchSize}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "DeviceType = ${DeviceType}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "CaseName = ${CaseName}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualFPS = ${ActualFPS}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainingTime = ${TrainingTime}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualLoss = ${ActualLoss}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
diff --git a/TensorFlow2/built-in/keras_sample/siamese_contrastive_ID2538_for_TensorFlow2.X/LICENSE b/TensorFlow2/built-in/keras_sample/siamese_contrastive_ID2538_for_TensorFlow2.X/LICENSE
new file mode 100644
index 0000000000000000000000000000000000000000..51d555a151df9c6c96d16137aa4bcf6142a447ef
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/siamese_contrastive_ID2538_for_TensorFlow2.X/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2018 Ke YU
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/TensorFlow2/built-in/keras_sample/siamese_contrastive_ID2538_for_TensorFlow2.X/README.md b/TensorFlow2/built-in/keras_sample/siamese_contrastive_ID2538_for_TensorFlow2.X/README.md
new file mode 100644
index 0000000000000000000000000000000000000000..b9a418b2b70732d994e3e458d149ec7ebf7472ab
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/siamese_contrastive_ID2538_for_TensorFlow2.X/README.md
@@ -0,0 +1,191 @@
+- [基本信息](#基本信息.md)
+- [概述](#概述.md)
+- [训练环境准备](#训练环境准备.md)
+- [快速上手](#快速上手.md)
+- [迁移学习指导](#迁移学习指导.md)
+- [高级参考](#高级参考.md)
+基本信息
+
+**发布者(Publisher):Huawei**
+
+**应用领域(Application Domain):Image Classification**
+
+**版本(Version):1.1**
+
+**修改时间(Modified) :2022.4.8**
+
+**大小(Size):35KB**
+
+**框架(Framework):TensorFlow_2.6.2**
+
+**模型格式(Model Format):ckpt**
+
+**精度(Precision):Mixed**
+
+**处理器(Processor):昇腾910**
+
+**应用级别(Categories):Official**
+
+**描述(Description):基于TensorFlow框架的使用经过对比损失训练的孪生网络进行相似性学习训练代码**
+
+概述
+
+## 简述
+
+孪生网络,是在两个或多个姐妹网络之间共享权重的神经网络,每个生成其各自输入的嵌入向量。在有监督的相似性学习中,网络被训练以最大化不同类输入的嵌入之间的对比(距离),同时最小化之间的距离相似类的嵌入,导致嵌入空间反映训练输入的类分割。
+
+- 参考论文:
+
+ skip
+
+- 参考实现:
+
+ https://github.com/keras-team/keras-io/blob/master/examples/vision/siamese_contrastive.py
+
+- 适配昇腾 AI 处理器的实现:
+
+ skip
+
+- 通过Git获取对应commit\_id的代码方法如下:
+
+ git clone {repository_url} # 克隆仓库的代码
+ cd {repository_name} # 切换到模型的代码仓目录
+ git checkout {branch} # 切换到对应分支
+ git reset --hard {commit_id} # 代码设置到对应的commit_id
+ cd {code_path} # 切换到模型代码所在路径,若仓库下只有该模型,则无需切换
+
+
+## 默认配置
+
+- 网络结构:
+ - 6-layers
+ - 5324 total params
+
+- 训练超参(单卡):
+ - Batch size: 16
+ - Dtype: float32
+ - Margin: 1
+ - Train epoch: 10
+
+
+## 支持特性
+
+| 特性列表 | 是否支持 |
+| ---------- | -------- |
+| 分布式训练 | 否 |
+| 混合精度 | 是 |
+| 数据并行 | 否 |
+
+
+## 混合精度训练
+
+昇腾910 AI处理器提供自动混合精度功能,可以针对全网中float32数据类型的算子,按照内置的优化策略,自动将部分float32的算子降低精度到float16,从而在精度损失很小的情况下提升系统性能并减少内存使用。
+
+## 开启混合精度
+
+拉起脚本中,传入--precision_mode='allow_mix_precision'
+
+```
+ ./train_performance_1p_16bs.sh --help
+
+parameter explain:
+ --precision_mode precision mode(allow_fp32_to_fp16/force_fp16/must_keep_origin_dtype/allow_mix_precision)
+ --over_dump if or not over detection, default is False
+ --data_dump_flag data dump flag, default is False
+ --data_dump_step data dump step, default is 10
+ --profiling if or not profiling for performance debug, default is False
+ --data_path source data of training
+ -h/--help show help message
+```
+
+相关代码示例:
+
+```
+flags.DEFINE_string(name='precision_mode', default= 'allow_fp32_to_fp16',
+ help='allow_fp32_to_fp16/force_fp16/ '
+ 'must_keep_origin_dtype/allow_mix_precision.')
+
+npu_device.global_options().precision_mode=FLAGS.precision_mode
+```
+
+训练环境准备
+
+- 硬件环境和运行环境准备请参见《[CANN软件安装指南](https://support.huawei.com/enterprise/zh/ascend-computing/cann-pid-251168373?category=installation-update)》
+- 运行以下命令安装依赖。
+```
+pip3 install requirements.txt
+```
+说明:依赖配置文件requirements.txt文件位于模型的根目录
+
+快速上手
+
+## 数据集准备
+
+1、用户自行准备好数据集,本网络使用的数据集是MNIST数据集
+
+数据集目录参考如下:
+
+```
+├──mnist.npz
+```
+
+
+
+## 模型训练
+
+- 单击“立即下载”,并选择合适的下载方式下载源码包。
+- 开始训练。
+
+ 1. 启动训练之前,首先要配置程序运行相关环境变量。
+
+ 环境变量配置信息参见:
+
+ [Ascend 910训练平台环境变量设置](https://gitee.com/ascend/modelzoo/wikis/Ascend%20910%E8%AE%AD%E7%BB%83%E5%B9%B3%E5%8F%B0%E7%8E%AF%E5%A2%83%E5%8F%98%E9%87%8F%E8%AE%BE%E7%BD%AE?sort_id=3148819)
+
+ 2. 单卡训练
+
+ 2. 1单卡训练指令(脚本位于siamese_contrastive_ID2538_for_TensorFlow2.X/test/train_full_1p.sh),需要先使用cd命令进入test目录下,再使用下面的命令启动训练。请确保下面例子中的“--data_path”修改为用户的数据路径,这里选择将mnist.npz放在home目录下。
+
+ bash train_full_1p.sh --data_path=/home
+
+
+
+
+高级参考
+
+## 脚本和示例代码
+
+```
+|--LICENSE
+|--README.md #说明文档
+|--siamese_contrastive.py #训练代码
+|--requirements.txt #所需依赖
+|--test #训练脚本目录
+| |--train_full_1p.sh #全量训练脚本
+| |--train_performance_1p.sh #performance训练脚本
+```
+
+## 脚本参数
+
+```
+--data_path # the path to train data
+--batch_size # batch size
+--epochs # epochs of training
+--log_steps # TimeHis log Step
+--precision_mode # the path to save over dump data
+--over_dump # if or not over detection, default is False
+--data_dump_flag # data dump flag, default is False
+--data_dump_step # data dump step, default is 10
+--profiling # if or not profiling for performance debug, default is False
+--profiling_dump_path # the path to save profiling data
+--over_dump_path # the path to save over dump data
+--data_dump_path # the path to save dump data
+--use_mixlist # use_mixlist flag, default is False
+--fusion_off_flag # fusion_off flag, default is False
+--mixlist_file # mixlist file name, default is ops_info.json
+--fusion_off_file # fusion_off file name, default is fusion_switch.cfg
+```
+
+## 训练过程
+
+通过“模型训练”中的训练指令启动单卡或者多卡训练。单卡和多卡通过运行不同脚本,支持单卡,8卡网络训练。模型存储路径为${cur_path}/output/${ASCEND_DEVICE_ID},包括训练的log以及checkpoints文件。以8卡训练为例,loss信息在文件${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log中。
\ No newline at end of file
diff --git a/TensorFlow2/built-in/keras_sample/siamese_contrastive_ID2538_for_TensorFlow2.X/configs/ops_info.json b/TensorFlow2/built-in/keras_sample/siamese_contrastive_ID2538_for_TensorFlow2.X/configs/ops_info.json
new file mode 100644
index 0000000000000000000000000000000000000000..9e13711c61cde970b3fc2b182229cd1d0dfffd2b
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/siamese_contrastive_ID2538_for_TensorFlow2.X/configs/ops_info.json
@@ -0,0 +1,7 @@
+{
+ "black-list":{
+ "to-add":[
+ "SqrtGrad"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/TensorFlow2/built-in/keras_sample/siamese_contrastive_ID2538_for_TensorFlow2.X/modelzoo_level.txt b/TensorFlow2/built-in/keras_sample/siamese_contrastive_ID2538_for_TensorFlow2.X/modelzoo_level.txt
new file mode 100644
index 0000000000000000000000000000000000000000..41666def85dde1920b31cd2284279cd465d60b91
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/siamese_contrastive_ID2538_for_TensorFlow2.X/modelzoo_level.txt
@@ -0,0 +1,3 @@
+FuncStatus:OK
+PerfStatus:PERFECT
+PrecisionStatus:OK
\ No newline at end of file
diff --git a/TensorFlow2/built-in/keras_sample/siamese_contrastive_ID2538_for_TensorFlow2.X/requirements.txt b/TensorFlow2/built-in/keras_sample/siamese_contrastive_ID2538_for_TensorFlow2.X/requirements.txt
new file mode 100644
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
diff --git a/TensorFlow2/built-in/keras_sample/siamese_contrastive_ID2538_for_TensorFlow2.X/siamese_contrastive.py b/TensorFlow2/built-in/keras_sample/siamese_contrastive_ID2538_for_TensorFlow2.X/siamese_contrastive.py
new file mode 100644
index 0000000000000000000000000000000000000000..8ed7493ac25c227943167413eeb920bc76cf5e18
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/siamese_contrastive_ID2538_for_TensorFlow2.X/siamese_contrastive.py
@@ -0,0 +1,412 @@
+#
+# Copyright 2017 The TensorFlow Authors. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============================================================================
+# Copyright 2021 Huawei Technologies Co., Ltd
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+"""
+Title: Image similarity estimation using a Siamese Network with a contrastive loss
+Author: Mehdi
+Date created: 2021/05/06
+Last modified: 2021/05/06
+Description: Similarity learning using a siamese network trained with a contrastive loss.
+"""
+
+"""
+## Introduction
+
+[Siamese Networks](https://en.wikipedia.org/wiki/Siamese_neural_network)
+are neural networks which share weights between two or more sister networks,
+each producing embedding vectors of its respective inputs.
+
+In supervised similarity learning, the networks are then trained to maximize the
+contrast (distance) between embeddings of inputs of different classes, while minimizing the distance between
+embeddings of similar classes, resulting in embedding spaces that reflect
+the class segmentation of the training inputs.
+"""
+
+import npu_device
+import argparse
+import ast
+#===============================NPU Migration=========================================
+parser = argparse.ArgumentParser()
+parser.add_argument('--batch_size', type=int, default=16,help='batch_size')
+parser.add_argument('--epochs', type=int, default=10,help='batch_size')
+parser.add_argument('--log_steps', type=int, default=3750, help='steps per log')
+parser.add_argument('--precision_mode', default="allow_mix_precision", type=str,help='the path to save over dump data')
+parser.add_argument('--over_dump', dest='over_dump', type=ast.literal_eval,
+ help='if or not over detection, default is False')
+parser.add_argument('--data_dump_flag', dest='data_dump_flag', type=ast.literal_eval,
+ help='data dump flag, default is False')
+parser.add_argument('--data_dump_step', default="10",
+ help='data dump step, default is 10')
+parser.add_argument('--profiling', dest='profiling', type=ast.literal_eval,help='if or not profiling for performance debug, default is False')
+parser.add_argument('--profiling_dump_path', default="/home/data", type=str,help='the path to save profiling data')
+parser.add_argument('--over_dump_path', default="/home/data", type=str,help='the path to save over dump data')
+parser.add_argument('--data_dump_path', default="/home/data", type=str,help='the path to save dump data')
+parser.add_argument('--use_mixlist', dest='use_mixlist', type=ast.literal_eval,
+ help='use_mixlist flag, default is False')
+parser.add_argument('--fusion_off_flag', dest='fusion_off_flag', type=ast.literal_eval,
+ help='fusion_off flag, default is False')
+parser.add_argument('--mixlist_file', default="ops_info.json", type=str,help='mixlist file name, default is ops_info.json')
+parser.add_argument('--fusion_off_file', default="fusion_switch.cfg", type=str,help='fusion_off file name, default is fusion_switch.cfg')
+args = parser.parse_args()
+
+def npu_config():
+ if args.data_dump_flag:
+ npu_device.global_options().dump_config.enable_dump = True
+ npu_device.global_options().dump_config.dump_path = args.data_dump_path
+ npu_device.global_options().dump_config.dump_step = args.data_dump_step
+ npu_device.global_options().dump_config.dump_mode = "all"
+
+ if args.over_dump:
+ npu_device.global_options().dump_config.enable_dump_debug = True
+ npu_device.global_options().dump_config.dump_path = args.over_dump_path
+ npu_device.global_options().dump_config.dump_debug_mode = "all"
+
+ if args.profiling:
+ npu_device.global_options().profiling_config.enable_profiling = True
+ profiling_options = '{"output":"' + args.profiling_dump_path + '", \
+ "training_trace":"on", \
+ "task_trace":"on", \
+ "aicpu":"on", \
+ "aic_metrics":"PipeUtilization",\
+ "fp_point":"", \
+ "bp_point":""}'
+ npu_device.global_options().profiling_config.profiling_options = profiling_options
+ npu_device.global_options().precision_mode = args.precision_mode
+ if args.use_mixlist and args.precision_mode=='allow_mix_precision':
+ npu_device.global_options().modify_mixlist=args.mixlist_file
+ if args.fusion_off_flag:
+ npu_device.global_options().fusion_switch_file=args.fusion_off_file
+ npu_device.open().as_default()
+#===============================NPU Migration=========================================
+npu_config()
+
+"""
+## Setup
+"""
+
+import time
+import random
+import numpy as np
+import tensorflow as tf
+from tensorflow import keras
+from tensorflow.keras import layers
+import matplotlib.pyplot as plt
+import argparse
+
+"""
+## Hyperparameters
+"""
+
+
+epochs = args.epochs
+batch_size = args.batch_size
+margin = 1 # Margin for constrastive loss.
+
+"""
+## Load the MNIST dataset
+"""
+
+(x_train_val, y_train_val), (x_test, y_test) = keras.datasets.mnist.load_data()
+
+# Change the data type to a floating point format
+x_train_val = x_train_val.astype("float32")
+x_test = x_test.astype("float32")
+
+
+"""
+## Define training and validation sets
+"""
+
+# Keep 50% of train_val in validation set
+x_train, x_val = x_train_val[:30000], x_train_val[30000:]
+y_train, y_val = y_train_val[:30000], y_train_val[30000:]
+del x_train_val, y_train_val
+
+
+"""
+## Create pairs of images
+
+We will train the model to differentiate between digits of different classes. For
+example, digit `0` needs to be differentiated from the rest of the
+digits (`1` through `9`), digit `1` - from `0` and `2` through `9`, and so on.
+To carry this out, we will select N random images from class A (for example,
+for digit `0`) and pair them with N random images from another class B
+(for example, for digit `1`). Then, we can repeat this process for all classes
+of digits (until digit `9`). Once we have paired digit `0` with other digits,
+we can repeat this process for the remaining classes for the rest of the digits
+(from `1` until `9`).
+"""
+
+
+def make_pairs(x, y):
+ """Creates a tuple containing image pairs with corresponding label.
+
+ Arguments:
+ x: List containing images, each index in this list corresponds to one image.
+ y: List containing labels, each label with datatype of `int`.
+
+ Returns:
+ Tuple containing two numpy arrays as (pairs_of_samples, labels),
+ where pairs_of_samples' shape is (2len(x), 2,n_features_dims) and
+ labels are a binary array of shape (2len(x)).
+ """
+
+ num_classes = max(y) + 1
+ digit_indices = [np.where(y == i)[0] for i in range(num_classes)]
+
+ pairs = []
+ labels = []
+
+ for idx1 in range(len(x)):
+ # add a matching example
+ x1 = x[idx1]
+ label1 = y[idx1]
+ idx2 = random.choice(digit_indices[label1])
+ x2 = x[idx2]
+
+ pairs += [[x1, x2]]
+ labels += [1]
+
+ # add a non-matching example
+ label2 = random.randint(0, num_classes - 1)
+ while label2 == label1:
+ label2 = random.randint(0, num_classes - 1)
+
+ idx2 = random.choice(digit_indices[label2])
+ x2 = x[idx2]
+
+ pairs += [[x1, x2]]
+ labels += [0]
+
+ return np.array(pairs), np.array(labels).astype("float32")
+
+
+# make train pairs
+pairs_train, labels_train = make_pairs(x_train, y_train)
+
+# make validation pairs
+pairs_val, labels_val = make_pairs(x_val, y_val)
+
+# make test pairs
+pairs_test, labels_test = make_pairs(x_test, y_test)
+
+"""
+We get:
+
+**pairs_train.shape = (60000, 2, 28, 28)**
+
+- We have 60,000 pairs
+- Each pair contains 2 images
+- Each image has shape `(28, 28)`
+"""
+
+"""
+Split the training pairs
+"""
+
+x_train_1 = pairs_train[:, 0] # x_train_1.shape is (60000, 28, 28)
+x_train_2 = pairs_train[:, 1]
+
+"""
+Split the validation pairs
+"""
+
+x_val_1 = pairs_val[:, 0] # x_val_1.shape = (60000, 28, 28)
+x_val_2 = pairs_val[:, 1]
+
+"""
+Split the test pairs
+"""
+
+x_test_1 = pairs_test[:, 0] # x_test_1.shape = (20000, 28, 28)
+x_test_2 = pairs_test[:, 1]
+
+
+"""
+## Define the model
+
+There are be two input layers, each leading to its own network, which
+produces embeddings. A `Lambda` layer then merges them using an
+[Euclidean distance](https://en.wikipedia.org/wiki/Euclidean_distance) and the
+merged output is fed to the final network.
+"""
+
+# Provided two tensors t1 and t2
+# Euclidean distance = sqrt(sum(square(t1-t2)))
+def euclidean_distance(vects):
+ """Find the Euclidean distance between two vectors.
+
+ Arguments:
+ vects: List containing two tensors of same length.
+
+ Returns:
+ Tensor containing euclidean distance
+ (as floating point value) between vectors.
+ """
+
+ x, y = vects
+ sum_square = tf.math.reduce_sum(tf.math.square(x - y), axis=1, keepdims=True)
+ return tf.math.sqrt(tf.math.maximum(sum_square, tf.keras.backend.epsilon()))
+
+
+input = layers.Input((28, 28, 1))
+x = tf.keras.layers.BatchNormalization()(input)
+x = layers.Conv2D(4, (5, 5), activation="tanh")(x)
+x = layers.AveragePooling2D(pool_size=(2, 2))(x)
+x = layers.Conv2D(16, (5, 5), activation="tanh")(x)
+x = layers.AveragePooling2D(pool_size=(2, 2))(x)
+x = layers.Flatten()(x)
+
+x = tf.keras.layers.BatchNormalization()(x)
+x = layers.Dense(10, activation="tanh")(x)
+embedding_network = keras.Model(input, x)
+
+
+input_1 = layers.Input((28, 28, 1))
+input_2 = layers.Input((28, 28, 1))
+
+# As mentioned above, Siamese Network share weights between
+# tower networks (sister networks). To allow this, we will use
+# same embedding network for both tower networks.
+tower_1 = embedding_network(input_1)
+tower_2 = embedding_network(input_2)
+
+merge_layer = layers.Lambda(euclidean_distance)([tower_1, tower_2])
+normal_layer = tf.keras.layers.BatchNormalization()(merge_layer)
+output_layer = layers.Dense(1, activation="sigmoid")(normal_layer)
+siamese = keras.Model(inputs=[input_1, input_2], outputs=output_layer)
+
+
+"""
+## Define the constrastive Loss
+"""
+
+
+def loss(margin=1):
+ """Provides 'constrastive_loss' an enclosing scope with variable 'margin'.
+
+ Arguments:
+ margin: Integer, defines the baseline for distance for which pairs
+ should be classified as dissimilar. - (default is 1).
+
+ Returns:
+ 'constrastive_loss' function with data ('margin') attached.
+ """
+
+ # Contrastive loss = mean( (1-true_value) * square(prediction) +
+ # true_value * square( max(margin-prediction, 0) ))
+ def contrastive_loss(y_true, y_pred):
+ """Calculates the constrastive loss.
+
+ Arguments:
+ y_true: List of labels, each label is of type float32.
+ y_pred: List of predictions of same length as of y_true,
+ each label is of type float32.
+
+ Returns:
+ A tensor containing constrastive loss as floating point value.
+ """
+
+ square_pred = tf.math.square(y_pred)
+ margin_square = tf.math.square(tf.math.maximum(margin - (y_pred), 0))
+ return tf.math.reduce_mean(
+ (1 - y_true) * square_pred + (y_true) * margin_square
+ )
+
+ return contrastive_loss
+
+
+"""
+## Compile the model with the contrastive loss
+"""
+
+siamese.compile(loss=loss(margin=margin), optimizer="RMSprop", metrics=["accuracy"])
+
+"""
+## Add time history callbacks
+"""
+
+class TimeHistory(tf.keras.callbacks.Callback):
+ def __init__(self, batch_size, log_steps, initial_step=0):
+ self.batch_size = batch_size
+ super(TimeHistory, self).__init__()
+ self.steps_before_epoch = initial_step
+ self.last_log_step = initial_step
+ self.log_steps = log_steps
+ self.steps_in_epoch = 0
+ self.start_time = None
+
+ @property
+ def global_steps(self):
+ """The current 1-indexed global step."""
+ return self.steps_before_epoch + self.steps_in_epoch
+
+ def on_epoch_begin(self, epoch, logs=None):
+ if not self.start_time:
+ self.start_time = time.time()
+ self.epoch_start = time.time()
+
+ def on_batch_begin(self, batch, logs=None):
+ if not self.start_time:
+ self.start_time = time.time()
+
+ def on_batch_end(self, batch, logs=None):
+ self.steps_in_epoch = batch + 1
+ steps_since_last_log = self.global_steps - self.last_log_step
+ if steps_since_last_log >= self.log_steps:
+ now = time.time()
+ elapsed_time = now - self.start_time
+ steps_per_second = steps_since_last_log / elapsed_time
+ examples_per_second = steps_per_second * self.batch_size
+ print(
+ 'TimeHistory: %.2f seconds, %.2f examples/second between steps %d '
+ 'and %d'%(elapsed_time, examples_per_second, self.last_log_step,
+ self.global_steps),flush=True)
+ self.last_log_step = self.global_steps
+ self.start_time = None
+
+ def on_epoch_end(self, epoch, logs=None):
+ epoch_run_time = time.time() - self.epoch_start
+ self.steps_before_epoch += self.steps_in_epoch
+ self.steps_in_epoch = 0
+
+"""
+## Train the model
+"""
+
+history = siamese.fit(
+ [x_train_1, x_train_2],
+ labels_train,
+ validation_data=([x_val_1, x_val_2], labels_val),
+ batch_size=batch_size,
+ epochs=epochs,
+ verbose=2,
+ callbacks=[TimeHistory(args.batch_size,args.log_steps)],
+)
diff --git a/TensorFlow2/built-in/keras_sample/siamese_contrastive_ID2538_for_TensorFlow2.X/test/train_full_1p.sh b/TensorFlow2/built-in/keras_sample/siamese_contrastive_ID2538_for_TensorFlow2.X/test/train_full_1p.sh
new file mode 100644
index 0000000000000000000000000000000000000000..f0318f5615eea3affa22a0ab31b42b85549f3b76
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/siamese_contrastive_ID2538_for_TensorFlow2.X/test/train_full_1p.sh
@@ -0,0 +1,195 @@
+#!/bin/bash
+
+#当前路径,不需要修改
+cur_path=`pwd`
+#export ASCEND_SLOG_PRINT_TO_STDOUT=1
+
+#集合通信参数,不需要修改
+
+export RANK_SIZE=1
+export JOB_ID=10087
+RANK_ID_START=0
+
+# 数据集路径,保持为空,不需要修改
+data_path=""
+
+#基础参数,需要模型审视修改
+#网络名称,同目录名称
+Network="siamese_contrastive_ID2538_for_TensorFlow2.X"
+#训练epoch
+train_epochs=10
+#训练batch_size
+batch_size=16
+
+
+############维测参数##############
+precision_mode="allow_mix_precision"
+#维持参数,以下不需要修改
+over_dump=False
+if [[ $over_dump == True ]];then
+ over_dump_path=$cur_path/overflow_dump #此处cur_path为代码根目录
+ mkdir -p ${over_dump_path}
+fi
+data_dump_flag=False
+data_dump_step="10"
+profiling=False
+use_mixlist=True
+mixlist_file="../configs/ops_info.json"
+fusion_off_flag=False
+fusion_off_file="../configs/fusion_switch.cfg"
+############维测参数##############
+
+# 帮助信息,不需要修改
+if [[ $1 == --help || $1 == -h ]];then
+ echo"usage:./train_full_1p.sh "
+ echo " "
+ echo "parameter explain:
+ --precision_mode precision mode(allow_fp32_to_fp16/force_fp16/must_keep_origin_dtype/allow_mix_precision)
+ --over_dump if or not over detection, default is False
+ --data_dump_flag data dump flag, default is False
+ --data_dump_step data dump step, default is 10
+ --profiling if or not profiling for performance debug, default is False
+ --data_path source data of training
+ -h/--help show help message
+ "
+ exit 1
+fi
+
+
+############维测参数##############
+for para in $*
+do
+ if [[ $para == --precision_mode* ]];then
+ precision_mode=`echo ${para#*=}`
+ elif [[ $para == --over_dump* ]];then
+ over_dump=`echo ${para#*=}`
+ over_dump_path=${cur_path}/output/overflow_dump
+ mkdir -p ${over_dump_path}
+ elif [[ $para == --data_dump_flag* ]];then
+ data_dump_flag=`echo ${para#*=}`
+ data_dump_path=${cur_path}/output/data_dump
+ mkdir -p ${data_dump_path}
+ elif [[ $para == --data_dump_step* ]];then
+ data_dump_step=`echo ${para#*=}`
+ elif [[ $para == --profiling* ]];then
+ profiling=`echo ${para#*=}`
+ profiling_dump_path=${cur_path}/output/profiling
+ mkdir -p ${profiling_dump_path}
+ elif [[ $para == --data_path* ]];then
+ data_path=`echo ${para#*=}`
+ elif [[ $para == --use_mixlist* ]];then
+ use_mixlist=`echo ${para#*=}`
+ elif [[ $para == --mixlist_file* ]];then
+ mixlist_file=`echo ${para#*=}`
+ elif [[ $para == --fusion_off_flag* ]];then
+ fusion_off_flag=`echo ${para#*=}`
+ elif [[ $para == --fusion_off_file* ]];then
+ fusion_off_file=`echo ${para#*=}`
+ fi
+done
+############维测参数##############
+
+#校验是否传入data_path,不需要修改
+if [[ $data_path == "" ]];then
+ echo "[Error] para \"data_path\" must be confing"
+ exit 1
+fi
+
+#训练开始时间,不需要修改
+start_time=$(date +%s)
+
+#进入训练脚本目录,需要模型审视修改
+cd $cur_path/../
+
+for((RANK_ID=$RANK_ID_START;RANK_ID<$((RANK_SIZE+RANK_ID_START));RANK_ID++));
+do
+ #设置环境变量,不需要修改
+ echo "Device ID: $ASCEND_DEVICE_ID"
+ export RANK_ID=$RANK_ID
+
+
+
+ #创建DeviceID输出目录,不需要修改
+ if [ -d ${cur_path}/output/${ASCEND_DEVICE_ID} ];then
+ rm -rf ${cur_path}/output/${ASCEND_DEVICE_ID}
+ mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt
+ else
+ mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt
+ fi
+
+ #执行训练脚本,以下传参不需要修改,其他需要模型审视修改
+ nohup python3 siamese_contrastive.py \
+ --epochs=$train_epochs \
+ --batch_size=$batch_size \
+ --precision_mode=${precision_mode} \
+ --over_dump=${over_dump} \
+ --over_dump_path=${over_dump_path} \
+ --data_dump_flag=${data_dump_flag} \
+ --data_dump_step=${data_dump_step} \
+ --data_dump_path=${data_dump_path} \
+ --profiling=${profiling} \
+ --use_mixlist=${use_mixlist} \
+ --fusion_off_flag=${fusion_off_flag} \
+ --mixlist_file=${mixlist_file} \
+ --fusion_off_file=${fusion_off_file} \
+ --profiling_dump_path=${profiling_dump_path} > ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 &
+done
+wait
+
+#conda deactivate
+#训练结束时间,不需要修改
+end_time=$(date +%s)
+e2e_time=$(( $end_time - $start_time ))
+
+#结果打印,不需要修改
+echo "------------------ Final result ------------------"
+#输出性能FPS,需要模型审视修改
+
+# Time=`grep "ms/step" $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log| tail -n 2 | grep '3750/3750' |awk -F' ' '{print $5'| awk -F'm' '{print $1}'`
+# FPS=`awk 'BEGIN{printf "%.2f\n",'1000'*'${batch_size}'/'${Time}'}'`
+single_batch_step_sec=`grep TimeHistory $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk 'END {print $4}'`
+FPS=`awk 'BEGIN{printf "%.2f\n",'${single_batch_step_sec}'}'`
+
+#打印,不需要修改
+echo "Final Performance images/sec : $FPS"
+
+#输出训练精度,需要模型审视修改
+# train_accuracy=`grep "test acc" $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F',' '{print $3}' | awk -F']' '{print $1}'`
+train_accuracy=`cat $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log| grep val_loss | awk -F " " '{print $15}'|awk 'END {print}'`
+
+#打印,不需要修改
+echo "Final Train Accuracy : ${train_accuracy}"
+echo "E2E Training Duration sec : $e2e_time"
+
+#稳定性精度看护结果汇总
+#训练用例信息,不需要修改
+BatchSize=${batch_size}
+DeviceType=`uname -m`
+CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc'
+
+##获取性能数据
+#吞吐量,不需要修改
+ActualFPS=${FPS}
+#单迭代训练时长,不需要修改
+# TrainingTime=`awk 'BEGIN{printf "%.2f\n",'${BatchSize}'*1000/'${FPS}'}'`
+TrainingTime=`awk 'BEGIN{printf "%.2f\n",'${BatchSize}'*'${RANK_SIZE}'*1000/'${FPS}'}'`
+
+#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视
+# cat $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|tr -d '\b\r' | grep -Eo " loss: [0-9]*\.[0-9]*" | awk -F" " '{print $2}' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt
+cat $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log| grep val_loss | awk -F " " '{print $6}' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt
+
+#最后一个迭代loss值,不需要修改
+# ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt`
+ActualLoss=`awk '{print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt|tail -n 1`
+
+#关键信息打印到${CaseName}.log中,不需要修改
+echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log
diff --git a/TensorFlow2/built-in/keras_sample/siamese_contrastive_ID2538_for_TensorFlow2.X/test/train_performance_1p.sh b/TensorFlow2/built-in/keras_sample/siamese_contrastive_ID2538_for_TensorFlow2.X/test/train_performance_1p.sh
new file mode 100644
index 0000000000000000000000000000000000000000..5b830dc1c68b3f8d7e21e7215dbb528f27e42265
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/siamese_contrastive_ID2538_for_TensorFlow2.X/test/train_performance_1p.sh
@@ -0,0 +1,228 @@
+#!/bin/bash
+
+#当前路径,不需要修改
+cur_path=`pwd`
+#export ASCEND_SLOG_PRINT_TO_STDOUT=1
+
+#集合通信参数,不需要修改
+
+export RANK_SIZE=1
+export JOB_ID=10087
+RANK_ID_START=0
+
+# 数据集路径,保持为空,不需要修改
+data_path=""
+
+#基础参数,需要模型审视修改
+#网络名称,同目录名称
+Network="siamese_contrastive_ID2538_for_TensorFlow2.X"
+#训练epoch
+train_epochs=10
+#训练batch_size
+batch_size=16
+
+# #维测参数,precision_mode需要模型审视修改
+# precision_mode="allow_mix_precision"
+# #维持参数,以下不需要修改
+# over_dump=False
+# data_dump_flag=False
+# data_dump_step="10"
+# profiling=False
+# autotune=False
+
+############维测参数##############
+precision_mode="allow_mix_precision"
+#维持参数,以下不需要修改
+over_dump=False
+if [[ $over_dump == True ]];then
+ over_dump_path=$cur_path/overflow_dump #此处cur_path为代码根目录
+ mkdir -p ${over_dump_path}
+fi
+data_dump_flag=False
+data_dump_step="10"
+profiling=False
+use_mixlist=False
+mixlist_file="../configs/ops_info.json"
+fusion_off_flag=False
+fusion_off_file="../configs/fusion_switch.cfg"
+############维测参数##############
+
+# 帮助信息,不需要修改
+if [[ $1 == --help || $1 == -h ]];then
+ echo"usage:./train_performance_1p.sh "
+ echo " "
+ echo "parameter explain:
+ --precision_mode precision mode(allow_fp32_to_fp16/force_fp16/must_keep_origin_dtype/allow_mix_precision)
+ --over_dump if or not over detection, default is False
+ --data_dump_flag data dump flag, default is False
+ --data_dump_step data dump step, default is 10
+ --profiling if or not profiling for performance debug, default is False
+ --data_path source data of training
+ -h/--help show help message
+ "
+ exit 1
+fi
+
+# #参数校验,不需要修改
+# for para in $*
+# do
+# if [[ $para == --precision_mode* ]];then
+# precision_mode=`echo ${para#*=}`
+# elif [[ $para == --over_dump* ]];then
+# over_dump=`echo ${para#*=}`
+# over_dump_path=${cur_path}/output/overflow_dump
+# mkdir -p ${over_dump_path}
+# elif [[ $para == --data_dump_flag* ]];then
+# data_dump_flag=`echo ${para#*=}`
+# data_dump_path=${cur_path}/output/data_dump
+# mkdir -p ${data_dump_path}
+# elif [[ $para == --data_dump_step* ]];then
+# data_dump_step=`echo ${para#*=}`
+# elif [[ $para == --profiling* ]];then
+# profiling=`echo ${para#*=}`
+# profiling_dump_path=${cur_path}/output/profiling
+# mkdir -p ${profiling_dump_path}
+# elif [[ $para == --data_path* ]];then
+# data_path=`echo ${para#*=}`
+# fi
+# done
+
+############维测参数##############
+for para in $*
+do
+ if [[ $para == --precision_mode* ]];then
+ precision_mode=`echo ${para#*=}`
+ elif [[ $para == --over_dump* ]];then
+ over_dump=`echo ${para#*=}`
+ over_dump_path=${cur_path}/output/overflow_dump
+ mkdir -p ${over_dump_path}
+ elif [[ $para == --data_dump_flag* ]];then
+ data_dump_flag=`echo ${para#*=}`
+ data_dump_path=${cur_path}/output/data_dump
+ mkdir -p ${data_dump_path}
+ elif [[ $para == --data_dump_step* ]];then
+ data_dump_step=`echo ${para#*=}`
+ elif [[ $para == --profiling* ]];then
+ profiling=`echo ${para#*=}`
+ profiling_dump_path=${cur_path}/output/profiling
+ mkdir -p ${profiling_dump_path}
+ elif [[ $para == --data_path* ]];then
+ data_path=`echo ${para#*=}`
+ elif [[ $para == --use_mixlist* ]];then
+ use_mixlist=`echo ${para#*=}`
+ elif [[ $para == --mixlist_file* ]];then
+ mixlist_file=`echo ${para#*=}`
+ elif [[ $para == --fusion_off_flag* ]];then
+ fusion_off_flag=`echo ${para#*=}`
+ elif [[ $para == --fusion_off_file* ]];then
+ fusion_off_file=`echo ${para#*=}`
+ fi
+done
+############维测参数##############
+
+#校验是否传入data_path,不需要修改
+if [[ $data_path == "" ]];then
+ echo "[Error] para \"data_path\" must be confing"
+ exit 1
+fi
+
+cp $data_path/mnist.npz /root/.keras/datasets/
+
+#训练开始时间,不需要修改
+start_time=$(date +%s)
+
+#进入训练脚本目录,需要模型审视修改
+cd $cur_path/../
+
+for((RANK_ID=$RANK_ID_START;RANK_ID<$((RANK_SIZE+RANK_ID_START));RANK_ID++));
+do
+ #设置环境变量,不需要修改
+ echo "Device ID: $ASCEND_DEVICE_ID"
+ export RANK_ID=$RANK_ID
+
+
+
+ #创建DeviceID输出目录,不需要修改
+ if [ -d ${cur_path}/output/${ASCEND_DEVICE_ID} ];then
+ rm -rf ${cur_path}/output/${ASCEND_DEVICE_ID}
+ mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt
+ else
+ mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt
+ fi
+
+ #执行训练脚本,以下传参不需要修改,其他需要模型审视修改
+ nohup python3 siamese_contrastive.py \
+ --epochs=$train_epochs \
+ --batch_size=$batch_size \
+ --precision_mode=${precision_mode} \
+ --over_dump=${over_dump} \
+ --over_dump_path=${over_dump_path} \
+ --data_dump_flag=${data_dump_flag} \
+ --data_dump_step=${data_dump_step} \
+ --data_dump_path=${data_dump_path} \
+ --profiling=${profiling} \
+ --use_mixlist=${use_mixlist} \
+ --fusion_off_flag=${fusion_off_flag} \
+ --mixlist_file=${mixlist_file} \
+ --fusion_off_file=${fusion_off_file} \
+ --profiling_dump_path=${profiling_dump_path} > ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 &
+done
+wait
+
+#conda deactivate
+#训练结束时间,不需要修改
+end_time=$(date +%s)
+e2e_time=$(( $end_time - $start_time ))
+
+#结果打印,不需要修改
+echo "------------------ Final result ------------------"
+#输出性能FPS,需要模型审视修改
+
+# Time=`grep "ms/step" $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log| tail -n 2 | grep '3750/3750' | awk -F' ' '{print $5}' | awk -F'm' '{print $1}'`
+# FPS=`awk 'BEGIN{printf "%.2f\n",'1000'*'${batch_size}'/'${Time}'}'`
+single_batch_step_sec=`grep TimeHistory $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log| tail -n +3|awk '{sum+=$4} END {print sum/NR}'`
+FPS=`awk 'BEGIN{printf "%.2f\n",'${single_batch_step_sec}'}'`
+
+#打印,不需要修改
+echo "Final Performance images/sec : $FPS"
+
+#输出训练精度,需要模型审视修改
+# train_accuracy=`grep 'test acc' $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F',' '{print $3}' |awk -F']' '{print $1}'`
+train_accuracy=`cat $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log| grep val_loss | awk -F " " '{print $15}'|awk 'END {print}'`
+
+#打印,不需要修改
+echo "Final Train Accuracy : ${train_accuracy}"
+echo "E2E Training Duration sec : $e2e_time"
+
+#稳定性精度看护结果汇总
+#训练用例信息,不需要修改
+BatchSize=${batch_size}
+DeviceType=`uname -m`
+CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf'
+
+##获取性能数据
+#吞吐量,不需要修改
+ActualFPS=${FPS}
+#单迭代训练时长,不需要修改
+# TrainingTime=`awk 'BEGIN{printf "%.2f\n",'${BatchSize}'*1000/'${FPS}'}'`
+TrainingTime=`awk 'BEGIN{printf "%.2f\n",'${BatchSize}'*'${RANK_SIZE}'*1000/'${FPS}'}'`
+
+#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视
+# cat $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log| tr -d '\b\r' | grep -Eo " loss: [0-9]*\.[0-9]*" | awk -F" " '{print $2}'>> $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt
+cat $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log| grep val_loss | awk -F " " '{print $6}' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt
+
+#最后一个迭代loss值,不需要修改
+# ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt`
+ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt`
+
+#关键信息打印到${CaseName}.log中,不需要修改
+echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log
\ No newline at end of file
diff --git a/TensorFlow2/built-in/keras_sample/siamese_network_ID2539_for_TensorFlow2.X/LICENSE b/TensorFlow2/built-in/keras_sample/siamese_network_ID2539_for_TensorFlow2.X/LICENSE
new file mode 100644
index 0000000000000000000000000000000000000000..51d555a151df9c6c96d16137aa4bcf6142a447ef
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/siamese_network_ID2539_for_TensorFlow2.X/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2018 Ke YU
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/TensorFlow2/built-in/keras_sample/siamese_network_ID2539_for_TensorFlow2.X/README.md b/TensorFlow2/built-in/keras_sample/siamese_network_ID2539_for_TensorFlow2.X/README.md
new file mode 100644
index 0000000000000000000000000000000000000000..6fa4959ba8d13e34d26f0108b8a64c5e49d4cfed
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/siamese_network_ID2539_for_TensorFlow2.X/README.md
@@ -0,0 +1,194 @@
+- [基本信息](#基本信息.md)
+- [概述](#概述.md)
+- [训练环境准备](#训练环境准备.md)
+- [快速上手](#快速上手.md)
+- [迁移学习指导](#迁移学习指导.md)
+- [高级参考](#高级参考.md)
+基本信息
+
+**发布者(Publisher):Huawei**
+
+**应用领域(Application Domain):Image Classification**
+
+**版本(Version):1.1**
+
+**修改时间(Modified) :2022.4.11**
+
+**大小(Size):42KB**
+
+**框架(Framework):TensorFlow_2.6.2**
+
+**模型格式(Model Format):ckpt**
+
+**精度(Precision):Mixed**
+
+**处理器(Processor):昇腾910**
+
+**应用级别(Categories):Official**
+
+**描述(Description):基于TensorFlow框架的使用三元组损失函数比较图像相似性的孪生网络训练代码**
+
+概述
+
+## 简述
+
+孪生网络,是在两个或多个姐妹网络之间共享权重的神经网络,每个生成其各自输入的嵌入向量。此示例使用具有三个相同子网的连体网络。 我们将为模型提供三个图像,其中两个相似(anchor 和 positive样本),第三个将不相关(negative样本)。
+此示例使用三元组损失函数及Totally Looks Like数据集。
+
+- 参考论文:
+
+ skip
+
+- 参考实现:
+
+ https://github.com/keras-team/keras-io/blob/master/examples/vision/siamese_network.py
+
+- 适配昇腾 AI 处理器的实现:
+
+ skip
+
+- 通过Git获取对应commit\_id的代码方法如下:
+
+ git clone {repository_url} # 克隆仓库的代码
+ cd {repository_name} # 切换到模型的代码仓目录
+ git checkout {branch} # 切换到对应分支
+ git reset --hard {commit_id} # 代码设置到对应的commit_id
+ cd {code_path} # 切换到模型代码所在路径,若仓库下只有该模型,则无需切换
+
+
+## 默认配置
+
+- 网络结构:
+ - 11-layers
+ - 75168640 total params
+
+- 训练超参(单卡):
+ - Batch size: 32
+ - Train epochs: 10
+
+
+## 支持特性
+
+| 特性列表 | 是否支持 |
+| ---------- | -------- |
+| 分布式训练 | 否 |
+| 混合精度 | 是 |
+| 数据并行 | 否 |
+
+
+## 混合精度训练
+
+昇腾910 AI处理器提供自动混合精度功能,可以针对全网中float32数据类型的算子,按照内置的优化策略,自动将部分float32的算子降低精度到float16,从而在精度损失很小的情况下提升系统性能并减少内存使用。
+
+## 开启混合精度
+
+拉起脚本中,传入--precision_mode='allow_mix_precision'
+
+```
+ ./train_performance_1p_16bs.sh --help
+
+parameter explain:
+ --precision_mode precision mode(allow_fp32_to_fp16/force_fp16/must_keep_origin_dtype/allow_mix_precision)
+ --over_dump if or not over detection, default is False
+ --data_dump_flag data dump flag, default is False
+ --data_dump_step data dump step, default is 10
+ --profiling if or not profiling for performance debug, default is False
+ --data_path source data of training
+ -h/--help show help message
+```
+
+相关代码示例:
+
+```
+flags.DEFINE_string(name='precision_mode', default= 'allow_fp32_to_fp16',
+ help='allow_fp32_to_fp16/force_fp16/ '
+ 'must_keep_origin_dtype/allow_mix_precision.')
+
+npu_device.global_options().precision_mode=FLAGS.precision_mode
+```
+
+训练环境准备
+
+- 硬件环境和运行环境准备请参见《[CANN软件安装指南](https://support.huawei.com/enterprise/zh/ascend-computing/cann-pid-251168373?category=installation-update)》
+- 运行以下命令安装依赖。
+```
+pip3 install requirements.txt
+```
+说明:依赖配置文件requirements.txt文件位于模型的根目录
+
+快速上手
+
+## 数据集准备
+
+1、用户自行准备好数据集,本网络使用的数据集是Totally Looks Like数据集
+
+数据集目录参考如下:
+
+```
+├──totally_looks_like
+│ ├──left
+│ ├──model
+│ │ ├──resnet50_weights_tf_dim_ordering_tf_kernels_notop.h5
+│ ├──right
+```
+
+
+
+## 模型训练
+
+- 单击“立即下载”,并选择合适的下载方式下载源码包。
+- 开始训练。
+
+ 1. 启动训练之前,首先要配置程序运行相关环境变量。
+
+ 环境变量配置信息参见:
+
+ [Ascend 910训练平台环境变量设置](https://gitee.com/ascend/modelzoo/wikis/Ascend%20910%E8%AE%AD%E7%BB%83%E5%B9%B3%E5%8F%B0%E7%8E%AF%E5%A2%83%E5%8F%98%E9%87%8F%E8%AE%BE%E7%BD%AE?sort_id=3148819)
+
+ 2. 单卡训练
+
+ 2. 1单卡训练指令(脚本位于siamese_network_ID2539_for_TensorFlow2.X/test/train_full_1p.sh),需要先使用cd命令进入test目录下,再使用下面的命令启动训练。请确保下面例子中的“--data_path”修改为用户的数据路径,这里选择将数据文件夹放在home目录下。
+
+ bash train_full_1p.sh --data_path=/home
+
+
+
+
+高级参考
+
+## 脚本和示例代码
+
+```
+|--LICENSE
+|--README.md #说明文档
+|--siamese_network.py #训练代码
+|--requirements.txt #所需依赖
+|--test #训练脚本目录
+| |--train_full_1p.sh #全量训练脚本
+| |--train_performance_1p_dynamic.sh #performance动态shape训练脚本
+| |--train_performance_1p_static.sh #performance静态shape训练脚本
+```
+
+## 脚本参数
+
+```
+--data_path # the path to train data
+--epoch # epochs of training
+--static_shape # static_shape, default is False
+--precision_mode # the path to save over dump data
+--over_dump # if or not over detection, default is False
+--data_dump_flag # data dump flag, default is False
+--data_dump_step # data dump step, default is 10
+--profiling # if or not profiling for performance debug, default is False
+--profiling_dump_path # the path to save profiling data
+--over_dump_path # the path to save over dump data
+--data_dump_path # the path to save dump data
+--use_mixlist # use_mixlist flag, default is False
+--fusion_off_flag # fusion_off flag, default is False
+--mixlist_file # mixlist file name, default is ops_info.json
+--fusion_off_file # fusion_off file name, default is fusion_switch.cfg
+```
+
+## 训练过程
+
+通过“模型训练”中的训练指令启动单卡或者多卡训练。单卡和多卡通过运行不同脚本,支持单卡,8卡网络训练。模型存储路径为${cur_path}/output/$ASCEND_DEVICE_ID,包括训练的log以及checkpoints文件。以8卡训练为例,loss信息在文件${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log中。
\ No newline at end of file
diff --git a/TensorFlow2/built-in/keras_sample/siamese_network_ID2539_for_TensorFlow2.X/modelzoo_level.txt b/TensorFlow2/built-in/keras_sample/siamese_network_ID2539_for_TensorFlow2.X/modelzoo_level.txt
new file mode 100644
index 0000000000000000000000000000000000000000..9f9b36084b426a5f1f9683f1e10fe071230705a1
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/siamese_network_ID2539_for_TensorFlow2.X/modelzoo_level.txt
@@ -0,0 +1,3 @@
+FuncStatus:OK
+PerfStatus:PERFECT
+PrecisionStatus:OK
\ No newline at end of file
diff --git a/TensorFlow2/built-in/keras_sample/siamese_network_ID2539_for_TensorFlow2.X/requirements.txt b/TensorFlow2/built-in/keras_sample/siamese_network_ID2539_for_TensorFlow2.X/requirements.txt
new file mode 100644
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
diff --git a/TensorFlow2/built-in/keras_sample/siamese_network_ID2539_for_TensorFlow2.X/siamese_network.py b/TensorFlow2/built-in/keras_sample/siamese_network_ID2539_for_TensorFlow2.X/siamese_network.py
new file mode 100644
index 0000000000000000000000000000000000000000..752f2e1cf8f6714bec39588d72646d33b98df9fb
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/siamese_network_ID2539_for_TensorFlow2.X/siamese_network.py
@@ -0,0 +1,509 @@
+#
+# Copyright 2017 The TensorFlow Authors. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============================================================================
+# Copyright 2021 Huawei Technologies Co., Ltd
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+"""
+Title: Image similarity estimation using a Siamese Network with a triplet loss
+Authors: [Hazem Essam](https://twitter.com/hazemessamm) and [Santiago L. Valdarrama](https://twitter.com/svpino)
+Date created: 2021/03/25
+Last modified: 2021/03/25
+Description: Training a Siamese Network to compare the similarity of images using a triplet loss function.
+"""
+
+"""
+## Introduction
+
+A [Siamese Network](https://en.wikipedia.org/wiki/Siamese_neural_network) is a type of network architecture that
+contains two or more identical subnetworks used to generate feature vectors for each input and compare them.
+
+Siamese Networks can be applied to different use cases, like detecting duplicates, finding anomalies, and face recognition.
+
+This example uses a Siamese Network with three identical subnetworks. We will provide three images to the model, where
+two of them will be similar (_anchor_ and _positive_ samples), and the third will be unrelated (a _negative_ example.)
+Our goal is for the model to learn to estimate the similarity between images.
+
+For the network to learn, we use a triplet loss function. You can find an introduction to triplet loss in the
+[FaceNet paper](https://arxiv.org/pdf/1503.03832.pdf) by Schroff et al,. 2015. In this example, we define the triplet
+loss function as follows:
+
+`L(A, P, N) = max(‖f(A) - f(P)‖² - ‖f(A) - f(N)‖² + margin, 0)`
+
+This example uses the [Totally Looks Like dataset](https://sites.google.com/view/totally-looks-like-dataset)
+by [Rosenfeld et al., 2018](https://arxiv.org/pdf/1803.01485v3.pdf).
+"""
+
+"""
+## Setup
+"""
+import npu_device
+import matplotlib.pyplot as plt
+import numpy as np
+import os
+import time
+import ast
+import random
+import tensorflow as tf
+from pathlib import Path
+from tensorflow.keras import applications
+from tensorflow.keras import layers
+from tensorflow.keras import losses
+from tensorflow.keras import optimizers
+from tensorflow.keras import metrics
+from tensorflow.keras import Model
+from tensorflow.keras.applications import resnet
+import argparse
+
+#===============================NPU Migration=========================================
+def parse_args():
+ parser = argparse.ArgumentParser(
+ formatter_class=argparse.ArgumentDefaultsHelpFormatter)
+ parser.add_argument('--data_path', default="./",
+ help="""directory to data""")
+ parser.add_argument('--batch_size', default=32, type=int,
+ help="""batch size for 1p""")
+ parser.add_argument('--epochs', default=10, type=int,
+ help="""epochs""")
+ parser.add_argument('--static_shape', type=ast.literal_eval,
+ help='static_shape, default is False')
+ parser.add_argument("--log_steps", default=50, type=int,
+ help="TimeHis log Step.")
+ parser.add_argument('--precision_mode', default="allow_mix_precision", type=str,help='the path to save over dump data')
+ parser.add_argument('--over_dump', dest='over_dump', type=ast.literal_eval,
+ help='if or not over detection, default is False')
+ parser.add_argument('--data_dump_flag', dest='data_dump_flag', type=ast.literal_eval,
+ help='data dump flag, default is False')
+ parser.add_argument('--data_dump_step', default="10",
+ help='data dump step, default is 10')
+ parser.add_argument('--profiling', dest='profiling', type=ast.literal_eval,help='if or not profiling for performance debug, default is False')
+ parser.add_argument('--profiling_dump_path', default="/home/data", type=str,help='the path to save profiling data')
+ parser.add_argument('--over_dump_path', default="/home/data", type=str,help='the path to save over dump data')
+ parser.add_argument('--data_dump_path', default="/home/data", type=str,help='the path to save dump data')
+ parser.add_argument('--use_mixlist', dest='use_mixlist', type=ast.literal_eval,
+ help='use_mixlist flag, default is False')
+ parser.add_argument('--fusion_off_flag', dest='fusion_off_flag', type=ast.literal_eval,
+ help='fusion_off flag, default is False')
+ parser.add_argument('--mixlist_file', default="ops_info.json", type=str,help='mixlist file name, default is ops_info.json')
+ parser.add_argument('--fusion_off_file', default="fusion_switch.cfg", type=str,help='fusion_off file name, default is fusion_switch.cfg')
+ parser.add_argument('--auto_tune', dest='auto_tune', type=ast.literal_eval,help='auto_tune flag, default is False')
+ args, unknown_args = parser.parse_known_args()
+ if len(unknown_args) > 0:
+ for bad_arg in unknown_args:
+ print("ERROR: Unknown command line arg: %s" % bad_arg)
+ raise ValueError("Invalid command line arg(s)")
+ return args
+
+args = parse_args()
+
+def npu_config():
+ if args.data_dump_flag:
+ npu_device.global_options().dump_config.enable_dump = True
+ npu_device.global_options().dump_config.dump_path = args.data_dump_path
+ npu_device.global_options().dump_config.dump_step = args.data_dump_step
+ npu_device.global_options().dump_config.dump_mode = "all"
+
+ if args.over_dump:
+ npu_device.global_options().dump_config.enable_dump_debug = True
+ npu_device.global_options().dump_config.dump_path = args.over_dump_path
+ npu_device.global_options().dump_config.dump_debug_mode = "all"
+
+ if args.profiling:
+ npu_device.global_options().profiling_config.enable_profiling = True
+ profiling_options = '{"output":"' + args.profiling_dump_path + '", \
+ "training_trace":"on", \
+ "task_trace":"on", \
+ "aicpu":"on", \
+ "aic_metrics":"PipeUtilization",\
+ "fp_point":"", \
+ "bp_point":""}'
+ npu_device.global_options().profiling_config.profiling_options = profiling_options
+ npu_device.global_options().precision_mode = args.precision_mode
+ if args.use_mixlist and args.precision_mode=='allow_mix_precision':
+ npu_device.global_options().modify_mixlist=args.mixlist_file
+ if args.fusion_off_flag:
+ npu_device.global_options().fusion_switch_file=args.fusion_off_file
+ if args.auto_tune:
+ npu_device.global_options().auto_tune_mode="RL,GA"
+ npu_device.open().as_default()
+#===============================NPU Migration=========================================
+npu_config()
+
+target_shape = (200, 200)
+
+
+"""
+## Load the dataset
+
+We are going to load the *Totally Looks Like* dataset and unzip it inside the `~/.keras` directory
+in the local environment.
+
+The dataset consists of two separate files:
+
+* `left.zip` contains the images that we will use as the anchor.
+* `right.zip` contains the images that we will use as the positive sample (an image that looks like the anchor).
+"""
+
+cache_dir = Path(args.data_path)
+anchor_images_path = cache_dir / "left"
+positive_images_path = cache_dir / "right"
+
+"""shell
+gdown --id 1jvkbTr_giSP3Ru8OwGNCg6B4PvVbcO34
+gdown --id 1EzBZUb_mh_Dp_FKD0P4XiYYSd0QBH5zW
+unzip -oq left.zip -d $cache_dir
+unzip -oq right.zip -d $cache_dir
+"""
+
+"""
+## Preparing the data
+
+We are going to use a `tf.data` pipeline to load the data and generate the triplets that we
+need to train the Siamese network.
+
+We'll set up the pipeline using a zipped list with anchor, positive, and negative filenames as
+the source. The pipeline will load and preprocess the corresponding images.
+"""
+
+
+def preprocess_image(filename):
+ """
+ Load the specified file as a JPEG image, preprocess it and
+ resize it to the target shape.
+ """
+
+ image_string = tf.io.read_file(filename)
+ image = tf.image.decode_jpeg(image_string, channels=3)
+ image = tf.image.convert_image_dtype(image, tf.float32)
+ image = tf.image.resize(image, target_shape)
+ return image
+
+
+def preprocess_triplets(anchor, positive, negative):
+ """
+ Given the filenames corresponding to the three images, load and
+ preprocess them.
+ """
+
+ return (
+ preprocess_image(anchor),
+ preprocess_image(positive),
+ preprocess_image(negative),
+ )
+
+
+"""
+Let's setup our data pipeline using a zipped list with an anchor, positive,
+and negative image filename as the source. The output of the pipeline
+contains the same triplet with every image loaded and preprocessed.
+"""
+
+# We need to make sure both the anchor and positive images are loaded in
+# sorted order so we can match them together.
+anchor_images = sorted(
+ [str(anchor_images_path / f) for f in os.listdir(anchor_images_path)]
+)
+
+positive_images = sorted(
+ [str(positive_images_path / f) for f in os.listdir(positive_images_path)]
+)
+
+image_count = len(anchor_images)
+
+anchor_dataset = tf.data.Dataset.from_tensor_slices(anchor_images)
+positive_dataset = tf.data.Dataset.from_tensor_slices(positive_images)
+
+# To generate the list of negative images, let's randomize the list of
+# available images and concatenate them together.
+rng = np.random.RandomState(seed=42)
+rng.shuffle(anchor_images)
+rng.shuffle(positive_images)
+
+negative_images = anchor_images + positive_images
+np.random.RandomState(seed=32).shuffle(negative_images)
+
+negative_dataset = tf.data.Dataset.from_tensor_slices(negative_images)
+negative_dataset = negative_dataset.shuffle(buffer_size=4096)
+
+dataset = tf.data.Dataset.zip((anchor_dataset, positive_dataset, negative_dataset))
+dataset = dataset.shuffle(buffer_size=1024)
+dataset = dataset.map(preprocess_triplets)
+
+# Let's now split our dataset in train and validation.
+train_dataset = dataset.take(round(image_count * 0.8))
+val_dataset = dataset.skip(round(image_count * 0.8))
+
+train_dataset = train_dataset.batch(args.batch_size, drop_remainder=args.static_shape)
+train_dataset = train_dataset.prefetch(tf.data.AUTOTUNE)
+
+val_dataset = val_dataset.batch(args.batch_size, drop_remainder=args.static_shape)
+val_dataset = val_dataset.prefetch(tf.data.AUTOTUNE)
+
+
+"""
+## Setting up the embedding generator model
+
+Our Siamese Network will generate embeddings for each of the images of the
+triplet. To do this, we will use a ResNet50 model pretrained on ImageNet and
+connect a few `Dense` layers to it so we can learn to separate these
+embeddings.
+
+We will freeze the weights of all the layers of the model up until the layer `conv5_block1_out`.
+This is important to avoid affecting the weights that the model has already learned.
+We are going to leave the bottom few layers trainable, so that we can fine-tune their weights
+during training.
+"""
+
+base_cnn = resnet.ResNet50(
+ weights="imagenet", input_shape=target_shape + (3,), include_top=False
+)
+
+flatten = layers.Flatten()(base_cnn.output)
+dense1 = layers.Dense(512, activation="relu")(flatten)
+dense1 = layers.BatchNormalization()(dense1)
+dense2 = layers.Dense(256, activation="relu")(dense1)
+dense2 = layers.BatchNormalization()(dense2)
+output = layers.Dense(256)(dense2)
+
+embedding = Model(base_cnn.input, output, name="Embedding")
+
+trainable = False
+for layer in base_cnn.layers:
+ if layer.name == "conv5_block1_out":
+ trainable = True
+ layer.trainable = trainable
+
+"""
+## Setting up the Siamese Network model
+
+The Siamese network will receive each of the triplet images as an input,
+generate the embeddings, and output the distance between the anchor and the
+positive embedding, as well as the distance between the anchor and the negative
+embedding.
+
+To compute the distance, we can use a custom layer `DistanceLayer` that
+returns both values as a tuple.
+"""
+
+
+class DistanceLayer(layers.Layer):
+ """
+ This layer is responsible for computing the distance between the anchor
+ embedding and the positive embedding, and the anchor embedding and the
+ negative embedding.
+ """
+
+ def __init__(self, **kwargs):
+ super().__init__(**kwargs)
+
+ def call(self, anchor, positive, negative):
+ ap_distance = tf.reduce_sum(tf.square(anchor - positive), -1)
+ an_distance = tf.reduce_sum(tf.square(anchor - negative), -1)
+ return (ap_distance, an_distance)
+
+
+anchor_input = layers.Input(name="anchor", shape=target_shape + (3,))
+positive_input = layers.Input(name="positive", shape=target_shape + (3,))
+negative_input = layers.Input(name="negative", shape=target_shape + (3,))
+
+distances = DistanceLayer()(
+ embedding(resnet.preprocess_input(anchor_input)),
+ embedding(resnet.preprocess_input(positive_input)),
+ embedding(resnet.preprocess_input(negative_input)),
+)
+
+siamese_network = Model(
+ inputs=[anchor_input, positive_input, negative_input], outputs=distances
+)
+
+"""
+## Putting everything together
+
+We now need to implement a model with custom training loop so we can compute
+the triplet loss using the three embeddings produced by the Siamese network.
+
+Let's create a `Mean` metric instance to track the loss of the training process.
+"""
+
+
+class SiameseModel(Model):
+ """The Siamese Network model with a custom training and testing loops.
+
+ Computes the triplet loss using the three embeddings produced by the
+ Siamese Network.
+
+ The triplet loss is defined as:
+ L(A, P, N) = max(‖f(A) - f(P)‖² - ‖f(A) - f(N)‖² + margin, 0)
+ """
+
+ def __init__(self, siamese_network, margin=0.5):
+ super(SiameseModel, self).__init__()
+ self.siamese_network = siamese_network
+ self.margin = margin
+ self.loss_tracker = metrics.Mean(name="loss")
+
+ def call(self, inputs):
+ return self.siamese_network(inputs)
+
+ def train_step(self, data):
+ # GradientTape is a context manager that records every operation that
+ # you do inside. We are using it here to compute the loss so we can get
+ # the gradients and apply them using the optimizer specified in
+ # `compile()`.
+ with tf.GradientTape() as tape:
+ loss = self._compute_loss(data)
+
+ # Storing the gradients of the loss function with respect to the
+ # weights/parameters.
+ gradients = tape.gradient(loss, self.siamese_network.trainable_weights)
+
+ # Applying the gradients on the model using the specified optimizer
+ self.optimizer.apply_gradients(
+ zip(gradients, self.siamese_network.trainable_weights)
+ )
+
+ # Let's update and return the training loss metric.
+ self.loss_tracker.update_state(loss)
+ return {"loss": self.loss_tracker.result()}
+
+ def test_step(self, data):
+ loss = self._compute_loss(data)
+
+ # Let's update and return the loss metric.
+ self.loss_tracker.update_state(loss)
+ return {"loss": self.loss_tracker.result()}
+
+ def _compute_loss(self, data):
+ # The output of the network is a tuple containing the distances
+ # between the anchor and the positive example, and the anchor and
+ # the negative example.
+ ap_distance, an_distance = self.siamese_network(data)
+
+ # Computing the Triplet Loss by subtracting both distances and
+ # making sure we don't get a negative value.
+ loss = ap_distance - an_distance
+ loss = tf.maximum(loss + self.margin, 0.0)
+ return loss
+
+ @property
+ def metrics(self):
+ # We need to list our metrics here so the `reset_states()` can be
+ # called automatically.
+ return [self.loss_tracker]
+
+
+"""
+## Training
+
+We are now ready to train our model.
+"""
+class TimeHistory(tf.keras.callbacks.Callback):
+ def __init__(self, batch_size, log_steps, initial_step=0):
+ self.batch_size = batch_size
+ super(TimeHistory, self).__init__()
+ self.steps_before_epoch = initial_step
+ self.last_log_step = initial_step
+ self.log_steps = log_steps
+ self.steps_in_epoch = 0
+ #self.opt = optimizer
+ self.start_time = None
+
+ @property
+ def global_steps(self):
+ """The current 1-indexed global step."""
+ return self.steps_before_epoch + self.steps_in_epoch
+
+ def on_epoch_begin(self, epoch, logs=None):
+ if not self.start_time:
+ self.start_time = time.time()
+ self.epoch_start = time.time()
+
+ def on_batch_begin(self, batch, logs=None):
+ if not self.start_time:
+ self.start_time = time.time()
+
+ def on_batch_end(self, batch, logs=None):
+ self.steps_in_epoch = batch + 1
+ steps_since_last_log = self.global_steps - self.last_log_step
+ if steps_since_last_log >= self.log_steps:
+ now = time.time()
+ elapsed_time = now - self.start_time
+ steps_per_second = steps_since_last_log / elapsed_time
+ examples_per_second = steps_per_second * self.batch_size
+ print(
+ 'TimeHistory: %.2f seconds, %.2f examples/second between steps %d '
+ 'and %d'%(elapsed_time, examples_per_second, self.last_log_step,
+ self.global_steps),flush=True)
+ self.last_log_step = self.global_steps
+ self.start_time = None
+
+ def on_epoch_end(self, epoch, logs=None):
+ epoch_run_time = time.time() - self.epoch_start
+ self.steps_before_epoch += self.steps_in_epoch
+ self.steps_in_epoch = 0
+
+siamese_model = SiameseModel(siamese_network)
+siamese_model.compile(optimizer=optimizers.Adam(0.0001))
+siamese_model.fit(train_dataset, epochs=args.epochs, validation_data=val_dataset, callbacks=[TimeHistory(args.batch_size,args.log_steps)], verbose=2)
+"""
+## Inspecting what the network has learned
+
+At this point, we can check how the network learned to separate the embeddings
+depending on whether they belong to similar images.
+
+We can use [cosine similarity](https://en.wikipedia.org/wiki/Cosine_similarity) to measure the
+similarity between embeddings.
+
+"""
+
+"""
+## Summary
+
+1. The `tf.data` API enables you to build efficient input pipelines for your model. It is
+particularly useful if you have a large dataset. You can learn more about `tf.data`
+pipelines in [tf.data: Build TensorFlow input pipelines](https://www.tensorflow.org/guide/data).
+
+2. In this example, we use a pre-trained ResNet50 as part of the subnetwork that generates
+the feature embeddings. By using [transfer learning](https://www.tensorflow.org/guide/keras/transfer_learning?hl=en),
+we can significantly reduce the training time and size of the dataset.
+
+3. Notice how we are [fine-tuning](https://www.tensorflow.org/guide/keras/transfer_learning?hl=en#fine-tuning)
+the weights of the final layers of the ResNet50 network but keeping the rest of the layers untouched.
+Using the name assigned to each layer, we can freeze the weights to a certain point and keep the last few layers open.
+
+4. We can create custom layers by creating a class that inherits from `tf.keras.layers.Layer`,
+as we did in the `DistanceLayer` class.
+
+5. We used a cosine similarity metric to measure how to 2 output embeddings are similar to each other.
+
+6. You can implement a custom training loop by overriding the `train_step()` method. `train_step()` uses
+[`tf.GradientTape`](https://www.tensorflow.org/api_docs/python/tf/GradientTape),
+which records every operation that you perform inside it. In this example, we use it to access the
+gradients passed to the optimizer to update the model weights at every step. For more details, check out the
+[Intro to Keras for researchers](https://keras.io/getting_started/intro_to_keras_for_researchers/)
+and [Writing a training loop from scratch](https://www.tensorflow.org/guide/keras/writing_a_training_loop_from_scratch?hl=en).
+
+"""
diff --git a/TensorFlow2/built-in/keras_sample/siamese_network_ID2539_for_TensorFlow2.X/test/train_full_1p.sh b/TensorFlow2/built-in/keras_sample/siamese_network_ID2539_for_TensorFlow2.X/test/train_full_1p.sh
new file mode 100644
index 0000000000000000000000000000000000000000..8fcd570aa65f53643a091219312358534860a56a
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/siamese_network_ID2539_for_TensorFlow2.X/test/train_full_1p.sh
@@ -0,0 +1,164 @@
+#!/bin/bash
+cur_path=`pwd`/../
+
+#基础参数,需要模型审视修改
+#Batch Size
+batch_size=32
+#网络名称,同目录名称
+Network="siamese_network_ID2539_for_TensorFlow2.X"
+#Device数量,单卡默认为1
+RankSize=1
+#训练epoch,可选
+train_epochs=10
+#训练step
+#train_steps=5
+#学习率
+#learning_rate=1e-4
+#ckpt_path=""
+#参数配置
+data_path=""
+
+############维测参数##############
+precision_mode="allow_mix_precision"
+#维持参数,以下不需要修改
+over_dump=False
+if [[ $over_dump == True ]];then
+ over_dump_path=$cur_path/test/overflow_dump #此处cur_path为代码根目录
+ mkdir -p ${over_dump_path}
+fi
+data_dump_flag=False
+data_dump_step="10"
+profiling=False
+use_mixlist=False
+mixlist_file="./configs/ops_info.json"
+fusion_off_flag=False
+fusion_off_file="./configs/fusion_switch.cfg"
+auto_tune=False
+############维测参数##############
+
+if [[ $1 == --help || $1 == --h ]];then
+ echo "usage: ./train_performance_1p_static_eval.sh"
+ exit 1
+fi
+
+for para in $*
+do
+ if [[ $para == --data_path* ]];then
+ data_path=`echo ${para#*=}`
+ elif [[ $para == --precision_mode* ]];then
+ precision_mode=`echo ${para#*=}`
+ elif [[ $para == --over_dump* ]];then
+ over_dump=`echo ${para#*=}`
+ over_dump_path=${cur_path}/output/overflow_dump
+ mkdir -p ${over_dump_path}
+ elif [[ $para == --data_dump_flag* ]];then
+ data_dump_flag=`echo ${para#*=}`
+ data_dump_path=${cur_path}/output/data_dump
+ mkdir -p ${data_dump_path}
+ elif [[ $para == --data_dump_step* ]];then
+ data_dump_step=`echo ${para#*=}`
+ elif [[ $para == --profiling* ]];then
+ profiling=`echo ${para#*=}`
+ profiling_dump_path=${cur_path}/output/profiling
+ mkdir -p ${profiling_dump_path}
+ elif [[ $para == --data_path* ]];then
+ data_path=`echo ${para#*=}`
+ elif [[ $para == --use_mixlist* ]];then
+ use_mixlist=`echo ${para#*=}`
+ elif [[ $para == --mixlist_file* ]];then
+ mixlist_file=`echo ${para#*=}`
+ elif [[ $para == --fusion_off_flag* ]];then
+ fusion_off_flag=`echo ${para#*=}`
+ elif [[ $para == --fusion_off_file* ]];then
+ fusion_off_file=`echo ${para#*=}`
+ elif [[ $para == --auto_tune* ]];then
+ auto_tune=`echo ${para#*=}`
+ fi
+done
+
+if [[ $data_path == "" ]];then
+ echo "[Error] para \"data_path \" must be config"
+ exit 1
+fi
+
+cd $cur_path/
+cp $data_path/model/resnet50_weights_tf_dim_ordering_tf_kernels_notop.h5 /root/.keras/models
+
+##############执行训练##########
+if [ -d $cur_path/test/output ];then
+ rm -rf $cur_path/test/output/*
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+else
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+fi
+wait
+
+start=$(date +%s)
+nohup python3 siamese_network.py \
+ --data_path=$data_path \
+ --epochs=$train_epochs \
+ --batch_size=$batch_size \
+ --static_shape=True \
+ --precision_mode=${precision_mode} \
+ --over_dump=${over_dump} \
+ --over_dump_path=${over_dump_path} \
+ --data_dump_flag=${data_dump_flag} \
+ --data_dump_step=${data_dump_step} \
+ --data_dump_path=${data_dump_path} \
+ --profiling=${profiling} \
+ --use_mixlist=${use_mixlist} \
+ --fusion_off_flag=${fusion_off_flag} \
+ --mixlist_file=${mixlist_file} \
+ --fusion_off_file=${fusion_off_file} \
+ --auto_tune=${auto_tune} \
+ --profiling_dump_path=${profiling_dump_path} > $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 &
+wait
+end=$(date +%s)
+e2e_time=$(( $end - $start ))
+
+echo "Final Training Duration sec : $e2e_time"
+
+#echo "Final Performance ms/step : $average_perf"#结果打印,不需要修改
+echo "------------------ Final result ------------------"
+#输出性能FPS,需要模型审视修改
+single_batch_step_sec=`grep TimeHistory $cur_path/test/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk 'END {print $4}'`
+FPS=`awk 'BEGIN{printf "%.2f\n",'${single_batch_step_sec}'}'`
+wait
+
+#打印,不需要修改
+echo "Final Performance images/sec : $FPS"
+
+#输出训练精度,需要模型审视修改
+train_accuracy='None'
+#打印,不需要修改
+echo "Final Train Accuracy : ${train_accuracy}"
+
+
+#精度看护结果汇总
+#训练用例信息,不需要修改
+BatchSize=${batch_size}
+DeviceType=`uname -m`
+CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc'
+
+##获取性能数据,不需要修改
+#吞吐量
+ActualFPS=${FPS}
+#单迭代训练时长
+TrainingTime=`awk 'BEGIN{printf "%.2f\n",'${BatchSize}'*'${RANK_SIZE}'*1000/'${FPS}'}'`
+
+#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视
+cat $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log| grep val_loss | awk -F " " '{print $6}' > $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt
+#最后一个迭代loss值,不需要修改
+ActualLoss=`awk 'END {print $1}' $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt`
+
+#关键信息打印到${CaseName}.log中,不需要修改
+echo "Network = ${Network}" > $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "RankSize = ${RANK_SIZE}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "BatchSize = ${BatchSize}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "DeviceType = ${DeviceType}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "CaseName = ${CaseName}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualFPS = ${ActualFPS}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainingTime = ${TrainingTime}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainAccuracy = ${ActualLoss}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualLoss = ${ActualLoss}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
diff --git a/TensorFlow2/built-in/keras_sample/siamese_network_ID2539_for_TensorFlow2.X/test/train_performance_1p_dynamic.sh b/TensorFlow2/built-in/keras_sample/siamese_network_ID2539_for_TensorFlow2.X/test/train_performance_1p_dynamic.sh
new file mode 100644
index 0000000000000000000000000000000000000000..bb1ecd386bdcfa811635c11bc4efa85f945e47e0
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/siamese_network_ID2539_for_TensorFlow2.X/test/train_performance_1p_dynamic.sh
@@ -0,0 +1,162 @@
+#!/bin/bash
+cur_path=`pwd`/../
+
+#基础参数,需要模型审视修改
+#Batch Size
+batch_size=32
+#网络名称,同目录名称
+Network="siamese_network_ID2539_for_TensorFlow2.X"
+#Device数量,单卡默认为1
+RankSize=1
+#训练epoch,可选
+train_epochs=2
+#训练step
+#train_steps=5
+#学习率
+#learning_rate=1e-4
+#ckpt_path=""
+#参数配置
+data_path=""
+
+############维测参数##############
+precision_mode="allow_mix_precision"
+#维持参数,以下不需要修改
+over_dump=False
+if [[ $over_dump == True ]];then
+ over_dump_path=$cur_path/test/overflow_dump #此处cur_path为代码根目录
+ mkdir -p ${over_dump_path}
+fi
+data_dump_flag=False
+data_dump_step="10"
+profiling=False
+use_mixlist=False
+mixlist_file="./configs/ops_info.json"
+fusion_off_flag=False
+fusion_off_file="./configs/fusion_switch.cfg"
+auto_tune=False
+############维测参数##############
+
+if [[ $1 == --help || $1 == --h ]];then
+ echo "usage: ./train_performance_1p_static_eval.sh"
+ exit 1
+fi
+
+for para in $*
+do
+ if [[ $para == --data_path* ]];then
+ data_path=`echo ${para#*=}`
+ elif [[ $para == --precision_mode* ]];then
+ precision_mode=`echo ${para#*=}`
+ elif [[ $para == --over_dump* ]];then
+ over_dump=`echo ${para#*=}`
+ over_dump_path=${cur_path}/output/overflow_dump
+ mkdir -p ${over_dump_path}
+ elif [[ $para == --data_dump_flag* ]];then
+ data_dump_flag=`echo ${para#*=}`
+ data_dump_path=${cur_path}/output/data_dump
+ mkdir -p ${data_dump_path}
+ elif [[ $para == --data_dump_step* ]];then
+ data_dump_step=`echo ${para#*=}`
+ elif [[ $para == --profiling* ]];then
+ profiling=`echo ${para#*=}`
+ profiling_dump_path=${cur_path}/output/profiling
+ mkdir -p ${profiling_dump_path}
+ elif [[ $para == --data_path* ]];then
+ data_path=`echo ${para#*=}`
+ elif [[ $para == --use_mixlist* ]];then
+ use_mixlist=`echo ${para#*=}`
+ elif [[ $para == --mixlist_file* ]];then
+ mixlist_file=`echo ${para#*=}`
+ elif [[ $para == --fusion_off_flag* ]];then
+ fusion_off_flag=`echo ${para#*=}`
+ elif [[ $para == --fusion_off_file* ]];then
+ fusion_off_file=`echo ${para#*=}`
+ elif [[ $para == --auto_tune* ]];then
+ auto_tune=`echo ${para#*=}`
+ fi
+done
+
+if [[ $data_path == "" ]];then
+ echo "[Error] para \"data_path \" must be config"
+ exit 1
+fi
+
+cd $cur_path/
+
+##############执行训练##########
+if [ -d $cur_path/test/output ];then
+ rm -rf $cur_path/test/output/*
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+else
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+fi
+wait
+
+start=$(date +%s)
+nohup python3 siamese_network.py \
+ --data_path=$data_path \
+ --epochs=$train_epochs \
+ --batch_size=$batch_size \
+ --static_shape=False \
+ --precision_mode=${precision_mode} \
+ --over_dump=${over_dump} \
+ --over_dump_path=${over_dump_path} \
+ --data_dump_flag=${data_dump_flag} \
+ --data_dump_step=${data_dump_step} \
+ --data_dump_path=${data_dump_path} \
+ --profiling=${profiling} \
+ --use_mixlist=${use_mixlist} \
+ --fusion_off_flag=${fusion_off_flag} \
+ --mixlist_file=${mixlist_file} \
+ --fusion_off_file=${fusion_off_file} \
+ --auto_tune=${auto_tune} \
+ --profiling_dump_path=${profiling_dump_path} > $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 &
+wait
+end=$(date +%s)
+e2e_time=$(( $end - $start ))
+
+echo "Final Training Duration sec : $e2e_time"
+#echo "Final Performance ms/step : $average_perf"#结果打印,不需要修改
+echo "------------------ Final result ------------------"
+#输出性能FPS,需要模型审视修改
+single_batch_step_sec=`grep TimeHistory $cur_path/test/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk 'END {print $4}'`
+FPS=`awk 'BEGIN{printf "%.2f\n",'${single_batch_step_sec}'}'`
+wait
+
+#打印,不需要修改
+echo "Final Performance images/sec : $FPS"
+
+#输出训练精度,需要模型审视修改
+train_accuracy='None'
+#打印,不需要修改
+echo "Final Train Accuracy : ${train_accuracy}"
+
+
+#精度看护结果汇总
+#训练用例信息,不需要修改
+BatchSize=${batch_size}
+DeviceType=`uname -m`
+CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf'
+
+##获取性能数据,不需要修改
+#吞吐量
+ActualFPS=${FPS}
+#单迭代训练时长
+TrainingTime=`awk 'BEGIN{printf "%.2f\n",'${BatchSize}'*'${RANK_SIZE}'*1000/'${FPS}'}'`
+
+#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视
+cat $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log| grep val_loss | awk -F " " '{print $6}' > $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt
+#最后一个迭代loss值,不需要修改
+ActualLoss=`awk 'END {print $1}' $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt`
+
+#关键信息打印到${CaseName}.log中,不需要修改
+echo "Network = ${Network}" > $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "RankSize = ${RANK_SIZE}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "BatchSize = ${BatchSize}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "DeviceType = ${DeviceType}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "CaseName = ${CaseName}_static" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualFPS = ${ActualFPS}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainingTime = ${TrainingTime}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainAccuracy = ${ActualLoss}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualLoss = ${ActualLoss}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
diff --git a/TensorFlow2/built-in/keras_sample/siamese_network_ID2539_for_TensorFlow2.X/test/train_performance_1p_static.sh b/TensorFlow2/built-in/keras_sample/siamese_network_ID2539_for_TensorFlow2.X/test/train_performance_1p_static.sh
new file mode 100644
index 0000000000000000000000000000000000000000..2bb2f4f64a16644faeb9dcaab869b360915b7c66
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/siamese_network_ID2539_for_TensorFlow2.X/test/train_performance_1p_static.sh
@@ -0,0 +1,165 @@
+#!/bin/bash
+cur_path=`pwd`/../
+
+#基础参数,需要模型审视修改
+#Batch Size
+batch_size=32
+#网络名称,同目录名称
+Network="siamese_network_ID2539_for_TensorFlow2.X"
+#Device数量,单卡默认为1
+RankSize=1
+RANK_SIZE=1
+#训练epoch,可选
+train_epochs=2
+#训练step
+#train_steps=5
+#学习率
+#learning_rate=1e-4
+#ckpt_path=""
+#参数配置
+data_path=""
+
+############维测参数##############
+precision_mode="allow_mix_precision"
+#维持参数,以下不需要修改
+over_dump=False
+if [[ $over_dump == True ]];then
+ over_dump_path=$cur_path/test/overflow_dump #此处cur_path为代码根目录
+ mkdir -p ${over_dump_path}
+fi
+data_dump_flag=False
+data_dump_step="10"
+profiling=False
+use_mixlist=False
+mixlist_file="./configs/ops_info.json"
+fusion_off_flag=False
+fusion_off_file="./configs/fusion_switch.cfg"
+auto_tune=False
+############维测参数##############
+
+if [[ $1 == --help || $1 == --h ]];then
+ echo "usage: ./train_performance_1p_static_eval.sh"
+ exit 1
+fi
+
+for para in $*
+do
+ if [[ $para == --data_path* ]];then
+ data_path=`echo ${para#*=}`
+ elif [[ $para == --precision_mode* ]];then
+ precision_mode=`echo ${para#*=}`
+ elif [[ $para == --over_dump* ]];then
+ over_dump=`echo ${para#*=}`
+ over_dump_path=${cur_path}/output/overflow_dump
+ mkdir -p ${over_dump_path}
+ elif [[ $para == --data_dump_flag* ]];then
+ data_dump_flag=`echo ${para#*=}`
+ data_dump_path=${cur_path}/output/data_dump
+ mkdir -p ${data_dump_path}
+ elif [[ $para == --data_dump_step* ]];then
+ data_dump_step=`echo ${para#*=}`
+ elif [[ $para == --profiling* ]];then
+ profiling=`echo ${para#*=}`
+ profiling_dump_path=${cur_path}/output/profiling
+ mkdir -p ${profiling_dump_path}
+ elif [[ $para == --data_path* ]];then
+ data_path=`echo ${para#*=}`
+ elif [[ $para == --use_mixlist* ]];then
+ use_mixlist=`echo ${para#*=}`
+ elif [[ $para == --mixlist_file* ]];then
+ mixlist_file=`echo ${para#*=}`
+ elif [[ $para == --fusion_off_flag* ]];then
+ fusion_off_flag=`echo ${para#*=}`
+ elif [[ $para == --fusion_off_file* ]];then
+ fusion_off_file=`echo ${para#*=}`
+ elif [[ $para == --auto_tune* ]];then
+ auto_tune=`echo ${para#*=}`
+ fi
+done
+
+if [[ $data_path == "" ]];then
+ echo "[Error] para \"data_path \" must be config"
+ exit 1
+fi
+
+cd $cur_path/
+cp $data_path/model/resnet50_weights_tf_dim_ordering_tf_kernels_notop.h5 /root/.keras/models
+
+##############执行训练##########
+if [ -d $cur_path/test/output ];then
+ rm -rf $cur_path/test/output/*
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+else
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+fi
+wait
+
+start=$(date +%s)
+nohup python3 siamese_network.py \
+ --data_path=$data_path \
+ --epochs=$train_epochs \
+ --batch_size=$batch_size \
+ --static_shape=True \
+ --precision_mode=${precision_mode} \
+ --over_dump=${over_dump} \
+ --over_dump_path=${over_dump_path} \
+ --data_dump_flag=${data_dump_flag} \
+ --data_dump_step=${data_dump_step} \
+ --data_dump_path=${data_dump_path} \
+ --profiling=${profiling} \
+ --use_mixlist=${use_mixlist} \
+ --fusion_off_flag=${fusion_off_flag} \
+ --mixlist_file=${mixlist_file} \
+ --fusion_off_file=${fusion_off_file} \
+ --auto_tune=${auto_tune} \
+ --profiling_dump_path=${profiling_dump_path} > $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 &
+wait
+end=$(date +%s)
+e2e_time=$(( $end - $start ))
+
+echo "Final Training Duration sec : $e2e_time"
+
+#echo "Final Performance ms/step : $average_perf"#结果打印,不需要修改
+echo "------------------ Final result ------------------"
+#输出性能FPS,需要模型审视修改
+single_batch_step_sec=`grep TimeHistory $cur_path/test/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk 'END {print $4}'`
+FPS=`awk 'BEGIN{printf "%.2f\n",'${single_batch_step_sec}'}'`
+wait
+
+#打印,不需要修改
+echo "Final Performance images/sec : $FPS"
+
+#输出训练精度,需要模型审视修改
+train_accuracy='None'
+#打印,不需要修改
+echo "Final Train Accuracy : ${train_accuracy}"
+
+
+#精度看护结果汇总
+#训练用例信息,不需要修改
+BatchSize=${batch_size}
+DeviceType=`uname -m`
+CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf'
+
+##获取性能数据,不需要修改
+#吞吐量
+ActualFPS=${FPS}
+#单迭代训练时长
+TrainingTime=`awk 'BEGIN{printf "%.2f\n",'${BatchSize}'*'${RANK_SIZE}'*1000/'${FPS}'}'`
+
+#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视
+cat $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log| grep val_loss | awk -F " " '{print $6}' > $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt
+#最后一个迭代loss值,不需要修改
+ActualLoss=`awk 'END {print $1}' $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt`
+
+#关键信息打印到${CaseName}.log中,不需要修改
+echo "Network = ${Network}" > $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "RankSize = ${RANK_SIZE}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "BatchSize = ${BatchSize}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "DeviceType = ${DeviceType}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "CaseName = ${CaseName}_static" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualFPS = ${ActualFPS}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainingTime = ${TrainingTime}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainAccuracy = ${ActualLoss}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualLoss = ${ActualLoss}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
diff --git a/TensorFlow2/built-in/keras_sample/subclassing_conv_layers_ID2615_for_TensorFlow2.X/LICENSE b/TensorFlow2/built-in/keras_sample/subclassing_conv_layers_ID2615_for_TensorFlow2.X/LICENSE
new file mode 100644
index 0000000000000000000000000000000000000000..261eeb9e9f8b2b4b0d119366dda99c6fd7d35c64
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/subclassing_conv_layers_ID2615_for_TensorFlow2.X/LICENSE
@@ -0,0 +1,201 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/TensorFlow2/built-in/keras_sample/subclassing_conv_layers_ID2615_for_TensorFlow2.X/README.md b/TensorFlow2/built-in/keras_sample/subclassing_conv_layers_ID2615_for_TensorFlow2.X/README.md
new file mode 100644
index 0000000000000000000000000000000000000000..2f83b0d67cad997c4f370a8c3aeb94e028485d08
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/subclassing_conv_layers_ID2615_for_TensorFlow2.X/README.md
@@ -0,0 +1,203 @@
+- [基本信息](#基本信息.md)
+- [概述](#概述.md)
+- [训练环境准备](#训练环境准备.md)
+- [快速上手](#快速上手.md)
+- [迁移学习指导](#迁移学习指导.md)
+- [高级参考](#高级参考.md)
+
+基本信息
+
+**发布者(Publisher):Huawei**
+
+**应用领域(Application Domain):Object Detection**
+
+**版本(Version):1.1**
+
+**修改时间(Modified) :2022.04.08**
+
+**大小(Size):458K**
+
+**框架(Framework):TensorFlow_2.6.2**
+
+**模型格式(Model Format):h5**
+
+**精度(Precision):Mixed**
+
+**处理器(Processor):昇腾910**
+
+**应用级别(Categories):Research**
+
+**描述(Description):基于TensorFlow2.X框架的图像检测训练代码**
+
+
+概述
+
+## 简述
+
+ subclassing_conv_layers网络展示了如何使用Conv.convolution_op()的API实现自定义卷积层,可以重用大部分基础卷积层,只需通过该方法自定义卷积操作本身。而使用 API 的“StandardizedConvolution”实现非常简洁,仅包含四行代码。
+
+ - 参考论文:
+
+ https://arxiv.org/abs/1903.10520(https://arxiv.org/abs/1903.10520)
+
+ - 参考实现:
+ https://github.com/keras-team/keras-io/blob/master/examples/keras_recipes/subclassing_conv_layers.py(https://github.com/keras-team/keras-io/blob/master/examples/keras_recipes/subclassing_conv_layers.py)
+
+
+ - 适配昇腾 AI 处理器的实现:
+ skip
+
+ - 通过Git获取对应commit\_id的代码方法如下::
+ ```
+ git clone {repository_url} # 克隆仓库的代码
+ cd {repository_name} # 切换到模型的代码仓目录
+ git checkout {branch} # 切换到对应分支
+ git reset --hard {commit_id} # 代码设置到对应的commit_id
+ cd {code_path} # 切换到模型代码所在路径,若仓库下只有该模型,则无需切换
+ ```
+
+
+
+
+## 默认配置
+
+
+- 网络结构
+ - 使用Conv.convolution_op()自定义卷积网络
+ - 训练参数个数:34,826
+
+
+- 训练超参(单卡):
+ - Batch size: 256
+ - num_classes:10
+ - input_shape: [28,28,1]
+ - Train epoch: 5
+
+
+## 支持特性
+
+| 特性列表 | 是否支持 |
+|-------|------|
+| 分布式训练 | 否 |
+| 混合精度 | 是 |
+| 数据并行 | 否 |
+
+## 混合精度训练
+
+昇腾910 AI处理器提供自动混合精度功能,可以针对全网中float32数据类型的算子,按照内置的优化策略,自动将部分float32的算子降低精度到float16,从而在精度损失很小的情况下提升系统性能并减少内存使用。
+
+## 开启混合精度
+相关代码示例。
+
+```
+config_proto = tf.ConfigProto(allow_soft_placement=True)
+ custom_op = config_proto.graph_options.rewrite_options.custom_optimizers.add()
+ custom_op.name = 'NpuOptimizer'
+ custom_op.parameter_map["use_off_line"].b = True
+ custom_op.parameter_map["precision_mode"].s = tf.compat.as_bytes("allow_mix_precision")
+ config_proto.graph_options.rewrite_options.remapping = RewriterConfig.OFF
+ session_config = npu_config_proto(config_proto=config_proto)
+```
+
+训练环境准备
+
+- 硬件环境和运行环境准备请参见《[CANN软件安装指南](https://support.huawei.com/enterprise/zh/ascend-computing/cann-pid-251168373?category=installation-update)》
+- 运行以下命令安装依赖。
+```
+pip3 install requirements.txt
+```
+说明:依赖配置文件requirements.txt文件位于模型的根目录
+
+
+快速上手
+
+## 数据集准备
+
+1. 模型训练使用mnist数据集,数据集请用户自行获取。
+2. 数据集下载完毕后,请用户使用keras.datasets.mnist.load_data()直接读取数据。
+
+## 模型训练
+- 单击“立即下载”,并选择合适的下载方式下载源码包。
+- 开始训练。
+
+ 1. 启动训练之前,首先要配置程序运行相关环境变量。
+
+ 环境变量配置信息参见:
+
+ [Ascend 910训练平台环境变量设置](https://gitee.com/ascend/modelzoo/wikis/Ascend%20910%E8%AE%AD%E7%BB%83%E5%B9%B3%E5%8F%B0%E7%8E%AF%E5%A2%83%E5%8F%98%E9%87%8F%E8%AE%BE%E7%BD%AE?sort_id=3148819)
+
+
+ 2. 单卡训练
+
+ 2.1 设置单卡训练参数(脚本位于subclassing_conv_layers_ID2615_for_TensorFlow2.X/test/train_full_1p.sh),示例如下。
+
+
+ ```
+ batch_size=256
+ #训练step
+ train_epochs=5
+ #学习率
+ learning_rate=0.001
+ ```
+
+
+
+ 2.2 单卡训练指令(subclassing_conv_layers_ID2615_for_TensorFlow2.X/test)
+
+ ```
+ 于终端中运行export ASCEND_DEVICE_ID=0 (0~7)以指定单卡训练时使用的卡
+ bash train_full_1p.sh --data_path=xx
+ 数据集应为npz类型(数据切分可能不同),配置data_path时需指定为data这一层,例:--data_path=/home/data
+ ├─data
+ ├─mnist_npz
+
+ ```
+
+迁移学习指导
+
+- 数据集准备。
+
+ 1. 获取数据。
+ 请参见“快速上手”中的数据集准备
+
+- 模型训练
+
+ 请参考“快速上手”章节
+
+高级参考
+
+## 脚本和示例代码
+
+ ├── README.md //说明文档
+ ├── requirements.txt //依赖
+ ├── modelzoo_level.txt //状态文件
+ ├── subclassing_conv_layers.py //网络结构定义脚本
+ ├── test
+ | |—— train_full_1p.sh //单卡训练脚本
+ | |—— train_performance_1p.sh //单卡训练脚本
+
+## 脚本参数
+
+```
+batch_size 训练batch_size
+learning_rate 初始学习率
+train_epochs 总训练epoch数
+precision_mode default="allow_mix_precision", type=str,help='the path to save over dump data'
+over_dump type=ast.literal_eval,help='if or not over detection, default is False'
+data_dump_flag type=ast.literal_eval,help='data dump flag, default is False'
+data_dump_step data dump step, default is 10
+profiling type=ast.literal_eval help='if or not profiling for performance debug, default is False'
+profiling_dump_path type=str, help='the path to save profiling data'
+over_dump_path type=str, help='the path to save over dump data'
+data_dump_path type=str, help='the path to save dump data'
+use_mixlist type=ast.literal_eval,help='use_mixlist flag, default is False'
+fusion_off_flag type=ast.literal_eval,help='fusion_off flag, default is False'
+mixlist_file type=str,help='mixlist file name, default is ops_info.json'
+fusion_off_file type=str,help='fusion_off file name, default is fusion_switch.cfg'
+auto_tune help='auto_tune flag, default is False'
+```
+
+## 训练过程
+
+通过“模型训练”中的训练指令启动单卡训练。
+将训练脚本(train_full_1p.sh)中的data_path设置为训练数据集的路径。具体的流程参见“模型训练”的示例。
diff --git a/TensorFlow2/built-in/keras_sample/subclassing_conv_layers_ID2615_for_TensorFlow2.X/README_BAK.md b/TensorFlow2/built-in/keras_sample/subclassing_conv_layers_ID2615_for_TensorFlow2.X/README_BAK.md
new file mode 100644
index 0000000000000000000000000000000000000000..b0e12437f69b1feb3649d4590b15895d4f61b4fb
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/subclassing_conv_layers_ID2615_for_TensorFlow2.X/README_BAK.md
@@ -0,0 +1,193 @@
+# Customizing the convolution operation of a Conv2D layer
+
+**Author:** [lukewood](https://lukewood.xyz)
+**Date created:** 11/03/2021
+**Last modified:** 11/03/2021
+**Description:** This example shows how to implement custom convolution layers using the `Conv.convolution_op()` API.
+
+
+
[**View in Colab**](https://colab.research.google.com/github/keras-team/keras-io/blob/master/examples/keras_recipes/ipynb/subclassing_conv_layers.ipynb) •
[**GitHub source**](https://github.com/keras-team/keras-io/blob/master/examples/keras_recipes/subclassing_conv_layers.py)
+
+
+
+---
+## Introduction
+
+You may sometimes need to implement custom versions of convolution layers like `Conv1D` and `Conv2D`.
+Keras enables you do this without implementing the entire layer from scratch: you can reuse
+most of the base convolution layer and just customize the convolution op itself via the
+`convolution_op()` method.
+
+This method was introduced in Keras 2.7. So before using the
+`convolution_op()` API, ensure that you are running Keras version 2.7.0 or greater.
+
+
+```python
+import tensorflow.keras as keras
+
+print(keras.__version__)
+```
+
+
+```
+2.7.0
+
+```
+
+---
+## A Simple `StandardizedConv2D` implementation
+
+There are two ways to use the `Conv.convolution_op()` API. The first way
+is to override the `convolution_op()` method on a convolution layer subclass.
+Using this approach, we can quickly implement a
+[StandardizedConv2D](https://arxiv.org/abs/1903.10520) as shown below.
+
+
+```python
+import tensorflow as tf
+import tensorflow.keras as keras
+import keras.layers as layers
+import numpy as np
+
+
+class StandardizedConv2DWithOverride(layers.Conv2D):
+ def convolution_op(self, inputs, kernel):
+ mean, var = tf.nn.moments(kernel, axes=[0, 1, 2], keepdims=True)
+ return tf.nn.conv2d(
+ inputs,
+ (kernel - mean) / tf.sqrt(var + 1e-10),
+ padding="VALID",
+ strides=list(self.strides),
+ name=self.__class__.__name__,
+ )
+
+```
+
+The other way to use the `Conv.convolution_op()` API is to directly call the
+`convolution_op()` method from the `call()` method of a convolution layer subclass.
+A comparable class implemented using this approach is shown below.
+
+
+```python
+
+class StandardizedConv2DWithCall(layers.Conv2D):
+ def call(self, inputs):
+ mean, var = tf.nn.moments(self.kernel, axes=[0, 1, 2], keepdims=True)
+ result = self.convolution_op(
+ inputs, (self.kernel - mean) / tf.sqrt(var + 1e-10)
+ )
+ if self.use_bias:
+ result = result + self.bias
+ return result
+
+```
+
+---
+## Example Usage
+
+Both of these layers work as drop-in replacements for `Conv2D`. The following
+demonstration performs classification on the MNIST dataset.
+
+
+```python
+# Model / data parameters
+num_classes = 10
+input_shape = (28, 28, 1)
+
+# the data, split between train and test sets
+(x_train, y_train), (x_test, y_test) = keras.datasets.mnist.load_data()
+
+# Scale images to the [0, 1] range
+x_train = x_train.astype("float32") / 255
+x_test = x_test.astype("float32") / 255
+# Make sure images have shape (28, 28, 1)
+x_train = np.expand_dims(x_train, -1)
+x_test = np.expand_dims(x_test, -1)
+print("x_train shape:", x_train.shape)
+print(x_train.shape[0], "train samples")
+print(x_test.shape[0], "test samples")
+
+# convert class vectors to binary class matrices
+y_train = keras.utils.to_categorical(y_train, num_classes)
+y_test = keras.utils.to_categorical(y_test, num_classes)
+
+model = keras.Sequential(
+ [
+ keras.layers.InputLayer(input_shape=input_shape),
+ StandardizedConv2DWithCall(32, kernel_size=(3, 3), activation="relu"),
+ layers.MaxPooling2D(pool_size=(2, 2)),
+ StandardizedConv2DWithOverride(64, kernel_size=(3, 3), activation="relu"),
+ layers.MaxPooling2D(pool_size=(2, 2)),
+ layers.Flatten(),
+ layers.Dropout(0.5),
+ layers.Dense(num_classes, activation="softmax"),
+ ]
+)
+
+model.summary()
+```
+
+```python
+batch_size = 128
+epochs = 5
+
+model.compile(loss="categorical_crossentropy", optimizer="adam", metrics=["accuracy"])
+
+model.fit(x_train, y_train, batch_size=batch_size, epochs=5, validation_split=0.1)
+```
+
+```
+x_train shape: (60000, 28, 28, 1)
+60000 train samples
+10000 test samples
+Model: "sequential"
+_________________________________________________________________
+ Layer (type) Output Shape Param #
+=================================================================
+ standardized_conv2d_with_ca (None, 26, 26, 32) 320
+ ll (StandardizedConv2DWithC
+ all)
+
+ max_pooling2d (MaxPooling2D (None, 13, 13, 32) 0
+ )
+
+ standardized_conv2d_with_ov (None, 11, 11, 64) 18496
+ erride (StandardizedConv2DW
+ ithOverride)
+
+ max_pooling2d_1 (MaxPooling (None, 5, 5, 64) 0
+ 2D)
+
+ flatten (Flatten) (None, 1600) 0
+
+ dropout (Dropout) (None, 1600) 0
+
+ dense (Dense) (None, 10) 16010
+
+=================================================================
+Total params: 34,826
+Trainable params: 34,826
+Non-trainable params: 0
+_________________________________________________________________
+
+Epoch 1/5
+422/422 [==============================] - 7s 15ms/step - loss: 1.8435 - accuracy: 0.8415 - val_loss: 0.1177 - val_accuracy: 0.9660
+Epoch 2/5
+422/422 [==============================] - 6s 14ms/step - loss: 0.2460 - accuracy: 0.9338 - val_loss: 0.0727 - val_accuracy: 0.9772
+Epoch 3/5
+422/422 [==============================] - 6s 14ms/step - loss: 0.1600 - accuracy: 0.9541 - val_loss: 0.0537 - val_accuracy: 0.9862
+Epoch 4/5
+422/422 [==============================] - 6s 14ms/step - loss: 0.1264 - accuracy: 0.9633 - val_loss: 0.0509 - val_accuracy: 0.9845
+Epoch 5/5
+422/422 [==============================] - 6s 14ms/step - loss: 0.1090 - accuracy: 0.9679 - val_loss: 0.0457 - val_accuracy: 0.9872
+
+
+
+```
+
+---
+## Conclusion
+
+The `Conv.convolution_op()` API provides an easy and readable way to implement custom
+convolution layers. A `StandardizedConvolution` implementation using the API is quite
+terse, consisting of only four lines of code.
diff --git a/TensorFlow2/built-in/keras_sample/subclassing_conv_layers_ID2615_for_TensorFlow2.X/modelzoo_level.txt b/TensorFlow2/built-in/keras_sample/subclassing_conv_layers_ID2615_for_TensorFlow2.X/modelzoo_level.txt
new file mode 100644
index 0000000000000000000000000000000000000000..a829ab59b97a1022dd6fc33b59b7ae0d55009432
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/subclassing_conv_layers_ID2615_for_TensorFlow2.X/modelzoo_level.txt
@@ -0,0 +1,3 @@
+FuncStatus:OK
+PerfStatus:NOK
+PrecisionStatus:OK
\ No newline at end of file
diff --git a/TensorFlow2/built-in/keras_sample/subclassing_conv_layers_ID2615_for_TensorFlow2.X/npu_convert_dropout.py b/TensorFlow2/built-in/keras_sample/subclassing_conv_layers_ID2615_for_TensorFlow2.X/npu_convert_dropout.py
new file mode 100644
index 0000000000000000000000000000000000000000..95f8689ce4da26c08f18a0fcb49c42eb7f1c8b06
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/subclassing_conv_layers_ID2615_for_TensorFlow2.X/npu_convert_dropout.py
@@ -0,0 +1,54 @@
+#!/usr/bin/env python3
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============================================================================
+# Copyright 2021 Huawei Technologies Co., Ltd
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+from keras import backend
+from keras.utils import control_flow_util
+from keras.layers.core import Dropout
+from tensorflow.python.ops import array_ops
+from tensorflow.python.ops import nn
+import npu_ops
+
+def dropout_call(self, inputs, training=None):
+ """Make Keras Dropout to execute NPU dropout"""
+ if training is None:
+ training = backend.learning_phase()
+
+ def dropped_inputs():
+ return npu_ops.dropout(
+ inputs,
+ noise_shape=self._get_noise_shape(inputs),
+ seed=self.seed,
+ keep_prob=1 - self.rate)
+
+ output = control_flow_util.smart_cond(training,
+ dropped_inputs,
+ lambda : array_ops.identity(inputs))
+
+ return output
+
+Dropout.call = dropout_call
diff --git a/TensorFlow2/built-in/keras_sample/subclassing_conv_layers_ID2615_for_TensorFlow2.X/npu_ops.py b/TensorFlow2/built-in/keras_sample/subclassing_conv_layers_ID2615_for_TensorFlow2.X/npu_ops.py
new file mode 100644
index 0000000000000000000000000000000000000000..fa6f8f211c19e1bce9d78a90c7c11b6121efdbd7
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/subclassing_conv_layers_ID2615_for_TensorFlow2.X/npu_ops.py
@@ -0,0 +1,256 @@
+# Copyright 2016 The TensorFlow Authors. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ==============================================================================
+# ============================================================================
+# Copyright 2021 Huawei Technologies Co., Ltd
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============================================================================
+
+"""Ops for collective operations implemented using hccl."""
+from __future__ import absolute_import
+from __future__ import division
+from __future__ import print_function
+
+
+import numbers
+from tensorflow.python.ops import array_ops
+from tensorflow.python.framework import tensor_shape
+from tensorflow.python.framework import ops
+from tensorflow.python.eager import context
+
+from npu_device import gen_npu_ops
+
+
+DEFAULT_GRAPH_SEED = 87654321
+_MAXINT32 = 2**31 - 1
+def LARSV2(input_weight,
+ input_grad,
+ weight_decay,
+ learning_rate,
+ hyperpara=0.001,
+ epsilon=0.00001,
+ use_clip=False,
+ name=None):
+ if context.executing_eagerly():
+ raise RuntimeError("tf.LARSV2() is not compatible with "
+ "eager execution.")
+
+ return gen_npu_ops.lars_v2(input_weight=input_weight,
+ input_grad=input_grad,
+ weight_decay=weight_decay,
+ learning_rate=learning_rate,
+ hyperpara=hyperpara,
+ epsilon=epsilon,
+ use_clip=use_clip,
+ name=name)
+
+
+def _truncate_seed(seed):
+ return seed % _MAXINT32 # Truncate to fit into 32-bit integer
+
+def get_seed(op_seed):
+ global_seed = ops.get_default_graph().seed
+
+ if global_seed is not None:
+ if op_seed is None:
+ op_seed = ops.get_default_graph()._last_id
+
+ seeds = _truncate_seed(global_seed), _truncate_seed(op_seed)
+ else:
+ if op_seed is not None:
+ seeds = DEFAULT_GRAPH_SEED, _truncate_seed(op_seed)
+ else:
+ seeds = None, None
+ # Avoid (0, 0) as the C++ ops interpret it as nondeterminism, which would
+ # be unexpected since Python docs say nondeterminism is (None, None).
+ if seeds == (0, 0):
+ return (0, _MAXINT32)
+ return seeds
+
+def _get_noise_shape(x, noise_shape):
+ # If noise_shape is none return immediately.
+ if noise_shape is None:
+ return array_ops.shape(x)
+
+ try:
+ # Best effort to figure out the intended shape.
+ # If not possible, let the op to handle it.
+ # In eager mode exception will show up.
+ noise_shape_ = tensor_shape.as_shape(noise_shape)
+ except (TypeError, ValueError):
+ return noise_shape
+
+ if x.shape.dims is not None and len(x.shape.dims) == len(noise_shape_.dims):
+ new_dims = []
+ for i, dim in enumerate(x.shape.dims):
+ if noise_shape_.dims[i].value is None and dim.value is not None:
+ new_dims.append(dim.value)
+ else:
+ new_dims.append(noise_shape_.dims[i].value)
+ return tensor_shape.TensorShape(new_dims)
+
+ return noise_shape
+
+def dropout(x, keep_prob, noise_shape=None, seed=None, name=None):
+ """The gradient for `gelu`.
+
+ Args:
+ x: A tensor with type is float.
+ keep_prob: A tensor, float, rate of every element reserved.
+ noise_shape: A 1-D tensor, with type int32, shape of keep/drop what random
+ generated.
+ seed: Random seed.
+ name: Layer name.
+
+ Returns:
+ A tensor.
+ """
+ if context.executing_eagerly():
+ raise RuntimeError("tf.dropout() is not compatible with "
+ "eager execution.")
+ x = ops.convert_to_tensor(x, name="x")
+ if not x.dtype.is_floating:
+ raise ValueError("x has to be a floating point tensor since it's going to"
+ " be scaled. Got a %s tensor instead." % x.dtype)
+ if isinstance(keep_prob, numbers.Real) and not 0 < keep_prob <= 1:
+ raise ValueError("keep_prob must be a scalar tensor or a float in the "
+ "range (0, 1], got %g" % keep_prob)
+ if isinstance(keep_prob, float) and keep_prob == 1:
+ return x
+ seed, seed2 = get_seed(seed)
+ noise_shape = _get_noise_shape(x, noise_shape)
+ gen_out = gen_npu_ops.drop_out_gen_mask(noise_shape, keep_prob, seed, seed2, name)
+ result = gen_npu_ops.drop_out_do_mask(x, gen_out, keep_prob, name)
+ return result
+
+@ops.RegisterGradient("DropOutDoMask")
+def _DropOutDoMaskGrad(op, grad):
+ result = gen_npu_ops.drop_out_do_mask(grad, op.inputs[1], op.inputs[2])
+ return [result, None, None]
+
+def basic_lstm_cell(x, h, c, w, b, keep_prob, forget_bias, state_is_tuple,
+ activation, name=None):
+ if context.executing_eagerly():
+ raise RuntimeError("tf.basic_lstm_cell() is not compatible with "
+ "eager execution.")
+ x = ops.convert_to_tensor(x, name="x")
+ h = ops.convert_to_tensor(h, name="h")
+ c = ops.convert_to_tensor(c, name="c")
+ w = ops.convert_to_tensor(w, name="w")
+ b = ops.convert_to_tensor(b, name="b")
+ result = gen_npu_ops.basic_lstm_cell(x, h, c, w, b, keep_prob, forget_bias, state_is_tuple,
+ activation, name)
+ return result
+
+@ops.RegisterGradient("BasicLSTMCell")
+def basic_lstm_cell_grad(op, dct, dht, dit, djt, dft, dot, dtanhct):
+
+ dgate, dct_1 = gen_npu_ops.basic_lstm_cell_c_state_grad(op.inputs[2], dht, dct, op.outputs[2], op.outputs[3], op.outputs[4], op.outputs[5], op.outputs[6], forget_bias=op.get_attr("forget_bias"), activation=op.get_attr("activation"))
+ dw, db = gen_npu_ops.basic_lstm_cell_weight_grad(op.inputs[0], op.inputs[1], dgate)
+ dxt, dht = gen_npu_ops.basic_lstm_cell_input_grad(dgate, op.inputs[3], keep_prob=op.get_attr("keep_prob"))
+
+ return [dxt, dht, dct_1, dw, db]
+
+def adam_apply_one_assign(input0, input1, input2, input3, input4,
+ mul0_x, mul1_x, mul2_x, mul3_x, add2_y, name=None):
+ if context.executing_eagerly():
+ raise RuntimeError("tf.adam_apply_one_assign() is not compatible with "
+ "eager execution.")
+ result = gen_npu_ops.adam_apply_one_assign(input0, input1, input2, input3, input4,
+ mul0_x, mul1_x, mul2_x, mul3_x, add2_y,name)
+ return result
+
+def adam_apply_one_with_decay_assign(input0, input1, input2, input3, input4,
+ mul0_x, mul1_x, mul2_x, mul3_x, mul4_x, add2_y, name=None):
+ if context.executing_eagerly():
+ raise RuntimeError("tf.adam_apply_one_with_decay_assign() is not compatible with "
+ "eager execution.")
+ result = gen_npu_ops.adam_apply_one_with_decay_assign(input0, input1, input2, input3, input4,
+ mul0_x, mul1_x, mul2_x, mul3_x, mul4_x, add2_y, name)
+ return result
+
+@ops.RegisterGradient("DynamicGruV2")
+def dynamic_gru_v2_grad(op, dy, doutput_h, dupdate, dreset, dnew, dhidden_new):
+ (x, weight_input, weight_hidden, bias_input, bias_hidden, seq_length, init_h) = op.inputs
+ (y, output_h, update, reset, new, hidden_new) = op.outputs
+ (dw_input, dw_hidden, db_input, db_hidden, dx, dh_prev) = gen_npu_ops.dynamic_gru_v2_grad(x, weight_input, weight_hidden, y, init_h, output_h, dy, doutput_h, update, reset, new, hidden_new, direction=op.get_attr("direction"), cell_depth=op.get_attr("cell_depth"), keep_prob=op.get_attr("keep_prob"), cell_clip=op.get_attr("cell_clip"), num_proj=op.get_attr("num_proj"), time_major=op.get_attr("time_major"), gate_order=op.get_attr("gate_order"), reset_after=op.get_attr("reset_after"))
+
+ return (dx, dw_input, dw_hidden, db_input, db_hidden, seq_length, dh_prev)
+
+@ops.RegisterGradient("DynamicRnn")
+def dynamic_rnn_grad(op, dy, dh, dc, di, dj, df, do, dtanhc):
+ (x, w, b, seq_length, init_h, init_c) = op.inputs
+ (y, output_h, output_c, i, j, f, o, tanhc) = op.outputs
+ (dw, db, dx, dh_prev, dc_prev) = gen_npu_ops.dynamic_rnn_grad(x, w, b, y, init_h[-1], init_c[-1], output_h, output_c, dy, dh[-1], dc[-1], i, j, f, o, tanhc, cell_type=op.get_attr("cell_type"), direction=op.get_attr("direction"), cell_depth=op.get_attr("cell_depth"), use_peephole=op.get_attr("use_peephole"), keep_prob=op.get_attr("keep_prob"), cell_clip=op.get_attr("cell_clip"), num_proj=op.get_attr("num_proj"), time_major=op.get_attr("time_major"), forget_bias=op.get_attr("forget_bias"))
+
+ return (dx, dw, db, seq_length, dh_prev, dc_prev)
+
+def lamb_apply_optimizer_assign(input0,input1,input2,input3,mul0_x,mul1_x,mul2_x,
+ mul3_x,add2_y,steps,do_use_weight,weight_decay_rate,name=None):
+ if context.executing_eagerly():
+ raise RuntimeError("tf.lamb_apply_optimizer_assign() is not compatible with eager execution")
+ update,nextv,nextm=gen_npu_ops.lamb_apply_optimizer_assign(input0,input1,input2,input3,mul0_x,mul1_x,mul2_x,
+ mul3_x,add2_y,steps,do_use_weight,weight_decay_rate,name)
+ return update,nextv,nextm
+
+def lamb_apply_weight_assign(input0,input1,input2,input3,input4,name=None):
+ if context.executing_eagerly():
+ raise RuntimeError("tf.lamb_apply_weight_assign() is not compatible with eager execution")
+ result = gen_npu_ops.lamb_apply_weight_assign(input0,input1,input2,input3,input4,name)
+ return result
+
+def dropout_v3(x, keep_prob, noise_shape=None, seed=None, name=None):
+ """ The gradient for gelu
+
+ Args:
+ x: A tensor with type is float
+ keep_prob: A tensor, float, rate of every element reserved
+ noise_shape: A 1-D tensor, with type int32, shape of keep/drop what random generated.
+ seed: Random seed.
+ name: Layer name.
+
+ Returns:
+ A tensor.
+ """
+ x = ops.convert_to_tensor(x,name="x")
+ if not x.dtype.is_floating:
+ raise ValueError("x has to be a floating point tensor since it's going to be scaled. Got a %s tensor instead." % x.dtype)
+
+ if isinstance(keep_prob,numbers.Real) and not 0 < keep_prob <=1:
+ raise ValueError("Keep_prob must be a scalar tensor or a float in the range (0,1], got %g" % keep_prob)
+
+ if isinstance(keep_prob,float) and keep_prob==1:
+ return x
+
+ seed, seed2 = get_seed(seed)
+ noise_shape = _get_noise_shape(x,noise_shape)
+ gen_out = gen_npu_ops.drop_out_gen_mask_v3(noise_shape,keep_prob,seed,seed2,name)
+ result = gen_npu_ops.drop_out_do_mask_v3(x, gen_out, keep_prob, name)
+ return result
+
+@ops.RegisterGradient("DropOutDoMaskV3")
+def _DropOutDoMaskV3Grad(op,grad):
+ result = gen_npu_ops.drop_out_do_mask_v3(grad, op.inputs[1], op.inputs[2])
+ return [result, None, None]
\ No newline at end of file
diff --git a/TensorFlow2/built-in/keras_sample/subclassing_conv_layers_ID2615_for_TensorFlow2.X/requirements.txt b/TensorFlow2/built-in/keras_sample/subclassing_conv_layers_ID2615_for_TensorFlow2.X/requirements.txt
new file mode 100644
index 0000000000000000000000000000000000000000..037077e65ef3f631a03753ff6eaf61cc1be38e1c
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/subclassing_conv_layers_ID2615_for_TensorFlow2.X/requirements.txt
@@ -0,0 +1,13 @@
+pygments>=2.7.4
+jinja2
+markdown
+requests
+mdx_truly_sane_lists
+sphinx~=3.0.3
+black==19.10b0
+pathlib
+tensorflow
+PyYAML
+jupyter
+keras
+pandas
\ No newline at end of file
diff --git a/TensorFlow2/built-in/keras_sample/subclassing_conv_layers_ID2615_for_TensorFlow2.X/run_1p.sh b/TensorFlow2/built-in/keras_sample/subclassing_conv_layers_ID2615_for_TensorFlow2.X/run_1p.sh
new file mode 100644
index 0000000000000000000000000000000000000000..21876811d3e9f4b19398a0ebf3a7c4d046dff30e
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/subclassing_conv_layers_ID2615_for_TensorFlow2.X/run_1p.sh
@@ -0,0 +1,3 @@
+#!/bin/bash
+data_path=""
+nohup python3 subclassing_conv_layers.py --epochs=2 --batch_size=256 --data_path=$data_path >$cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 &
\ No newline at end of file
diff --git a/TensorFlow2/built-in/keras_sample/subclassing_conv_layers_ID2615_for_TensorFlow2.X/subclassing_conv_layers.py b/TensorFlow2/built-in/keras_sample/subclassing_conv_layers_ID2615_for_TensorFlow2.X/subclassing_conv_layers.py
new file mode 100644
index 0000000000000000000000000000000000000000..93d344533496b40b88abd1865757d29947b1b801
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/subclassing_conv_layers_ID2615_for_TensorFlow2.X/subclassing_conv_layers.py
@@ -0,0 +1,310 @@
+"""
+Title: Customizing the convolution operation of a Conv2D layer
+Author: [lukewood](https://lukewood.xyz)
+Date created: 11/03/2021
+Last modified: 11/03/2021
+Description: This example shows how to implement custom convolution layers using the `Conv.convolution_op()` API.
+"""
+"""
+## Introduction
+
+You may sometimes need to implement custom versions of convolution layers like `Conv1D` and `Conv2D`.
+Keras enables you do this without implementing the entire layer from scratch: you can reuse
+most of the base convolution layer and just customize the convolution op itself via the
+`convolution_op()` method.
+
+This method was introduced in Keras 2.7. So before using the
+`convolution_op()` API, ensure that you are running Keras version 2.7.0 or greater.
+"""
+#
+# Copyright 2017 The TensorFlow Authors. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============================================================================
+# Copyright 2021 Huawei Technologies Co., Ltd
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+import tensorflow.keras as keras
+
+print(keras.__version__)
+"""
+## A Simple `StandardizedConv2D` implementation
+
+There are two ways to use the `Conv.convolution_op()` API. The first way
+is to override the `convolution_op()` method on a convolution layer subclass.
+Using this approach, we can quickly implement a
+[StandardizedConv2D](https://arxiv.org/abs/1903.10520) as shown below.
+"""
+import tensorflow as tf
+import tensorflow.keras as keras
+import keras.layers as layers
+import numpy as np
+from time import time
+import npu_device
+import os
+import time
+from absl import flags, app
+import npu_convert_dropout
+
+# npu_device.open().as_default()
+
+flags.DEFINE_string(name='data_path', default='/home/hzh/involution/cifar-10-batches-py',
+ help='dataset path(local)')
+flags.DEFINE_integer(name='epochs', default=5, help='training epochs')
+flags.DEFINE_integer(name='batch_size', default=128, help='training batch_size')
+flags.DEFINE_boolean(name='save_h5', default=True, help='whether save h5 file after training')
+flags.DEFINE_integer(name='log_steps', default=234, help='training epochs')
+flags.DEFINE_string(name='precision_mode', default= 'allow_fp32_to_fp16',
+ help='allow_fp32_to_fp16/force_fp16/ '
+ 'must_keep_origin_dtype/allow_mix_precision.')
+flags.DEFINE_boolean(name='over_dump', default=False,
+ help='if or not over detection, default is False')
+flags.DEFINE_boolean(name='data_dump_flag', default=False,
+ help='data dump flag, default is False')
+flags.DEFINE_string(name='data_dump_step', default="10",
+ help='data dump step, default is 10')
+flags.DEFINE_boolean(name='profiling', default=False,
+ help='if or not profiling for performance debug, default is False')
+flags.DEFINE_string(name='profiling_dump_path', default="/home/data",
+ help='the path to save profiling data')
+flags.DEFINE_string(name='over_dump_path', default="/home/data",
+ help='the path to save over dump data')
+flags.DEFINE_string(name='data_dump_path', default="/home/data",
+ help='the path to save dump data')
+flags.DEFINE_boolean(name='use_mixlist', default=False,
+ help='whether to enable mixlist, default is True')
+flags.DEFINE_boolean(name='fusion_off_flag', default=False,
+ help='whether to enable mixlist, default is True')
+flags.DEFINE_string(name='mixlist_file', default='ops_info.json',
+ help='mixlist file name, default is ops_info.json')
+flags.DEFINE_string(name='fusion_off_file', default='fusion_switch.cfg',
+ help='fusion_off file name, default is fusion_switch.cfg')
+flags.DEFINE_boolean(name='auto_tune', default=False,
+ help='auto_tune flag, default is False')
+flags.DEFINE_integer(name='static', default=0,
+ help='static, default is 0')
+FLAGS = flags.FLAGS
+
+def npu_config():
+
+
+ npu_config = {}
+
+ if FLAGS.data_dump_flag:
+ npu_device.global_options().dump_config.enable_dump = True
+ npu_device.global_options().dump_config.dump_path = FLAGS.data_dump_path
+ npu_device.global_options().dump_config.dump_step = FLAGS.data_dump_step
+ npu_device.global_options().dump_config.dump_mode = "all"
+
+ if FLAGS.over_dump:
+ npu_device.global_options().dump_config.enable_dump_debug = True
+ npu_device.global_options().dump_config.dump_path = FLAGS.over_dump_path
+ npu_device.global_options().dump_config.dump_debug_mode = "all"
+
+ if FLAGS.profiling:
+ npu_device.global_options().profiling_config.enable_profiling = True
+ profiling_options = '{"output":"' + FLAGS.profiling_dump_path + '", \
+ "training_trace":"on", \
+ "task_trace":"on", \
+ "aicpu":"on", \
+ "aic_metrics":"PipeUtilization",\
+ "fp_point":"", \
+ "bp_point":""}'
+ npu_device.global_options().profiling_config.profiling_options = profiling_options
+ npu_device.global_options().precision_mode=FLAGS.precision_mode
+ if FLAGS.use_mixlist and FLAGS.precision_mode=='allow_mix_precision':
+ npu_device.global_options().modify_mixlist=FLAGS.mixlist_file
+ if FLAGS.fusion_off_flag:
+ npu_device.global_options().fusion_switch_file=FLAGS.fusion_off_file
+ if FLAGS.auto_tune:
+ npu_device.global_options().auto_tune_mode="RL,GA"
+ npu_device.open().as_default()
+#===============================NPU Migration=========================================
+
+class TimeHistory(tf.keras.callbacks.Callback):
+ def __init__(self, batch_size, log_steps, initial_step=0):
+ self.batch_size = batch_size
+ super(TimeHistory, self).__init__()
+ self.steps_before_epoch = initial_step
+ self.last_log_step = initial_step
+ self.log_steps = log_steps
+ self.steps_in_epoch = 0
+ self.start_time = None
+
+ @property
+ def global_steps(self):
+ """The current 1-indexed global step."""
+ return self.steps_before_epoch + self.steps_in_epoch
+
+ def on_epoch_begin(self, epoch, logs=None):
+ if not self.start_time:
+ self.start_time = time.time()
+ self.epoch_start = time.time()
+
+ def on_batch_begin(self, batch, logs=None):
+ if not self.start_time:
+ self.start_time = time.time()
+
+ def on_batch_end(self, batch, logs=None):
+ self.steps_in_epoch = batch + 1
+ steps_since_last_log = self.global_steps - self.last_log_step
+ if steps_since_last_log >= self.log_steps:
+ now = time.time()
+ elapsed_time = now - self.start_time
+ steps_per_second = steps_since_last_log / elapsed_time
+ examples_per_second = steps_per_second * self.batch_size
+ print(
+ 'TimeHistory: %.2f seconds, %.2f examples/second between steps %d '
+ 'and %d'%(elapsed_time, examples_per_second, self.last_log_step,
+ self.global_steps),flush=True)
+ self.last_log_step = self.global_steps
+ self.start_time = None
+
+ def on_epoch_end(self, epoch, logs=None):
+ epoch_run_time = time.time() - self.epoch_start
+ self.steps_before_epoch += self.steps_in_epoch
+ self.steps_in_epoch = 0
+
+
+def task(_):
+ class StandardizedConv2DWithOverride(layers.Conv2D):
+ def convolution_op(self, inputs, kernel):
+ mean, var = tf.nn.moments(kernel, axes=[0, 1, 2], keepdims=True)
+ return tf.nn.conv2d(
+ inputs,
+ (kernel - mean) / tf.sqrt(var + 1e-10),
+ padding="VALID",
+ strides=list(self.strides),
+ name=self.__class__.__name__,
+ )
+
+
+ """
+ The other way to use the `Conv.convolution_op()` API is to directly call the
+ `convolution_op()` method from the `call()` method of a convolution layer subclass.
+ A comparable class implemented using this approach is shown below.
+ """
+
+
+ class StandardizedConv2DWithCall(layers.Conv2D):
+ def convolution_op(self, inputs, kernel):
+ mean, var = tf.nn.moments(kernel, axes=[0, 1, 2], keepdims=True)
+ return tf.nn.conv2d(
+ inputs,
+ (kernel - mean) / tf.sqrt(var + 1e-10),
+ padding="VALID",
+ strides=list(self.strides),
+ name=self.__class__.__name__,
+ )
+
+ def call(self, inputs):
+ mean, var = tf.nn.moments(self.kernel, axes=[0, 1, 2], keepdims=True)
+ result = self.convolution_op(
+ inputs, (self.kernel - mean) / tf.sqrt(var + 1e-10)
+ )
+ if self.use_bias:
+ result = result + self.bias
+ return result
+
+
+ """
+ ## Example Usage
+
+ Both of these layers work as drop-in replacements for `Conv2D`. The following
+ demonstration performs classification on the MNIST dataset.
+ """
+
+ npu_config()
+
+ # Model / data parameters
+ num_classes = 10
+ input_shape = (28, 28, 1)
+ batch_size = FLAGS.batch_size
+ epochs = FLAGS.epochs
+ # the data, split between train and test sets
+ (x_train, y_train), (x_test, y_test) = keras.datasets.mnist.load_data(os.path.join(FLAGS.data_path, 'mnist.npz'))
+
+ # Scale images to the [0, 1] range
+ x_train = x_train.astype("float32") / 255
+ x_test = x_test.astype("float32") / 255
+ # Make sure images have shape (28, 28, 1)
+ x_train = np.expand_dims(x_train, -1)
+ x_test = np.expand_dims(x_test, -1)
+ print("x_train shape:", x_train.shape)
+ print(x_train.shape[0], "train samples")
+ print(x_test.shape[0], "test samples")
+
+ # convert class vectors to binary class matrices
+ y_train = keras.utils.to_categorical(y_train, num_classes)
+ y_test = keras.utils.to_categorical(y_test, num_classes)
+ if FLAGS.static==1:
+ train_ds = (
+ tf.data.Dataset.from_tensor_slices((x_train, y_train))
+ .batch(batch_size, drop_remainder=True))
+ else:
+ train_ds = (
+ tf.data.Dataset.from_tensor_slices((x_train, y_train))
+ .batch(batch_size, drop_remainder=False))
+ train_ds = train_ds.prefetch(tf.data.experimental.AUTOTUNE)
+ model = keras.Sequential(
+ [
+ keras.layers.InputLayer(input_shape=input_shape),
+ StandardizedConv2DWithCall(32, kernel_size=(3, 3), activation="relu"),
+ layers.MaxPooling2D(pool_size=(2, 2)),
+ StandardizedConv2DWithOverride(64, kernel_size=(3, 3), activation="relu"),
+ layers.MaxPooling2D(pool_size=(2, 2)),
+ layers.Flatten(),
+ layers.Dropout(0.5),
+ layers.Dense(num_classes, activation="softmax"),
+ ]
+ )
+
+ model.summary()
+ """
+
+ """
+
+
+ model.compile(loss="categorical_crossentropy", optimizer="adam", metrics=["accuracy"])
+ callbacks = [TimeHistory(batch_size,FLAGS.log_steps)]
+ #start_time = time()
+ #model.fit(x_train, y_train, batch_size=batch_size, epochs=epochs, validation_split=0.1, verbose=2)
+ model.fit(train_ds, batch_size=batch_size, epochs=epochs, verbose=2, callbacks=callbacks)
+ #end_time = time()
+ #time_s = end_time - start_time
+ #print("TrainingTime: ", time_s)
+
+ if FLAGS.save_h5:
+ model.save("model.h5")
+ """
+ ## Conclusion
+
+ The `Conv.convolution_op()` API provides an easy and readable way to implement custom
+ convolution layers. A `StandardizedConvolution` implementation using the API is quite
+ terse, consisting of only four lines of code.
+ """
+
+
+if __name__ == '__main__':
+ app.run(task)
diff --git a/TensorFlow2/built-in/keras_sample/subclassing_conv_layers_ID2615_for_TensorFlow2.X/test/train_full_1p.sh b/TensorFlow2/built-in/keras_sample/subclassing_conv_layers_ID2615_for_TensorFlow2.X/test/train_full_1p.sh
new file mode 100644
index 0000000000000000000000000000000000000000..278486c1ab436e36c138395be3ab9a62ac64f0cc
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/subclassing_conv_layers_ID2615_for_TensorFlow2.X/test/train_full_1p.sh
@@ -0,0 +1,167 @@
+#!/bin/bash
+cur_path=`pwd`/../
+
+#设置默认日志级别,不需要修改
+# export ASCEND_GLOBAL_LOG_LEVEL=3
+
+#基础参数,需要模型审视修改
+#Batch Size
+batch_size=256
+#网络名称,同目录名称
+Network="subclassing_conv_layers_ID2615_for_TensorFlow2.X"
+#Device数量,单卡默认为1
+RANK_SIZE=1
+#训练epoch,可选
+train_epochs=5
+#训练step
+#train_steps=50000
+#学习率
+# learning_rate=0.001
+# weight_decay=0.0001
+#参数配置
+data_path=""
+
+############维测参数##############
+precision_mode="allow_mix_precision"
+#维持参数,以下不需要修改
+over_dump=False
+if [[ $over_dump == True ]];then
+ over_dump_path=$cur_path/test/overflow_dump #此处cur_path为代码根目录
+ mkdir -p ${over_dump_path}
+fi
+data_dump_flag=False
+data_dump_step="10"
+profiling=False
+use_mixlist=False
+mixlist_file="./configs/ops_info.json"
+fusion_off_flag=False
+fusion_off_file="./configs/fusion_switch.cfg"
+auto_tune=False
+############维测参数##############
+
+if [[ $1 == --help || $1 == --h ]];then
+ echo "usage: ./train_full_1p.sh"
+ exit 1
+fi
+
+for para in $*
+do
+ if [[ $para == --data_path* ]];then
+ data_path=`echo ${para#*=}`
+ elif [[ $para == --precision_mode* ]];then
+ precision_mode=`echo ${para#*=}`
+ elif [[ $para == --over_dump* ]];then
+ over_dump=`echo ${para#*=}`
+ over_dump_path=${cur_path}/output/overflow_dump
+ mkdir -p ${over_dump_path}
+ elif [[ $para == --data_dump_flag* ]];then
+ data_dump_flag=`echo ${para#*=}`
+ data_dump_path=${cur_path}/output/data_dump
+ mkdir -p ${data_dump_path}
+ elif [[ $para == --data_dump_step* ]];then
+ data_dump_step=`echo ${para#*=}`
+ elif [[ $para == --profiling* ]];then
+ profiling=`echo ${para#*=}`
+ profiling_dump_path=${cur_path}/output/profiling
+ mkdir -p ${profiling_dump_path}
+ elif [[ $para == --data_path* ]];then
+ data_path=`echo ${para#*=}`
+ elif [[ $para == --use_mixlist* ]];then
+ use_mixlist=`echo ${para#*=}`
+ elif [[ $para == --mixlist_file* ]];then
+ mixlist_file=`echo ${para#*=}`
+ elif [[ $para == --fusion_off_flag* ]];then
+ fusion_off_flag=`echo ${para#*=}`
+ elif [[ $para == --fusion_off_file* ]];then
+ fusion_off_file=`echo ${para#*=}`
+ elif [[ $para == --auto_tune* ]];then
+ auto_tune=`echo ${para#*=}`
+ fi
+done
+
+if [[ $data_path == "" ]];then
+ echo "[Error] para \"data_path \" must be config"
+ exit 1
+fi
+
+##############执行训练##########
+cd $cur_path
+
+if [ -d $cur_path/test/output ];then
+ rm -rf $cur_path/test/output/*
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+else
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+fi
+wait
+
+start=$(date +%s)
+nohup python3 subclassing_conv_layers.py \
+ --data_path=$data_path \
+ --epochs=${train_epochs} \
+ --batch_size=${batch_size} \
+ --precision_mode=${precision_mode} \
+ --over_dump=${over_dump} \
+ --over_dump_path=${over_dump_path} \
+ --data_dump_flag=${data_dump_flag} \
+ --data_dump_step=${data_dump_step} \
+ --data_dump_path=${data_dump_path} \
+ --profiling=${profiling} \
+ --use_mixlist=${use_mixlist} \
+ --fusion_off_flag=${fusion_off_flag} \
+ --mixlist_file=${mixlist_file} \
+ --auto_tune=${auto_tune} \
+ --fusion_off_file=${fusion_off_file} \
+ --profiling_dump_path=${profiling_dump_path}>$cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 &
+wait
+
+end=$(date +%s)
+e2e_time=$(( $end - $start ))
+
+echo "Final Training Duration sec : $e2e_time"
+
+#结果打印,不需要修改
+echo "------------------ Final result ------------------"
+#输出性能FPS,需要模型审视修改
+#FPS=`awk 'BEGIN{printf "%.2f\n",'211'*'${batch_size}'/'${TrainingTime}'}'`
+TrainingTime=`grep loss $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk '{print $3}'|awk 'NR==2'|tr -cd "[0-9]"`
+FPS=`grep TimeHistory: $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk '{print $4}'|tail -1`
+wait
+
+#打印,不需要修改
+echo "Final Performance images/sec : $FPS"
+
+#输出训练精度,需要模型审视修改
+train_accuracy=`grep loss $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | awk 'END {print$(NF-0)}'`
+#打印,不需要修改
+echo "Final Train Accuracy : ${train_accuracy}"
+
+
+#精度看护结果汇总
+#训练用例信息,不需要修改
+BatchSize=${batch_size}
+DeviceType=`uname -m`
+CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc'
+
+##获取性能数据,不需要修改
+#吞吐量
+ActualFPS=${FPS}
+#单迭代训练时长
+TrainingTime=${TrainingTime}
+
+#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视
+cat $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log| grep loss | awk '{print $6}' > $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt
+#最后一个迭代loss值,不需要修改
+ActualLoss=`awk 'END {print $1}' $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt`
+
+#关键信息打印到${CaseName}.log中,不需要修改
+echo "Network = ${Network}" > $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "RankSize = ${RANK_SIZE}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "BatchSize = ${BatchSize}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "DeviceType = ${DeviceType}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "CaseName = ${CaseName}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualFPS = ${ActualFPS}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainingTime = ${TrainingTime}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualLoss = ${ActualLoss}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
\ No newline at end of file
diff --git a/TensorFlow2/built-in/keras_sample/subclassing_conv_layers_ID2615_for_TensorFlow2.X/test/train_performance_1p.sh b/TensorFlow2/built-in/keras_sample/subclassing_conv_layers_ID2615_for_TensorFlow2.X/test/train_performance_1p.sh
new file mode 100644
index 0000000000000000000000000000000000000000..5a8035e4f7280151ea3df12013ac2d5f0c9652a6
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/subclassing_conv_layers_ID2615_for_TensorFlow2.X/test/train_performance_1p.sh
@@ -0,0 +1,169 @@
+#!/bin/bash
+cur_path=`pwd`/../
+
+#设置默认日志级别,不需要修改
+# export ASCEND_GLOBAL_LOG_LEVEL=3
+
+#基础参数,需要模型审视修改
+#Batch Size
+batch_size=256
+#网络名称,同目录名称
+Network="subclassing_conv_layers_ID2615_for_TensorFlow2.X"
+#Device数量,单卡默认为1
+RANK_SIZE=1
+#训练epoch,可选
+train_epochs=2
+#训练step
+#train_steps=50000
+#学习率
+# learning_rate=0.001
+# weight_decay=0.0001
+#参数配置
+data_path=""
+
+############维测参数##############
+precision_mode="allow_mix_precision"
+#维持参数,以下不需要修改
+over_dump=False
+if [[ $over_dump == True ]];then
+ over_dump_path=$cur_path/test/overflow_dump #此处cur_path为代码根目录
+ mkdir -p ${over_dump_path}
+fi
+data_dump_flag=False
+data_dump_step="10"
+profiling=False
+use_mixlist=False
+mixlist_file="./configs/ops_info.json"
+fusion_off_flag=False
+fusion_off_file="./configs/fusion_switch.cfg"
+auto_tune=False
+############维测参数##############
+
+if [[ $1 == --help || $1 == --h ]];then
+ echo "usage: ./train_performance_1p.sh"
+ exit 1
+fi
+
+for para in $*
+do
+ if [[ $para == --data_path* ]];then
+ data_path=`echo ${para#*=}`
+ elif [[ $para == --precision_mode* ]];then
+ precision_mode=`echo ${para#*=}`
+ elif [[ $para == --over_dump* ]];then
+ over_dump=`echo ${para#*=}`
+ over_dump_path=${cur_path}/output/overflow_dump
+ mkdir -p ${over_dump_path}
+ elif [[ $para == --data_dump_flag* ]];then
+ data_dump_flag=`echo ${para#*=}`
+ data_dump_path=${cur_path}/output/data_dump
+ mkdir -p ${data_dump_path}
+ elif [[ $para == --data_dump_step* ]];then
+ data_dump_step=`echo ${para#*=}`
+ elif [[ $para == --profiling* ]];then
+ profiling=`echo ${para#*=}`
+ profiling_dump_path=${cur_path}/output/profiling
+ mkdir -p ${profiling_dump_path}
+ elif [[ $para == --data_path* ]];then
+ data_path=`echo ${para#*=}`
+ elif [[ $para == --use_mixlist* ]];then
+ use_mixlist=`echo ${para#*=}`
+ elif [[ $para == --mixlist_file* ]];then
+ mixlist_file=`echo ${para#*=}`
+ elif [[ $para == --fusion_off_flag* ]];then
+ fusion_off_flag=`echo ${para#*=}`
+ elif [[ $para == --fusion_off_file* ]];then
+ fusion_off_file=`echo ${para#*=}`
+ elif [[ $para == --auto_tune* ]];then
+ auto_tune=`echo ${para#*=}`
+ fi
+done
+
+if [[ $data_path == "" ]];then
+ echo "[Error] para \"data_path \" must be config"
+ exit 1
+fi
+
+##############执行训练##########
+cd $cur_path
+
+if [ -d $cur_path/test/output ];then
+ rm -rf $cur_path/test/output/*
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+else
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+fi
+wait
+
+start=$(date +%s)
+nohup python3 subclassing_conv_layers.py \
+ --data_path=$data_path \
+ --epochs=${train_epochs} \
+ --batch_size=${batch_size} \
+ --precision_mode=${precision_mode} \
+ --over_dump=${over_dump} \
+ --over_dump_path=${over_dump_path} \
+ --data_dump_flag=${data_dump_flag} \
+ --data_dump_step=${data_dump_step} \
+ --data_dump_path=${data_dump_path} \
+ --profiling=${profiling} \
+ --use_mixlist=${use_mixlist} \
+ --fusion_off_flag=${fusion_off_flag} \
+ --mixlist_file=${mixlist_file} \
+ --auto_tune=${auto_tune} \
+ --fusion_off_file=${fusion_off_file} \
+ --profiling_dump_path=${profiling_dump_path} \
+ --static=0 \
+ --log_steps=235 >$cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 &
+wait
+
+end=$(date +%s)
+e2e_time=$(( $end - $start ))
+
+echo "Final Training Duration sec : $e2e_time"
+
+#结果打印,不需要修改
+echo "------------------ Final result ------------------"
+#输出性能FPS,需要模型审视修改
+TrainingTime=`grep 235/235 $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk '{print $3}'|awk 'NR==2'|tr -cd "[0-9]"`
+#FPS=`awk 'BEGIN{printf "%.2f\n",'235'*'${batch_size}'/'${TrainingTime}'}'`
+FPS=`grep TimeHistory: $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk '{print $4}'|tail -1`
+wait
+
+#打印,不需要修改
+echo "Final Performance images/sec : $FPS"
+
+#输出训练精度,需要模型审视修改
+train_accuracy=`grep loss $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | awk 'END {print$(NF-0)}'`
+#打印,不需要修改
+echo "Final Train Accuracy : ${train_accuracy}"
+
+
+#精度看护结果汇总
+#训练用例信息,不需要修改
+BatchSize=${batch_size}
+DeviceType=`uname -m`
+CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf'
+
+##获取性能数据,不需要修改
+#吞吐量
+ActualFPS=${FPS}
+#单迭代训练时长
+TrainingTime=${TrainingTime}
+
+#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视
+cat $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log| grep loss | awk '{print $6}' > $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt
+#最后一个迭代loss值,不需要修改
+ActualLoss=`awk 'END {print $1}' $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt`
+
+#关键信息打印到${CaseName}.log中,不需要修改
+echo "Network = ${Network}" > $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "RankSize = ${RANK_SIZE}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "BatchSize = ${BatchSize}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "DeviceType = ${DeviceType}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "CaseName = ${CaseName}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualFPS = ${ActualFPS}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainingTime = ${TrainingTime}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualLoss = ${ActualLoss}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
\ No newline at end of file
diff --git a/TensorFlow2/built-in/keras_sample/subclassing_conv_layers_ID2615_for_TensorFlow2.X/test/train_performance_1p_static.sh b/TensorFlow2/built-in/keras_sample/subclassing_conv_layers_ID2615_for_TensorFlow2.X/test/train_performance_1p_static.sh
new file mode 100644
index 0000000000000000000000000000000000000000..25a5b597b26aec87c8e477bcac94d923f877e6fd
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/subclassing_conv_layers_ID2615_for_TensorFlow2.X/test/train_performance_1p_static.sh
@@ -0,0 +1,169 @@
+#!/bin/bash
+cur_path=`pwd`/../
+
+#设置默认日志级别,不需要修改
+# export ASCEND_GLOBAL_LOG_LEVEL=3
+
+#基础参数,需要模型审视修改
+#Batch Size
+batch_size=256
+#网络名称,同目录名称
+Network="subclassing_conv_layers_ID2615_for_TensorFlow2.X"
+#Device数量,单卡默认为1
+RANK_SIZE=1
+#训练epoch,可选
+train_epochs=3
+#训练step
+#train_steps=50000
+#学习率
+# learning_rate=0.001
+# weight_decay=0.0001
+#参数配置
+data_path=""
+
+############维测参数##############
+precision_mode="allow_mix_precision"
+#维持参数,以下不需要修改
+over_dump=False
+if [[ $over_dump == True ]];then
+ over_dump_path=$cur_path/test/overflow_dump #此处cur_path为代码根目录
+ mkdir -p ${over_dump_path}
+fi
+data_dump_flag=False
+data_dump_step="10"
+profiling=False
+use_mixlist=False
+mixlist_file="./configs/ops_info.json"
+fusion_off_flag=False
+fusion_off_file="./configs/fusion_switch.cfg"
+auto_tune=False
+############维测参数##############
+
+if [[ $1 == --help || $1 == --h ]];then
+ echo "usage: ./train_performance_1p.sh"
+ exit 1
+fi
+
+for para in $*
+do
+ if [[ $para == --data_path* ]];then
+ data_path=`echo ${para#*=}`
+ elif [[ $para == --precision_mode* ]];then
+ precision_mode=`echo ${para#*=}`
+ elif [[ $para == --over_dump* ]];then
+ over_dump=`echo ${para#*=}`
+ over_dump_path=${cur_path}/output/overflow_dump
+ mkdir -p ${over_dump_path}
+ elif [[ $para == --data_dump_flag* ]];then
+ data_dump_flag=`echo ${para#*=}`
+ data_dump_path=${cur_path}/output/data_dump
+ mkdir -p ${data_dump_path}
+ elif [[ $para == --data_dump_step* ]];then
+ data_dump_step=`echo ${para#*=}`
+ elif [[ $para == --profiling* ]];then
+ profiling=`echo ${para#*=}`
+ profiling_dump_path=${cur_path}/output/profiling
+ mkdir -p ${profiling_dump_path}
+ elif [[ $para == --data_path* ]];then
+ data_path=`echo ${para#*=}`
+ elif [[ $para == --use_mixlist* ]];then
+ use_mixlist=`echo ${para#*=}`
+ elif [[ $para == --mixlist_file* ]];then
+ mixlist_file=`echo ${para#*=}`
+ elif [[ $para == --fusion_off_flag* ]];then
+ fusion_off_flag=`echo ${para#*=}`
+ elif [[ $para == --fusion_off_file* ]];then
+ fusion_off_file=`echo ${para#*=}`
+ elif [[ $para == --auto_tune* ]];then
+ auto_tune=`echo ${para#*=}`
+ fi
+done
+
+if [[ $data_path == "" ]];then
+ echo "[Error] para \"data_path \" must be config"
+ exit 1
+fi
+
+##############执行训练##########
+cd $cur_path
+
+if [ -d $cur_path/test/output ];then
+ rm -rf $cur_path/test/output/*
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+else
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+fi
+wait
+
+start=$(date +%s)
+nohup python3 subclassing_conv_layers.py \
+ --data_path=$data_path \
+ --epochs=${train_epochs} \
+ --batch_size=${batch_size} \
+ --precision_mode=${precision_mode} \
+ --over_dump=${over_dump} \
+ --over_dump_path=${over_dump_path} \
+ --data_dump_flag=${data_dump_flag} \
+ --data_dump_step=${data_dump_step} \
+ --data_dump_path=${data_dump_path} \
+ --profiling=${profiling} \
+ --use_mixlist=${use_mixlist} \
+ --fusion_off_flag=${fusion_off_flag} \
+ --mixlist_file=${mixlist_file} \
+ --auto_tune=${auto_tune} \
+ --fusion_off_file=${fusion_off_file} \
+ --profiling_dump_path=${profiling_dump_path} \
+ --static=1 \
+ --log_steps=234>$cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 &
+wait
+
+end=$(date +%s)
+e2e_time=$(( $end - $start ))
+
+echo "Final Training Duration sec : $e2e_time"
+
+#结果打印,不需要修改
+echo "------------------ Final result ------------------"
+#输出性能FPS,需要模型审视修改
+TrainingTime=`grep 234/ $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk '{print $3}'|awk 'NR==2'|tr -cd "[0-9]"`
+#FPS=`awk 'BEGIN{printf "%.2f\n",'234'*'${batch_size}'/'${TrainingTime}'}'`
+FPS=`grep TimeHistory: $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk '{print $4}'|tail -1`
+wait
+
+#打印,不需要修改
+echo "Final Performance images/sec : $FPS"
+
+#输出训练精度,需要模型审视修改
+train_accuracy=`grep accuracy $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | awk 'END {print$(NF-0)}'`
+#打印,不需要修改
+echo "Final Train Accuracy : ${train_accuracy}"
+
+
+#精度看护结果汇总
+#训练用例信息,不需要修改
+BatchSize=${batch_size}
+DeviceType=`uname -m`
+CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf'
+
+##获取性能数据,不需要修改
+#吞吐量
+ActualFPS=${FPS}
+#单迭代训练时长
+TrainingTime=${TrainingTime}
+
+#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视
+cat $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log| grep loss | awk '{print $6}' > $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt
+#最后一个迭代loss值,不需要修改
+ActualLoss=`awk 'END {print $1}' $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt`
+
+#关键信息打印到${CaseName}.log中,不需要修改
+echo "Network = ${Network}" > $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "RankSize = ${RANK_SIZE}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "BatchSize = ${BatchSize}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "DeviceType = ${DeviceType}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "CaseName = ${CaseName}_static" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualFPS = ${ActualFPS}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainingTime = ${TrainingTime}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualLoss = ${ActualLoss}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
\ No newline at end of file
diff --git a/TensorFlow2/built-in/keras_sample/super_resolution_sub_pixel_ID2541_for_TensorFlow2.X/LICENSE b/TensorFlow2/built-in/keras_sample/super_resolution_sub_pixel_ID2541_for_TensorFlow2.X/LICENSE
new file mode 100644
index 0000000000000000000000000000000000000000..51d555a151df9c6c96d16137aa4bcf6142a447ef
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/super_resolution_sub_pixel_ID2541_for_TensorFlow2.X/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2018 Ke YU
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/TensorFlow2/built-in/keras_sample/super_resolution_sub_pixel_ID2541_for_TensorFlow2.X/README.md b/TensorFlow2/built-in/keras_sample/super_resolution_sub_pixel_ID2541_for_TensorFlow2.X/README.md
new file mode 100644
index 0000000000000000000000000000000000000000..f95018552fca598057999f82cc43c262cf0b1085
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/super_resolution_sub_pixel_ID2541_for_TensorFlow2.X/README.md
@@ -0,0 +1,208 @@
+- [基本信息](#基本信息.md)
+- [概述](#概述.md)
+- [训练环境准备](#训练环境准备.md)
+- [快速上手](#快速上手.md)
+- [迁移学习指导](#迁移学习指导.md)
+- [高级参考](#高级参考.md)
+
+基本信息
+
+**发布者(Publisher):Huawei**
+
+**应用领域(Application Domain):Super Resolution**
+
+**版本(Version):1.1**
+
+**修改时间(Modified) :2022.04.21**
+
+**大小(Size):712K**
+
+**框架(Framework):TensorFlow_2.6.2**
+
+**模型格式(Model Format):ckpt**
+
+**精度(Precision):Mixed**
+
+**处理器(Processor):昇腾910**
+
+**应用级别(Categories):Research**
+
+**描述(Description):基于TensorFlow2.X框架的图像超分辨率重建网络训练代码**
+
+
+概述
+
+## 简述
+
+ 由Shi在2016年提出的ESPCN(Efficient Sub-Pixel CNN)是一种在给定低分辨率版本的情况下重建图像的高分辨率版本的网络模型。它利用高效的“亚像素卷积”层,学习一组图像放大滤波器。
+
+
+ - 参考论文:
+
+ https://arxiv.org/abs/1609.05158(https://arxiv.org/abs/1609.05158)
+
+ - 参考实现:
+ https://github.com/keras-team/keras-io/blob/master/examples/vision/super_resolution_sub_pixel.py(https://github.com/keras-team/keras-io/blob/master/examples/vision/super_resolution_sub_pixel.py)
+
+
+ - 适配昇腾 AI 处理器的实现:
+ skip
+
+ - 通过Git获取对应commit\_id的代码方法如下:
+ ```
+ git clone {repository_url} # 克隆仓库的代码
+ cd {repository_name} # 切换到模型的代码仓目录
+ git checkout {branch} # 切换到对应分支
+ git reset --hard {commit_id} # 代码设置到对应的commit_id
+ cd {code_path} # 切换到模型代码所在路径,若仓库下只有该模型,则无需切换
+ ```
+
+
+
+
+## 默认配置
+
+
+- 网络结构
+ - Interpolation,用简单的三次样条插值进行初步的上采样,然后进行学习非线性映射
+ - deconvolution,在最后的上采样层,通过学习最后的deconvolution layer。但deconvolution本质上是可以看做一种特殊的卷积,理论上后面要通过stack filters才能使得性能有更大的提升。
+ - 亚像素卷积sub-pixel Layer,跟常规的卷积层相比,其输出的特征通道数为r^2,其中r为缩放倍数
+
+- 训练超参(单卡):
+ - Batch size: 8
+ - crop_size: 300
+ - upscale_factor: 3
+ - Train epoch: 100
+
+
+## 支持特性
+
+| 特性列表 | 是否支持 |
+|-------|------|
+| 分布式训练 | 否 |
+| 混合精度 | 是 |
+| 数据并行 | 否 |
+
+## 混合精度训练
+
+昇腾910 AI处理器提供自动混合精度功能,可以针对全网中float32数据类型的算子,按照内置的优化策略,自动将部分float32的算子降低精度到float16,从而在精度损失很小的情况下提升系统性能并减少内存使用。
+
+## 开启混合精度
+相关代码示例。
+
+```
+ config_proto = tf.ConfigProto(allow_soft_placement=True)
+ custom_op = config_proto.graph_options.rewrite_options.custom_optimizers.add()
+ custom_op.name = 'NpuOptimizer'
+ custom_op.parameter_map["use_off_line"].b = True
+ custom_op.parameter_map["precision_mode"].s = tf.compat.as_bytes("allow_mix_precision")
+ config_proto.graph_options.rewrite_options.remapping = RewriterConfig.OFF
+ session_config = npu_config_proto(config_proto=config_proto)
+```
+
+训练环境准备
+
+- 硬件环境和运行环境准备请参见《[CANN软件安装指南](https://support.huawei.com/enterprise/zh/ascend-computing/cann-pid-251168373?category=installation-update)》
+- 运行以下命令安装依赖。
+```
+pip3 install requirements.txt
+```
+说明:依赖配置文件requirements.txt文件位于模型的根目录
+
+
+快速上手
+
+## 数据集准备
+
+1. 模型训练使用BSDS500数据集,该数据集包含200张训练图,100张验证图,200张测试图;所有真值用.mat文件保存,包含segmentation和boundaries,每张图片对应真值有五个,为5个标注的真值,训练时真值可采用平均值或者用来扩充数据,评测代码中会依次对这五个真值都做对比。
+2. 创建训练和验证数据集image_dataset_from_directory。
+3. 重新缩放图像以获取 [0, 1] 范围内的值。
+4. 裁剪和调整图像大小,将图像从 RGB 颜色空间转换为 YUV 颜色空间。
+
+## 模型训练
+- 单击“立即下载”,并选择合适的下载方式下载源码包。
+- 开始训练。
+
+ 1. 启动训练之前,首先要配置程序运行相关环境变量。
+
+ 环境变量配置信息参见:
+
+ [Ascend 910训练平台环境变量设置](https://gitee.com/ascend/modelzoo/wikis/Ascend%20910%E8%AE%AD%E7%BB%83%E5%B9%B3%E5%8F%B0%E7%8E%AF%E5%A2%83%E5%8F%98%E9%87%8F%E8%AE%BE%E7%BD%AE?sort_id=3148819)
+
+
+ 2. 单卡训练
+
+ 2.1 设置单卡训练参数(脚本位于super_resolution_sub_pixel_ID2541_for_TensorFlow2.X/test/train_full_1p.sh),示例如下。
+
+
+ ```
+ batch_size=8
+ #训练step
+ train_epochs=100
+ #训练epochs
+ ```
+
+
+
+ 2.2 单卡训练指令(super_resolution_sub_pixel_ID2541_for_TensorFlow2.X/test)
+
+ ```
+ 于终端中运行export ASCEND_DEVICE_ID=0 (0~7)以指定单卡训练时使用的卡
+ bash train_full_1p.sh --data_path=xx
+ 数据集应为h5类型,配置data_path时需指定为datasets这一层,例:--data_path=/home/datasets
+ ├─datasets
+ ├─BSR
+ ├─bench
+ ├─BSDS500
+ ├─documentation
+
+ ```
+
+迁移学习指导
+
+- 数据集准备。
+
+ 1. 获取数据。
+ 请参见“快速上手”中的数据集准备
+
+- 模型训练
+
+ 请参考“快速上手”章节
+
+高级参考
+
+## 脚本和示例代码
+
+ ├── README.md //说明文档
+ ├── requirements.txt //依赖
+ ├── modelzoo_level.txt //状态文件
+ ├── super_resolution_sub_pixel.py //网络结构定义脚本
+ ├── test
+ | |—— train_full_1p.sh //单卡训练脚本
+ | |—— train_performance_1p.sh //单卡训练脚本
+
+
+## 脚本参数
+
+```
+batch_size 训练batch_size
+epochs 训练epoch数
+precision_mode default="allow_mix_precision", type=str,help='the path to save over dump data'
+over_dump type=ast.literal_eval,help='if or not over detection, default is False'
+data_dump_flag type=ast.literal_eval,help='data dump flag, default is False'
+data_dump_step data dump step, default is 10
+profiling type=ast.literal_eval help='if or not profiling for performance debug, default is False'
+profiling_dump_path type=str, help='the path to save profiling data'
+over_dump_path type=str, help='the path to save over dump data'
+data_dump_path type=str, help='the path to save dump data'
+use_mixlist type=ast.literal_eval,help='use_mixlist flag, default is False'
+fusion_off_flag type=ast.literal_eval,help='fusion_off flag, default is False'
+mixlist_file type=str,help='mixlist file name, default is ops_info.json'
+fusion_off_file type=str,help='fusion_off file name, default is fusion_switch.cfg'
+auto_tune help='auto_tune flag, default is False'
+```
+
+## 训练过程
+
+通过“模型训练”中的训练指令启动单卡训练。
+将训练脚本(train_full_1p.sh)中的data_path设置为训练数据集的路径。具体的流程参见“模型训练”的示例。
diff --git a/TensorFlow2/built-in/keras_sample/super_resolution_sub_pixel_ID2541_for_TensorFlow2.X/README_BAK.md b/TensorFlow2/built-in/keras_sample/super_resolution_sub_pixel_ID2541_for_TensorFlow2.X/README_BAK.md
new file mode 100644
index 0000000000000000000000000000000000000000..2b7b82c436a90b383a4b9c915cab4c259ac75346
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/super_resolution_sub_pixel_ID2541_for_TensorFlow2.X/README_BAK.md
@@ -0,0 +1,91 @@
+## RL-Restore [[project page](http://mmlab.ie.cuhk.edu.hk/projects/RL-Restore/)][[paper](https://arxiv.org/abs/1804.03312)]
+
+:triangular_flag_on_post: Support arbitrary input size. Aug 25
+:triangular_flag_on_post: Add Python3 compatibility. Aug 6
+:triangular_flag_on_post: Training code is ready! Jun 15
+
+### Overview
+
+- Framework
+
+
+- Synthetic & real-world results
+
+
+
+
+
+### Prerequisite
+
+- [Anaconda](https://www.anaconda.com/download/) is highly recommended as you can easily adjust the environment setting.
+ ```
+ pip install opencv-python scipy tqdm h5py
+ ```
+
+- We have tested our code under the following settings:
+
+ | Python | TensorFlow | CUDA | cuDNN |
+ | :----: | :--------: | :--: | :---: |
+ | 2.7 | 1.3 | 8.0 | 5.1 |
+ | 3.5 | 1.4 | 8.0 | 5.1 |
+ | 3.6 | 1.10 | 9.0 | 7.0 |
+
+### Test
+- Start testing on synthetic dataset
+ ```
+ python main.py --dataset moderate
+ ```
+ > `dataset`: choose a test set among `mild`, `moderate` and `severe`
+
+- :heavy_exclamation_mark: Start testing on real-world data (support arbitrary input size)
+ ```
+ python main.py --dataset mine
+ ```
+
+ - You may put your own test images in `data/test/mine/`
+
+- Dataset
+
+ - All test sets can be downloaded at [Google Drive](https://drive.google.com/open?id=19z2s1e3zT8_1J9ZtsCOrzUSsrQahuINo) or [Baidu Cloud](https://pan.baidu.com/s/1RXTcfI-mne5YZh3myQcjzQ).
+
+ - Replace `test_images/` with the downloaded data and play with the whole dataset.
+
+- Naming rules
+
+ - Each saved image name refers to a selected toolchain. Please refer to my second reply in this [issue](https://github.com/yuke93/RL-Restore/issues/1).
+
+### Train
+- Download training images
+ - Download training images (down-sampled DIV2K images) at [Google Drive](https://drive.google.com/file/d/146mmYHcZeWnklQ_Sg7ltCrJVqjL_yB3K/view?usp=sharing) or [Baidu Cloud](https://pan.baidu.com/s/1CD-E5dUMsMswvCVQhe5PeQ).
+
+ - Move the downloaded file to `data/train/` and unzip.
+
+- Generate training data
+ - Run `data/train/generate_train.m` to generate training data in HDF5 format.
+
+ - You may generate multiple `.h5` files in `data/train/`
+
+- Let's train!
+
+ ```
+ python main.py --is_train True
+ ```
+
+ - When you observe `reward_sum` is increasing, it indicates training is going well.
+
+ - You can visualize reward increasing by TensorBoard.
+
+
+
+### Acknowledgement
+The DQN algorithm is modified from [DQN-tensorflow](https://github.com/devsisters/DQN-tensorflow).
+
+### Citation
+
+ @inproceedings{yu2018crafting,
+ author = {Yu, Ke and Dong, Chao and Lin, Liang and Loy, Chen Change},
+ title = {Crafting a Toolchain for Image Restoration by Deep Reinforcement Learning},
+ booktitle = {Proceedings of IEEE Conference on Computer Vision and Pattern Recognition},
+ pages={2443--2452},
+ year = {2018}
+ }
diff --git a/TensorFlow2/built-in/keras_sample/super_resolution_sub_pixel_ID2541_for_TensorFlow2.X/image_dataset.py b/TensorFlow2/built-in/keras_sample/super_resolution_sub_pixel_ID2541_for_TensorFlow2.X/image_dataset.py
new file mode 100644
index 0000000000000000000000000000000000000000..74fca2a1e38d2a3653484ba97fd04f3e36372817
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/super_resolution_sub_pixel_ID2541_for_TensorFlow2.X/image_dataset.py
@@ -0,0 +1,254 @@
+# Copyright 2020 The TensorFlow Authors. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ==============================================================================
+"""Keras image dataset loading utilities."""
+# pylint: disable=g-classes-have-attributes
+
+import numpy as np
+
+from tensorflow.python.data.ops import dataset_ops
+from tensorflow.python.keras.layers.preprocessing import image_preprocessing
+from tensorflow.python.keras.preprocessing import dataset_utils
+from tensorflow.python.keras.preprocessing import image as keras_image_ops
+from tensorflow.python.ops import image_ops
+from tensorflow.python.ops import io_ops
+from tensorflow.python.util.tf_export import keras_export
+
+
+ALLOWLIST_FORMATS = ('.bmp', '.gif', '.jpeg', '.jpg', '.png')
+
+
+@keras_export('keras.preprocessing.image_dataset_from_directory', v1=[])
+def image_dataset_from_directory_static(directory,
+ labels='inferred',
+ label_mode='int',
+ class_names=None,
+ color_mode='rgb',
+ batch_size=32,
+ image_size=(256, 256),
+ shuffle=True,
+ seed=None,
+ validation_split=None,
+ subset=None,
+ interpolation='bilinear',
+ follow_links=False,
+ smart_resize=False):
+ """Generates a `tf.data.Dataset` from image files in a directory.
+
+ If your directory structure is:
+
+ ```
+ main_directory/
+ ...class_a/
+ ......a_image_1.jpg
+ ......a_image_2.jpg
+ ...class_b/
+ ......b_image_1.jpg
+ ......b_image_2.jpg
+ ```
+
+ Then calling `image_dataset_from_directory(main_directory, labels='inferred')`
+ will return a `tf.data.Dataset` that yields batches of images from
+ the subdirectories `class_a` and `class_b`, together with labels
+ 0 and 1 (0 corresponding to `class_a` and 1 corresponding to `class_b`).
+
+ Supported image formats: jpeg, png, bmp, gif.
+ Animated gifs are truncated to the first frame.
+
+ Args:
+ directory: Directory where the data is located.
+ If `labels` is "inferred", it should contain
+ subdirectories, each containing images for a class.
+ Otherwise, the directory structure is ignored.
+ labels: Either "inferred"
+ (labels are generated from the directory structure),
+ None (no labels),
+ or a list/tuple of integer labels of the same size as the number of
+ image files found in the directory. Labels should be sorted according
+ to the alphanumeric order of the image file paths
+ (obtained via `os.walk(directory)` in Python).
+ label_mode:
+ - 'int': means that the labels are encoded as integers
+ (e.g. for `sparse_categorical_crossentropy` loss).
+ - 'categorical' means that the labels are
+ encoded as a categorical vector
+ (e.g. for `categorical_crossentropy` loss).
+ - 'binary' means that the labels (there can be only 2)
+ are encoded as `float32` scalars with values 0 or 1
+ (e.g. for `binary_crossentropy`).
+ - None (no labels).
+ class_names: Only valid if "labels" is "inferred". This is the explict
+ list of class names (must match names of subdirectories). Used
+ to control the order of the classes
+ (otherwise alphanumerical order is used).
+ color_mode: One of "grayscale", "rgb", "rgba". Default: "rgb".
+ Whether the images will be converted to
+ have 1, 3, or 4 channels.
+ batch_size: Size of the batches of data. Default: 32.
+ image_size: Size to resize images to after they are read from disk.
+ Defaults to `(256, 256)`.
+ Since the pipeline processes batches of images that must all have
+ the same size, this must be provided.
+ shuffle: Whether to shuffle the data. Default: True.
+ If set to False, sorts the data in alphanumeric order.
+ seed: Optional random seed for shuffling and transformations.
+ validation_split: Optional float between 0 and 1,
+ fraction of data to reserve for validation.
+ subset: One of "training" or "validation".
+ Only used if `validation_split` is set.
+ interpolation: String, the interpolation method used when resizing images.
+ Defaults to `bilinear`. Supports `bilinear`, `nearest`, `bicubic`,
+ `area`, `lanczos3`, `lanczos5`, `gaussian`, `mitchellcubic`.
+ follow_links: Whether to visits subdirectories pointed to by symlinks.
+ Defaults to False.
+ smart_resize: If True, the resizing function used will be
+ `tf.keras.preprocessing.image.smart_resize`, which preserves the aspect
+ ratio of the original image by using a mixture of resizing and cropping.
+ If False (default), the resizing function is `tf.image.resize`, which
+ does not preserve aspect ratio.
+
+ Returns:
+ A `tf.data.Dataset` object.
+ - If `label_mode` is None, it yields `float32` tensors of shape
+ `(batch_size, image_size[0], image_size[1], num_channels)`,
+ encoding images (see below for rules regarding `num_channels`).
+ - Otherwise, it yields a tuple `(images, labels)`, where `images`
+ has shape `(batch_size, image_size[0], image_size[1], num_channels)`,
+ and `labels` follows the format described below.
+
+ Rules regarding labels format:
+ - if `label_mode` is `int`, the labels are an `int32` tensor of shape
+ `(batch_size,)`.
+ - if `label_mode` is `binary`, the labels are a `float32` tensor of
+ 1s and 0s of shape `(batch_size, 1)`.
+ - if `label_mode` is `categorial`, the labels are a `float32` tensor
+ of shape `(batch_size, num_classes)`, representing a one-hot
+ encoding of the class index.
+
+ Rules regarding number of channels in the yielded images:
+ - if `color_mode` is `grayscale`,
+ there's 1 channel in the image tensors.
+ - if `color_mode` is `rgb`,
+ there are 3 channel in the image tensors.
+ - if `color_mode` is `rgba`,
+ there are 4 channel in the image tensors.
+ """
+ if labels not in ('inferred', None):
+ if not isinstance(labels, (list, tuple)):
+ raise ValueError(
+ '`labels` argument should be a list/tuple of integer labels, of '
+ 'the same size as the number of image files in the target '
+ 'directory. If you wish to infer the labels from the subdirectory '
+ 'names in the target directory, pass `labels="inferred"`. '
+ 'If you wish to get a dataset that only contains images '
+ '(no labels), pass `label_mode=None`.')
+ if class_names:
+ raise ValueError('You can only pass `class_names` if the labels are '
+ 'inferred from the subdirectory names in the target '
+ 'directory (`labels="inferred"`).')
+ if label_mode not in {'int', 'categorical', 'binary', None}:
+ raise ValueError(
+ '`label_mode` argument must be one of "int", "categorical", "binary", '
+ 'or None. Received: %s' % (label_mode,))
+ if labels is None or label_mode is None:
+ labels = None
+ label_mode = None
+ if color_mode == 'rgb':
+ num_channels = 3
+ elif color_mode == 'rgba':
+ num_channels = 4
+ elif color_mode == 'grayscale':
+ num_channels = 1
+ else:
+ raise ValueError(
+ '`color_mode` must be one of {"rbg", "rgba", "grayscale"}. '
+ 'Received: %s' % (color_mode,))
+ interpolation = image_preprocessing.get_interpolation(interpolation)
+ dataset_utils.check_validation_split_arg(
+ validation_split, subset, shuffle, seed)
+
+ if seed is None:
+ seed = np.random.randint(1e6)
+ image_paths, labels, class_names = dataset_utils.index_directory(
+ directory,
+ labels,
+ formats=ALLOWLIST_FORMATS,
+ class_names=class_names,
+ shuffle=shuffle,
+ seed=seed,
+ follow_links=follow_links)
+
+ if label_mode == 'binary' and len(class_names) != 2:
+ raise ValueError(
+ 'When passing `label_mode="binary", there must exactly 2 classes. '
+ 'Found the following classes: %s' % (class_names,))
+
+ image_paths, labels = dataset_utils.get_training_or_validation_split(
+ image_paths, labels, validation_split, subset)
+ if not image_paths:
+ raise ValueError('No images found.')
+
+ dataset = paths_and_labels_to_dataset(
+ image_paths=image_paths,
+ image_size=image_size,
+ num_channels=num_channels,
+ labels=labels,
+ label_mode=label_mode,
+ num_classes=len(class_names),
+ interpolation=interpolation,
+ smart_resize=smart_resize)
+ if shuffle:
+ # Shuffle locally at each iteration
+ dataset = dataset.shuffle(buffer_size=batch_size * 8, seed=seed)
+ dataset = dataset.batch(batch_size,drop_remainder=True)
+ # Users may need to reference `class_names`.
+ dataset.class_names = class_names
+ # Include file paths for images as attribute.
+ dataset.file_paths = image_paths
+ return dataset
+
+
+def paths_and_labels_to_dataset(image_paths,
+ image_size,
+ num_channels,
+ labels,
+ label_mode,
+ num_classes,
+ interpolation,
+ smart_resize=False):
+ """Constructs a dataset of images and labels."""
+ # TODO(fchollet): consider making num_parallel_calls settable
+ path_ds = dataset_ops.Dataset.from_tensor_slices(image_paths)
+ args = (image_size, num_channels, interpolation, smart_resize)
+ img_ds = path_ds.map(
+ lambda x: load_image(x, *args))
+ if label_mode:
+ label_ds = dataset_utils.labels_to_dataset(labels, label_mode, num_classes)
+ img_ds = dataset_ops.Dataset.zip((img_ds, label_ds))
+ return img_ds
+
+
+def load_image(path, image_size, num_channels, interpolation,
+ smart_resize=False):
+ """Load an image from a path and resize it."""
+ img = io_ops.read_file(path)
+ img = image_ops.decode_image(
+ img, channels=num_channels, expand_animations=False)
+ if smart_resize:
+ img = keras_image_ops.smart_resize(img, image_size,
+ interpolation=interpolation)
+ else:
+ img = image_ops.resize_images_v2(img, image_size, method=interpolation)
+ img.set_shape((image_size[0], image_size[1], num_channels))
+ return img
diff --git a/TensorFlow2/built-in/keras_sample/super_resolution_sub_pixel_ID2541_for_TensorFlow2.X/modelzoo_level.txt b/TensorFlow2/built-in/keras_sample/super_resolution_sub_pixel_ID2541_for_TensorFlow2.X/modelzoo_level.txt
new file mode 100644
index 0000000000000000000000000000000000000000..a829ab59b97a1022dd6fc33b59b7ae0d55009432
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/super_resolution_sub_pixel_ID2541_for_TensorFlow2.X/modelzoo_level.txt
@@ -0,0 +1,3 @@
+FuncStatus:OK
+PerfStatus:NOK
+PrecisionStatus:OK
\ No newline at end of file
diff --git a/TensorFlow2/built-in/keras_sample/super_resolution_sub_pixel_ID2541_for_TensorFlow2.X/requirements.txt b/TensorFlow2/built-in/keras_sample/super_resolution_sub_pixel_ID2541_for_TensorFlow2.X/requirements.txt
new file mode 100644
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
diff --git a/TensorFlow2/built-in/keras_sample/super_resolution_sub_pixel_ID2541_for_TensorFlow2.X/super_resolution_sub_pixel.py b/TensorFlow2/built-in/keras_sample/super_resolution_sub_pixel_ID2541_for_TensorFlow2.X/super_resolution_sub_pixel.py
new file mode 100644
index 0000000000000000000000000000000000000000..045f7a9cc2316d7158d2a163290a173a58fc5ae9
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/super_resolution_sub_pixel_ID2541_for_TensorFlow2.X/super_resolution_sub_pixel.py
@@ -0,0 +1,508 @@
+"""
+Title: Image Super-Resolution using an Efficient Sub-Pixel CNN
+Author: [Xingyu Long](https://github.com/xingyu-long)
+Date created: 2020/07/28
+Last modified: 2020/08/27
+Description: Implementing Super-Resolution using Efficient sub-pixel model on BSDS500.
+"""
+
+"""
+## Introduction
+
+ESPCN (Efficient Sub-Pixel CNN), proposed by [Shi, 2016](https://arxiv.org/abs/1609.05158)
+is a model that reconstructs a high-resolution version of an image given a low-resolution version.
+It leverages efficient "sub-pixel convolution" layers, which learns an array of
+image upscaling filters.
+
+In this code example, we will implement the model from the paper and train it on a small dataset,
+[BSDS500](https://www2.eecs.berkeley.edu/Research/Projects/CS/vision/grouping/resources.html).
+"""
+
+"""
+## Setup
+"""
+
+import npu_device
+import ast
+import argparse
+
+
+def init_arg():
+ parser = argparse.ArgumentParser()
+ parser.add_argument('--data_dir', type=str, default='datasets/BSR', help='dataset path')
+ parser.add_argument('--batch_size', type=int, default=8, help='batch_size')
+ parser.add_argument('--epochs', type=int, default=100, help='batch_size')
+ parser.add_argument('--precision_mode', default="allow_mix_precision", type=str,
+ help='the path to save over dump data')
+ parser.add_argument('--over_dump', dest='over_dump', type=ast.literal_eval,
+ help='if or not over detection, default is False')
+ parser.add_argument('--data_dump_flag', dest='data_dump_flag', type=ast.literal_eval,
+ help='data dump flag, default is False')
+ parser.add_argument('--data_dump_step', default="10",
+ help='data dump step, default is 10')
+ parser.add_argument('--profiling', dest='profiling', type=ast.literal_eval,
+ help='if or not profiling for performance debug, default is False')
+ parser.add_argument('--profiling_dump_path', default="/home/data", type=str, help='the path to save profiling data')
+ parser.add_argument('--over_dump_path', default="/home/data", type=str, help='the path to save over dump data')
+ parser.add_argument('--data_dump_path', default="/home/data", type=str, help='the path to save dump data')
+ parser.add_argument('--use_mixlist', dest='use_mixlist', type=ast.literal_eval,
+ help='use_mixlist flag, default is False')
+ parser.add_argument('--fusion_off_flag', dest='fusion_off_flag', type=ast.literal_eval,
+ help='fusion_off flag, default is False')
+ parser.add_argument('--mixlist_file', default="ops_info.json", type=str,
+ help='mixlist file name, default is ops_info.json')
+ parser.add_argument('--fusion_off_file', default="fusion_switch.cfg", type=str,
+ help='fusion_off file name, default is fusion_switch.cfg')
+ parser.add_argument('--auto_tune', dest='auto_tune', type=ast.literal_eval,
+ help='auto_tune flag, default is False')
+ parser.add_argument('--drop_remainder', dest='drop_remainder', type=ast.literal_eval,
+ help='drop_remainder flag, default is False')
+
+ return parser.parse_args()
+
+
+args = init_arg()
+
+
+def npu_config():
+ if args.data_dump_flag:
+ npu_device.global_options().dump_config.enable_dump = True
+ npu_device.global_options().dump_config.dump_path = args.data_dump_path
+ npu_device.global_options().dump_config.dump_step = args.data_dump_step
+ npu_device.global_options().dump_config.dump_mode = "all"
+
+ if args.over_dump:
+ npu_device.global_options().dump_config.enable_dump_debug = True
+ npu_device.global_options().dump_config.dump_path = args.over_dump_path
+ npu_device.global_options().dump_config.dump_debug_mode = "all"
+
+ if args.profiling:
+ npu_device.global_options().profiling_config.enable_profiling = True
+ profiling_options = '{"output":"' + args.profiling_dump_path + '", \
+ "training_trace":"on", \
+ "task_trace":"on", \
+ "aicpu":"on", \
+ "aic_metrics":"PipeUtilization",\
+ "fp_point":"", \
+ "bp_point":""}'
+ npu_device.global_options().profiling_config.profiling_options = profiling_options
+ npu_device.global_options().precision_mode = args.precision_mode
+ if args.use_mixlist and args.precision_mode == 'allow_mix_precision':
+ npu_device.global_options().modify_mixlist = "../configs/" + args.mixlist_file
+ if args.fusion_off_flag:
+ npu_device.global_options().fusion_switch_file = "../configs/" + args.fusion_off_file
+ if args.auto_tune:
+ npu_device.global_options().auto_tune_mode = "RL,GA"
+ npu_device.open().as_default()
+
+
+npu_config()
+
+import tensorflow as tf
+
+import os
+import math
+import numpy as np
+
+from tensorflow import keras
+from tensorflow.keras import layers
+from tensorflow.keras.preprocessing.image import load_img
+from tensorflow.keras.preprocessing.image import array_to_img
+from tensorflow.keras.preprocessing.image import img_to_array
+from tensorflow.keras.preprocessing import image_dataset_from_directory
+from image_dataset import image_dataset_from_directory_static
+
+from IPython.display import display
+
+
+"""
+## Load data: BSDS500 dataset
+
+### Download dataset
+
+We use the built-in `keras.utils.get_file` utility to retrieve the dataset.
+"""
+
+data_dir = args.data_dir + '/datasets/BSR'
+# dataset_url = "http://www.eecs.berkeley.edu/Research/Projects/CS/vision/grouping/BSR/BSR_bsds500.tgz"
+# data_dir = keras.utils.get_file(origin=dataset_url, fname="BSR", untar=True)
+root_dir = os.path.join(data_dir, "BSDS500/data")
+
+"""
+We create training and validation datasets via `image_dataset_from_directory`.
+"""
+
+crop_size = 300
+upscale_factor = 3
+input_size = crop_size // upscale_factor
+batch_size = args.batch_size
+
+if args.drop_remainder:
+ train_ds = image_dataset_from_directory_static(
+ root_dir,
+ batch_size=batch_size,
+ image_size=(crop_size, crop_size),
+ validation_split=0.2,
+ subset="training",
+ seed=1337,
+ label_mode=None,
+ )
+
+ valid_ds = image_dataset_from_directory_static(
+ root_dir,
+ batch_size=batch_size,
+ image_size=(crop_size, crop_size),
+ validation_split=0.2,
+ subset="validation",
+ seed=1337,
+ label_mode=None,
+ )
+else:
+ train_ds = image_dataset_from_directory(
+ root_dir,
+ batch_size=batch_size,
+ image_size=(crop_size, crop_size),
+ validation_split=0.2,
+ subset="training",
+ seed=1337,
+ label_mode=None,
+ )
+
+ valid_ds = image_dataset_from_directory(
+ root_dir,
+ batch_size=batch_size,
+ image_size=(crop_size, crop_size),
+ validation_split=0.2,
+ subset="validation",
+ seed=1337,
+ label_mode=None,
+ )
+
+"""
+We rescale the images to take values in the range [0, 1].
+"""
+
+
+def scaling(input_image):
+ input_image = input_image / 255.0
+ return input_image
+
+
+# Scale from (0, 255) to (0, 1)
+train_ds = train_ds.map(scaling)
+valid_ds = valid_ds.map(scaling)
+
+"""
+Let's visualize a few sample images:
+"""
+
+#for batch in train_ds.take(1):
+# for img in batch:
+# display(array_to_img(img))
+
+"""
+We prepare a dataset of test image paths that we will use for
+visual evaluation at the end of this example.
+"""
+
+dataset = os.path.join(root_dir, "images")
+test_path = os.path.join(dataset, "test")
+
+test_img_paths = sorted(
+ [
+ os.path.join(test_path, fname)
+ for fname in os.listdir(test_path)
+ if fname.endswith(".jpg")
+ ]
+)
+
+"""
+## Crop and resize images
+
+Let's process image data.
+First, we convert our images from the RGB color space to the
+[YUV colour space](https://en.wikipedia.org/wiki/YUV).
+
+For the input data (low-resolution images),
+we crop the image, retrieve the `y` channel (luninance),
+and resize it with the `area` method (use `BICUBIC` if you use PIL).
+We only consider the luminance channel
+in the YUV color space because humans are more sensitive to
+luminance change.
+
+For the target data (high-resolution images), we just crop the image
+and retrieve the `y` channel.
+"""
+
+
+# Use TF Ops to process.
+def process_input(input, input_size, upscale_factor):
+ input = tf.image.rgb_to_yuv(input)
+ last_dimension_axis = len(input.shape) - 1
+ y, u, v = tf.split(input, 3, axis=last_dimension_axis)
+ return tf.image.resize(y, [input_size, input_size], method="area")
+
+
+def process_target(input):
+ input = tf.image.rgb_to_yuv(input)
+ last_dimension_axis = len(input.shape) - 1
+ y, u, v = tf.split(input, 3, axis=last_dimension_axis)
+ return y
+
+
+train_ds = train_ds.map(
+ lambda x: (process_input(x, input_size, upscale_factor), process_target(x))
+)
+
+train_ds = train_ds.prefetch(buffer_size=32)
+valid_ds = valid_ds.map(
+ lambda x: (process_input(x, input_size, upscale_factor), process_target(x))
+)
+valid_ds = valid_ds.prefetch(buffer_size=32)
+
+"""
+for batch in train_ds.take(1):
+ for img in batch[0]:
+ display(array_to_img(img))
+ for img in batch[1]:
+ display(array_to_img(img))
+"""
+
+def get_model(upscale_factor=3, channels=1):
+ conv_args = {
+ "activation": "relu",
+ "kernel_initializer": "Orthogonal",
+ "padding": "same",
+ }
+ inputs = keras.Input(shape=(None, None, channels))
+ x = layers.Conv2D(64, 5, **conv_args)(inputs)
+ x = layers.Conv2D(64, 3, **conv_args)(x)
+ x = layers.Conv2D(32, 3, **conv_args)(x)
+ x = layers.Conv2D(channels * (upscale_factor ** 2), 3, **conv_args)(x)
+ outputs = tf.nn.depth_to_space(x, upscale_factor)
+
+ return keras.Model(inputs, outputs)
+
+
+import matplotlib.pyplot as plt
+from mpl_toolkits.axes_grid1.inset_locator import zoomed_inset_axes
+from mpl_toolkits.axes_grid1.inset_locator import mark_inset
+import PIL
+
+
+def plot_results(img, prefix, title):
+ img_array = img_to_array(img)
+ img_array = img_array.astype("float32") / 255.0
+
+ # Create a new figure with a default 111 subplot.
+ fig, ax = plt.subplots()
+ im = ax.imshow(img_array[::-1], origin="lower")
+
+ plt.title(title)
+ # zoom-factor: 2.0, location: upper-left
+ axins = zoomed_inset_axes(ax, 2, loc=2)
+ axins.imshow(img_array[::-1], origin="lower")
+
+ # Specify the limits.
+ x1, x2, y1, y2 = 200, 300, 100, 200
+ # Apply the x-limits.
+ axins.set_xlim(x1, x2)
+ # Apply the y-limits.
+ axins.set_ylim(y1, y2)
+
+ plt.yticks(visible=False)
+ plt.xticks(visible=False)
+
+ # Make the line.
+ mark_inset(ax, axins, loc1=1, loc2=3, fc="none", ec="blue")
+ plt.savefig("./output/" + str(prefix) + "-" + title + ".png")
+ plt.show()
+
+
+def get_lowres_image(img, upscale_factor):
+ return img.resize(
+ (img.size[0] // upscale_factor, img.size[1] // upscale_factor),
+ PIL.Image.BICUBIC,
+ )
+
+
+def upscale_image(model, img):
+ """Predict the result based on input image and restore the image as RGB."""
+ ycbcr = img.convert("YCbCr")
+ y, cb, cr = ycbcr.split()
+ y = img_to_array(y)
+ y = y.astype("float32") / 255.0
+
+ input = np.expand_dims(y, axis=0)
+ out = model.predict(input)
+
+ out_img_y = out[0]
+ out_img_y *= 255.0
+
+ # Restore the image in RGB color space.
+ out_img_y = out_img_y.clip(0, 255)
+ out_img_y = out_img_y.reshape((np.shape(out_img_y)[0], np.shape(out_img_y)[1]))
+ out_img_y = PIL.Image.fromarray(np.uint8(out_img_y), mode="L")
+ out_img_cb = cb.resize(out_img_y.size, PIL.Image.BICUBIC)
+ out_img_cr = cr.resize(out_img_y.size, PIL.Image.BICUBIC)
+ out_img = PIL.Image.merge("YCbCr", (out_img_y, out_img_cb, out_img_cr)).convert(
+ "RGB"
+ )
+ return out_img
+
+
+"""
+## Define callbacks to monitor training
+
+The `ESPCNCallback` object will compute and display
+the [PSNR](https://en.wikipedia.org/wiki/Peak_signal-to-noise_ratio) metric.
+This is the main metric we use to evaluate super-resolution performance.
+"""
+
+
+class ESPCNCallback(keras.callbacks.Callback):
+ def __init__(self):
+ super(ESPCNCallback, self).__init__()
+ self.test_img = get_lowres_image(load_img(test_img_paths[0]), upscale_factor)
+
+ # Store PSNR value in each epoch.
+ def on_epoch_begin(self, epoch, logs=None):
+ self.psnr = []
+
+ def on_epoch_end(self, epoch, logs=None):
+ print("Mean PSNR for epoch: %.2f" % (np.mean(self.psnr)))
+ if epoch % 20 == 0:
+ prediction = upscale_image(self.model, self.test_img)
+ # plot_results(prediction, "epoch-" + str(epoch), "prediction")
+
+ def on_test_batch_end(self, batch, logs=None):
+ self.psnr.append(10 * math.log10(1 / logs["loss"]))
+
+
+import time
+
+
+class TimeHistory(tf.keras.callbacks.Callback):
+ def __init__(self, batch_size, log_steps, initial_step=0):
+ self.batch_size = batch_size
+ super(TimeHistory, self).__init__()
+ self.steps_before_epoch = initial_step
+ self.last_log_step = initial_step
+ self.log_steps = log_steps
+ self.steps_in_epoch = 0
+ self.start_time = None
+
+ @property
+ def global_steps(self):
+ """The current 1-indexed global step."""
+ return self.steps_before_epoch + self.steps_in_epoch
+
+ def on_epoch_begin(self, epoch, logs=None):
+ if not self.start_time:
+ self.start_time = time.time()
+ self.epoch_start = time.time()
+
+ def on_batch_begin(self, batch, logs=None):
+ if not self.start_time:
+ self.start_time = time.time()
+
+ def on_batch_end(self, batch, logs=None):
+ self.steps_in_epoch = batch + 1
+ steps_since_last_log = self.global_steps - self.last_log_step
+ if steps_since_last_log >= self.log_steps:
+ now = time.time()
+ elapsed_time = now - self.start_time
+ steps_per_second = steps_since_last_log / elapsed_time
+ examples_per_second = steps_per_second * self.batch_size
+ print(
+ 'TimeHistory: %.2f seconds, %.2f examples/second between steps %d '
+ 'and %d' % (elapsed_time, examples_per_second, self.last_log_step,
+ self.global_steps), flush=True)
+ self.last_log_step = self.global_steps
+ self.start_time = None
+
+ def on_epoch_end(self, epoch, logs=None):
+ epoch_run_time = time.time() - self.epoch_start
+ self.steps_before_epoch += self.steps_in_epoch
+ self.steps_in_epoch = 0
+
+
+"""
+Define `ModelCheckpoint` and `EarlyStopping` callbacks.
+"""
+
+early_stopping_callback = keras.callbacks.EarlyStopping(monitor="loss", patience=10)
+
+"""
+checkpoint_filepath = "./ckpt/checkpoint"
+
+model_checkpoint_callback = keras.callbacks.ModelCheckpoint(
+ filepath=checkpoint_filepath,
+ save_weights_only=True,
+ monitor="loss",
+ mode="min",
+ save_best_only=True,
+)
+"""
+model = get_model(upscale_factor=upscale_factor, channels=1)
+model.summary()
+
+callbacks = [ESPCNCallback(), early_stopping_callback, TimeHistory(batch_size, 10)] # , model_checkpoint_callback]
+loss_fn = keras.losses.MeanSquaredError()
+optimizer = keras.optimizers.Adam(learning_rate=0.001)
+
+"""
+## Train the model
+"""
+
+epochs = args.epochs
+model.compile(optimizer=optimizer, loss=loss_fn)
+start_time = time.time()
+model.fit(
+ train_ds, epochs=epochs, callbacks=callbacks, validation_data=valid_ds, verbose=2
+)
+
+Average_Duration = time.time() - start_time
+print(f'{args.epochs} Epoch: {Average_Duration / args.epochs} s/epoch')
+
+# save model
+# model.save_weights(checkpoint_filepath)
+# The model weights (that are considered the best) are loaded into the model.
+# model.load_weights(checkpoint_filepath)
+
+"""
+## Run model prediction and plot the results
+
+Let's compute the reconstructed version of a few images and save the results.
+"""
+
+total_bicubic_psnr = 0.0
+total_test_psnr = 0.0
+
+for index, test_img_path in enumerate(test_img_paths[50:60]):
+ img = load_img(test_img_path)
+ lowres_input = get_lowres_image(img, upscale_factor)
+ w = lowres_input.size[0] * upscale_factor
+ h = lowres_input.size[1] * upscale_factor
+ highres_img = img.resize((w, h))
+ prediction = upscale_image(model, lowres_input)
+ lowres_img = lowres_input.resize((w, h))
+ lowres_img_arr = img_to_array(lowres_img)
+ highres_img_arr = img_to_array(highres_img)
+ predict_img_arr = img_to_array(prediction)
+ bicubic_psnr = tf.image.psnr(lowres_img_arr, highres_img_arr, max_val=255)
+ test_psnr = tf.image.psnr(predict_img_arr, highres_img_arr, max_val=255)
+
+ total_bicubic_psnr += bicubic_psnr
+ total_test_psnr += test_psnr
+
+ print(
+ "PSNR of low resolution image and high resolution image is %.4f" % bicubic_psnr
+ )
+ print("PSNR of predict and high resolution is %.4f" % test_psnr)
+ plot_results(lowres_img, index, "lowres")
+ plot_results(highres_img, index, "highres")
+ plot_results(prediction, index, "prediction")
+
+print("Avg. PSNR of lowres images is %.4f" % (total_bicubic_psnr / 10))
+print("Avg. PSNR of reconstructions is %.4f" % (total_test_psnr / 10))
diff --git a/TensorFlow2/built-in/keras_sample/super_resolution_sub_pixel_ID2541_for_TensorFlow2.X/test/train_full_1p.sh b/TensorFlow2/built-in/keras_sample/super_resolution_sub_pixel_ID2541_for_TensorFlow2.X/test/train_full_1p.sh
new file mode 100644
index 0000000000000000000000000000000000000000..22e70688dc908a3ecd16d0824a57acb81ecc351f
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/super_resolution_sub_pixel_ID2541_for_TensorFlow2.X/test/train_full_1p.sh
@@ -0,0 +1,186 @@
+#!/bin/bash
+
+cur_path=`pwd`/../
+#失败用例打屏
+#export ASCEND_SLOG_PRINT_TO_STDOUT=1
+
+#基础参数,需要模型审视修改
+#Batch Size
+batch_size=8
+#网络名称,同目录名称
+Network="super_resolution_sub_pixel_ID2541_for_TensorFlow2.X"
+#Device数量,单卡默认为1
+RANK_SIZE=1
+#训练epoch,可选
+train_epochs=100
+#训练step
+#train_steps=5
+#学习率
+#learning_rate=1e-4
+#ckpt_path=""
+#参数配置
+data_path=""
+#work_dir="$cur_path/estimator_working_dir"
+#export_path="$cur_path/outputs/models/000001-first_generation"
+############维测参数##############
+precision_mode="allow_mix_precision"
+#维持参数,以下不需要修改
+over_dump=False
+if [[ $over_dump == True ]];then
+ over_dump_path=$cur_path/test/overflow_dump #此处cur_path为代码根目录
+ mkdir -p ${over_dump_path}
+fi
+data_dump_flag=False
+data_dump_step="10"
+profiling=False
+use_mixlist=False
+mixlist_file="ops_info.json"
+fusion_off_flag=False
+fusion_off_file="fusion_switch.cfg"
+auto_tune=False
+############维测参数##############
+
+if [[ $1 == --help || $1 == --h ]];then
+ echo "usage:./train_performance_1p.sh --data_path=$data_path"
+ exit 1
+fi
+
+############维测参数##############
+for para in $*
+do
+ if [[ $para == --precision_mode* ]];then
+ precision_mode=`echo ${para#*=}`
+ elif [[ $para == --over_dump* ]];then
+ over_dump=`echo ${para#*=}`
+ over_dump_path=${cur_path}/test/output/overflow_dump
+ mkdir -p ${over_dump_path}
+ elif [[ $para == --data_dump_flag* ]];then
+ data_dump_flag=`echo ${para#*=}`
+ data_dump_path=${cur_path}/test/output/data_dump
+ mkdir -p ${data_dump_path}
+ elif [[ $para == --data_dump_step* ]];then
+ data_dump_step=`echo ${para#*=}`
+ elif [[ $para == --profiling* ]];then
+ profiling=`echo ${para#*=}`
+ profiling_dump_path=${cur_path}/test/output/profiling
+ mkdir -p ${profiling_dump_path}
+ elif [[ $para == --data_path* ]];then
+ data_path=`echo ${para#*=}`
+ elif [[ $para == --use_mixlist* ]];then
+ use_mixlist=`echo ${para#*=}`
+ elif [[ $para == --mixlist_file* ]];then
+ mixlist_file=`echo ${para#*=}`
+ elif [[ $para == --fusion_off_flag* ]];then
+ fusion_off_flag=`echo ${para#*=}`
+ elif [[ $para == --fusion_off_file* ]];then
+ fusion_off_file=`echo ${para#*=}`
+ elif [[ $para == --auto_tune* ]];then
+ auto_tune=`echo ${para#*=}`
+
+ fi
+done
+############维测参数##############
+
+if [[ $data_path == "" ]];then
+ echo "[Error] para \"data_path\" must be config"
+ exit 1
+fi
+
+cd $cur_path/
+mkdir output
+mkdir ckpt
+
+##############执行训练##########
+if [ -d $cur_path/test/output ];then
+ rm -rf $cur_path/test/output/$ASCEND_DEVICE_ID
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+else
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+fi
+wait
+
+
+start=$(date +%s)
+nohup python3 super_resolution_sub_pixel.py \
+ --data_dir=$data_path \
+ --epochs=$train_epochs \
+ --batch_size=$batch_size \
+ --precision_mode=${precision_mode} \
+ --over_dump=${over_dump} \
+ --over_dump_path=${over_dump_path} \
+ --data_dump_flag=${data_dump_flag} \
+ --data_dump_step=${data_dump_step} \
+ --data_dump_path=${data_dump_path} \
+ --profiling=${profiling} \
+ --use_mixlist=${use_mixlist} \
+ --fusion_off_flag=${fusion_off_flag} \
+ --mixlist_file=${mixlist_file} \
+ --fusion_off_file=${fusion_off_file} \
+ --profiling_dump_path=${profiling_dump_path} \
+ --auto_tune=${auto_tune} > $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 &
+wait
+end=$(date +%s)
+e2e_time=$(( $end - $start ))
+
+
+#结果打印,不需要修改
+echo "------------------ Final result ------------------"
+#输出性能FPS,需要模型审视修改
+FPS=`grep TimeHistory $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log| tail -n +2|awk '{print $4}'|awk '{sum+=$1} END {print"",sum/NR}'|sed s/[[:space:]]//g`
+wait
+TrainingTime=`awk 'BEGIN{printf "%.2f\n",'${batch_size}'/'${FPS}'}'`
+
+#cat $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log |grep val_loss|awk '{print $3}' >> $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt
+#ActualLoss=`awk 'END {print $1}' $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt`
+train_accuracy=`cat $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|grep PSNR|awk '{print $6}'|tail -1`
+#echo "Final Performance ms/step : $average_perf"
+echo "Final Training Duration sec : $e2e_time"
+
+###下面字段用于冒烟看护
+BatchSize=${batch_size}
+#设备类型,自动获取
+DeviceType=`uname -m`
+#用例名称,自动获取
+CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc'
+
+#steps="50"
+#time=`cat $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|grep val_loss|awk '{print $3}'|tail -n1 |awk -F 's' '{print $1}'`
+#step_per_s=`awk 'BEGIN{printf "%2f\n",'${steps}'/'${time}'}'`
+#FPS=`awk 'BEGIN{printf "%.2f\n",'${batch_size}'*'${step_per_s}'}'`
+
+echo "Final Performance images/sec : $FPS"
+
+##获取性能数据,不需要修改
+#吞吐量
+ActualFPS=${FPS}
+
+#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视
+
+cat $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log |grep loss|awk '{print $6}'|sed s/[[:space:]]//g > $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt
+
+#最后一个迭代loss值,不需要修改
+ActualLoss=`awk 'END {print $1}' $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt`
+##获取错误信息
+#系统错误信息
+#ModelStatus="图执行FAIL"
+#error_msg="EZ3002"
+#判断错误信息是否和历史状态一致,此处无需修改
+#error_msg="Graph engine process graph failed: EZ3002: Optype \[Conv2DBackpropFilter\] of Ops kernel"
+#Status=`grep "${error_msg}" $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|wc -l`
+#DTS单号或者issue链接
+#DTS_Number="DTS2021090622224"
+
+echo "Network = ${Network}" > $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "RankSize = ${RANK_SIZE}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "BatchSize = ${BatchSize}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "DeviceType = ${DeviceType}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "CaseName = ${CaseName}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualFPS = ${FPS}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainingTime = ${TrainingTime}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualLoss = ${ActualLoss}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+#echo "ModelStatus = ${ModelStatus}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+#echo "DTS_Number = ${DTS_Number}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+#echo "Status = ${Status}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+#echo "error_msg = ${error_msg}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
\ No newline at end of file
diff --git a/TensorFlow2/built-in/keras_sample/super_resolution_sub_pixel_ID2541_for_TensorFlow2.X/test/train_performance_1p.sh b/TensorFlow2/built-in/keras_sample/super_resolution_sub_pixel_ID2541_for_TensorFlow2.X/test/train_performance_1p.sh
new file mode 100644
index 0000000000000000000000000000000000000000..b15fdedbab617f0e360e5bf23bb9dc5bcf17304b
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/super_resolution_sub_pixel_ID2541_for_TensorFlow2.X/test/train_performance_1p.sh
@@ -0,0 +1,187 @@
+#!/bin/bash
+
+cur_path=`pwd`/../
+#失败用例打屏
+#export ASCEND_SLOG_PRINT_TO_STDOUT=1
+
+#基础参数,需要模型审视修改
+#Batch Size
+batch_size=8
+#网络名称,同目录名称
+Network="super_resolution_sub_pixel_ID2541_for_TensorFlow2.X"
+#Device数量,单卡默认为1
+RANK_SIZE=1
+#训练epoch,可选
+train_epochs=2
+#训练step
+#train_steps=5
+#学习率
+#learning_rate=1e-4
+#ckpt_path=""
+#参数配置
+data_path=""
+#work_dir="$cur_path/estimator_working_dir"
+#export_path="$cur_path/outputs/models/000001-first_generation"
+############维测参数##############
+precision_mode="allow_mix_precision"
+#维持参数,以下不需要修改
+over_dump=False
+if [[ $over_dump == True ]];then
+ over_dump_path=$cur_path/test/overflow_dump #此处cur_path为代码根目录
+ mkdir -p ${over_dump_path}
+fi
+data_dump_flag=False
+data_dump_step="10"
+profiling=False
+use_mixlist=False
+mixlist_file="ops_info.json"
+fusion_off_flag=False
+fusion_off_file="fusion_switch.cfg"
+auto_tune=False
+############维测参数##############
+
+if [[ $1 == --help || $1 == --h ]];then
+ echo "usage:./train_performance_1p.sh --data_path=$data_path"
+ exit 1
+fi
+
+############维测参数##############
+for para in $*
+do
+ if [[ $para == --precision_mode* ]];then
+ precision_mode=`echo ${para#*=}`
+ elif [[ $para == --over_dump* ]];then
+ over_dump=`echo ${para#*=}`
+ over_dump_path=${cur_path}/test/output/overflow_dump
+ mkdir -p ${over_dump_path}
+ elif [[ $para == --data_dump_flag* ]];then
+ data_dump_flag=`echo ${para#*=}`
+ data_dump_path=${cur_path}/test/output/data_dump
+ mkdir -p ${data_dump_path}
+ elif [[ $para == --data_dump_step* ]];then
+ data_dump_step=`echo ${para#*=}`
+ elif [[ $para == --profiling* ]];then
+ profiling=`echo ${para#*=}`
+ profiling_dump_path=${cur_path}/test/output/profiling
+ mkdir -p ${profiling_dump_path}
+ elif [[ $para == --data_path* ]];then
+ data_path=`echo ${para#*=}`
+ elif [[ $para == --use_mixlist* ]];then
+ use_mixlist=`echo ${para#*=}`
+ elif [[ $para == --mixlist_file* ]];then
+ mixlist_file=`echo ${para#*=}`
+ elif [[ $para == --fusion_off_flag* ]];then
+ fusion_off_flag=`echo ${para#*=}`
+ elif [[ $para == --fusion_off_file* ]];then
+ fusion_off_file=`echo ${para#*=}`
+ elif [[ $para == --auto_tune* ]];then
+ auto_tune=`echo ${para#*=}`
+
+ fi
+done
+############维测参数##############
+
+if [[ $data_path == "" ]];then
+ echo "[Error] para \"data_path\" must be config"
+ exit 1
+fi
+
+cd $cur_path/
+mkdir output
+mkdir ckpt
+
+##############执行训练##########
+if [ -d $cur_path/test/output ];then
+ rm -rf $cur_path/test/output/$ASCEND_DEVICE_ID
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+else
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+fi
+wait
+
+
+start=$(date +%s)
+nohup python3 super_resolution_sub_pixel.py \
+ --data_dir=$data_path \
+ --epochs=$train_epochs \
+ --batch_size=$batch_size \
+ --precision_mode=${precision_mode} \
+ --over_dump=${over_dump} \
+ --over_dump_path=${over_dump_path} \
+ --data_dump_flag=${data_dump_flag} \
+ --data_dump_step=${data_dump_step} \
+ --data_dump_path=${data_dump_path} \
+ --profiling=${profiling} \
+ --use_mixlist=${use_mixlist} \
+ --fusion_off_flag=${fusion_off_flag} \
+ --mixlist_file=${mixlist_file} \
+ --fusion_off_file=${fusion_off_file} \
+ --profiling_dump_path=${profiling_dump_path} \
+ --auto_tune=${auto_tune} \
+ --drop_remainder=False > $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 &
+wait
+end=$(date +%s)
+e2e_time=$(( $end - $start ))
+
+
+#结果打印,不需要修改
+echo "------------------ Final result ------------------"
+#输出性能FPS,需要模型审视修改
+FPS=`grep TimeHistory $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log| tail -n +2|awk '{print $4}'|awk '{sum+=$1} END {print"",sum/NR}'|sed s/[[:space:]]//g`
+wait
+TrainingTime=`awk 'BEGIN{printf "%.2f\n",'${batch_size}'/'${FPS}'}'`
+
+#cat $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log |grep val_loss|awk '{print $3}' >> $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt
+#ActualLoss=`awk 'END {print $1}' $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt`
+#train_accuracy=`cat $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|grep PSNR|grep epoch|awk '{print $5}'|tail -n1`
+#echo "Final Performance ms/step : $average_perf"
+echo "Final Training Duration sec : $e2e_time"
+
+###下面字段用于冒烟看护
+BatchSize=${batch_size}
+#设备类型,自动获取
+DeviceType=`uname -m`
+#用例名称,自动获取
+CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf'
+
+#steps="50"
+#time=`cat $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|grep val_loss|awk '{print $3}'|tail -n1 |awk -F 's' '{print $1}'`
+#step_per_s=`awk 'BEGIN{printf "%2f\n",'${steps}'/'${time}'}'`
+#FPS=`awk 'BEGIN{printf "%.2f\n",'${batch_size}'*'${step_per_s}'}'`
+
+echo "Final Performance images/sec : $FPS"
+
+##获取性能数据,不需要修改
+#吞吐量
+ActualFPS=${FPS}
+
+#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视
+
+cat $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log |grep loss|awk '{print $6}'|sed s/[[:space:]]//g > $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt
+
+#最后一个迭代loss值,不需要修改
+ActualLoss=`awk 'END {print $1}' $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt`
+##获取错误信息
+#系统错误信息
+#ModelStatus="图执行FAIL"
+#error_msg="EZ3002"
+#判断错误信息是否和历史状态一致,此处无需修改
+#error_msg="Graph engine process graph failed: EZ3002: Optype \[Conv2DBackpropFilter\] of Ops kernel"
+#Status=`grep "${error_msg}" $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|wc -l`
+#DTS单号或者issue链接
+#DTS_Number="DTS2021090622224"
+
+echo "Network = ${Network}" > $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "RankSize = ${RANK_SIZE}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "BatchSize = ${BatchSize}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "DeviceType = ${DeviceType}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "CaseName = ${CaseName}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualFPS = ${FPS}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainingTime = ${TrainingTime}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+#echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualLoss = ${ActualLoss}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+#echo "ModelStatus = ${ModelStatus}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+#echo "DTS_Number = ${DTS_Number}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+#echo "Status = ${Status}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+#echo "error_msg = ${error_msg}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
\ No newline at end of file
diff --git a/TensorFlow2/built-in/keras_sample/super_resolution_sub_pixel_ID2541_for_TensorFlow2.X/test/train_performance_1p_static.sh b/TensorFlow2/built-in/keras_sample/super_resolution_sub_pixel_ID2541_for_TensorFlow2.X/test/train_performance_1p_static.sh
new file mode 100644
index 0000000000000000000000000000000000000000..8adbcb65c68cf1ba461a7ad75b1b010f0151b9e5
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/super_resolution_sub_pixel_ID2541_for_TensorFlow2.X/test/train_performance_1p_static.sh
@@ -0,0 +1,187 @@
+#!/bin/bash
+
+cur_path=`pwd`/../
+#失败用例打屏
+#export ASCEND_SLOG_PRINT_TO_STDOUT=1
+
+#基础参数,需要模型审视修改
+#Batch Size
+batch_size=8
+#网络名称,同目录名称
+Network="super_resolution_sub_pixel_ID2541_for_TensorFlow2.X"
+#Device数量,单卡默认为1
+RANK_SIZE=1
+#训练epoch,可选
+train_epochs=2
+#训练step
+#train_steps=5
+#学习率
+#learning_rate=1e-4
+#ckpt_path=""
+#参数配置
+data_path=""
+#work_dir="$cur_path/estimator_working_dir"
+#export_path="$cur_path/outputs/models/000001-first_generation"
+############维测参数##############
+precision_mode="allow_mix_precision"
+#维持参数,以下不需要修改
+over_dump=False
+if [[ $over_dump == True ]];then
+ over_dump_path=$cur_path/test/overflow_dump #此处cur_path为代码根目录
+ mkdir -p ${over_dump_path}
+fi
+data_dump_flag=False
+data_dump_step="10"
+profiling=False
+use_mixlist=False
+mixlist_file="ops_info.json"
+fusion_off_flag=False
+fusion_off_file="fusion_switch.cfg"
+auto_tune=False
+############维测参数##############
+
+if [[ $1 == --help || $1 == --h ]];then
+ echo "usage:./train_performance_1p.sh --data_path=$data_path"
+ exit 1
+fi
+
+############维测参数##############
+for para in $*
+do
+ if [[ $para == --precision_mode* ]];then
+ precision_mode=`echo ${para#*=}`
+ elif [[ $para == --over_dump* ]];then
+ over_dump=`echo ${para#*=}`
+ over_dump_path=${cur_path}/test/output/overflow_dump
+ mkdir -p ${over_dump_path}
+ elif [[ $para == --data_dump_flag* ]];then
+ data_dump_flag=`echo ${para#*=}`
+ data_dump_path=${cur_path}/test/output/data_dump
+ mkdir -p ${data_dump_path}
+ elif [[ $para == --data_dump_step* ]];then
+ data_dump_step=`echo ${para#*=}`
+ elif [[ $para == --profiling* ]];then
+ profiling=`echo ${para#*=}`
+ profiling_dump_path=${cur_path}/test/output/profiling
+ mkdir -p ${profiling_dump_path}
+ elif [[ $para == --data_path* ]];then
+ data_path=`echo ${para#*=}`
+ elif [[ $para == --use_mixlist* ]];then
+ use_mixlist=`echo ${para#*=}`
+ elif [[ $para == --mixlist_file* ]];then
+ mixlist_file=`echo ${para#*=}`
+ elif [[ $para == --fusion_off_flag* ]];then
+ fusion_off_flag=`echo ${para#*=}`
+ elif [[ $para == --fusion_off_file* ]];then
+ fusion_off_file=`echo ${para#*=}`
+ elif [[ $para == --auto_tune* ]];then
+ auto_tune=`echo ${para#*=}`
+
+ fi
+done
+############维测参数##############
+
+if [[ $data_path == "" ]];then
+ echo "[Error] para \"data_path\" must be config"
+ exit 1
+fi
+
+cd $cur_path/
+mkdir output
+mkdir ckpt
+
+##############执行训练##########
+if [ -d $cur_path/test/output ];then
+ rm -rf $cur_path/test/output/$ASCEND_DEVICE_ID
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+else
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+fi
+wait
+
+
+start=$(date +%s)
+nohup python3 super_resolution_sub_pixel.py \
+ --data_dir=$data_path \
+ --epochs=$train_epochs \
+ --batch_size=$batch_size \
+ --drop_remainder=True \
+ --precision_mode=${precision_mode} \
+ --over_dump=${over_dump} \
+ --over_dump_path=${over_dump_path} \
+ --data_dump_flag=${data_dump_flag} \
+ --data_dump_step=${data_dump_step} \
+ --data_dump_path=${data_dump_path} \
+ --profiling=${profiling} \
+ --use_mixlist=${use_mixlist} \
+ --fusion_off_flag=${fusion_off_flag} \
+ --mixlist_file=${mixlist_file} \
+ --fusion_off_file=${fusion_off_file} \
+ --profiling_dump_path=${profiling_dump_path} \
+ --auto_tune=${auto_tune} > $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 &
+wait
+end=$(date +%s)
+e2e_time=$(( $end - $start ))
+
+
+#结果打印,不需要修改
+echo "------------------ Final result ------------------"
+#输出性能FPS,需要模型审视修改
+FPS=`grep TimeHistory $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log| tail -n 3|awk '{print $4}'|awk '{sum+=$1} END {print"",sum/NR}'|sed s/[[:space:]]//g`
+wait
+TrainingTime=`awk 'BEGIN{printf "%.2f\n",'${batch_size}'/'${FPS}'}'`
+
+#cat $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log |grep val_loss|awk '{print $3}' >> $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt
+#ActualLoss=`awk 'END {print $1}' $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt`
+#train_accuracy=`cat $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|grep PSNR|grep epoch|awk '{print $5}'|tail -n1`
+#echo "Final Performance ms/step : $average_perf"
+echo "Final Training Duration sec : $e2e_time"
+
+###下面字段用于冒烟看护
+BatchSize=${batch_size}
+#设备类型,自动获取
+DeviceType=`uname -m`
+#用例名称,自动获取
+CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf'
+
+#steps="50"
+#time=`cat $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|grep val_loss|awk '{print $3}'|tail -n1 |awk -F 's' '{print $1}'`
+#step_per_s=`awk 'BEGIN{printf "%2f\n",'${steps}'/'${time}'}'`
+#FPS=`awk 'BEGIN{printf "%.2f\n",'${batch_size}'*'${step_per_s}'}'`
+
+echo "Final Performance images/sec : $FPS"
+
+##获取性能数据,不需要修改
+#吞吐量
+ActualFPS=${FPS}
+
+#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视
+
+cat $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log |grep val_loss|awk '{print $6}'|sed s/[[:space:]]//g > $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt
+
+#最后一个迭代loss值,不需要修改
+ActualLoss=`awk 'END {print $1}' $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt`
+##获取错误信息
+#系统错误信息
+#ModelStatus="图执行FAIL"
+#error_msg="EZ3002"
+#判断错误信息是否和历史状态一致,此处无需修改
+#error_msg="Graph engine process graph failed: EZ3002: Optype \[Conv2DBackpropFilter\] of Ops kernel"
+#Status=`grep "${error_msg}" $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|wc -l`
+#DTS单号或者issue链接
+#DTS_Number="DTS2021090622224"
+
+echo "Network = ${Network}" > $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "RankSize = ${RANK_SIZE}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "BatchSize = ${BatchSize}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "DeviceType = ${DeviceType}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "CaseName = ${CaseName}_static" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualFPS = ${FPS}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainingTime = ${TrainingTime}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+#echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualLoss = ${ActualLoss}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+#echo "ModelStatus = ${ModelStatus}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+#echo "DTS_Number = ${DTS_Number}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+#echo "Status = ${Status}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+#echo "error_msg = ${error_msg}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
\ No newline at end of file
diff --git a/TensorFlow2/built-in/keras_sample/text_classification_with_transformer_ID2563_for_TensorFlow2.X/LICENSE b/TensorFlow2/built-in/keras_sample/text_classification_with_transformer_ID2563_for_TensorFlow2.X/LICENSE
new file mode 100644
index 0000000000000000000000000000000000000000..ab652360b248f2947c2e3ccf306ca128660ea731
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/text_classification_with_transformer_ID2563_for_TensorFlow2.X/LICENSE
@@ -0,0 +1,284 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+------------------
+Files: third_party/compute_library/...
+
+MIT License
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+
+------------------
+Files: ACKNOWLEDGEMENTS
+LICENSE
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+------------------
+Files: third_party/hexagon
+
+Copyright (c) 2016-2019, The Linux Foundation. All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted (subject to the limitations in the
+disclaimer below) provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+
+ * Neither the name of The Linux Foundation nor the names of its
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
+GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
+HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/TensorFlow2/built-in/keras_sample/text_classification_with_transformer_ID2563_for_TensorFlow2.X/README.md b/TensorFlow2/built-in/keras_sample/text_classification_with_transformer_ID2563_for_TensorFlow2.X/README.md
new file mode 100644
index 0000000000000000000000000000000000000000..367d52351ff34edc42e27e25b6d180bc89141b91
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/text_classification_with_transformer_ID2563_for_TensorFlow2.X/README.md
@@ -0,0 +1,192 @@
+- [基本信息](#基本信息.md)
+- [概述](#概述.md)
+- [训练环境准备](#训练环境准备.md)
+- [快速上手](#快速上手.md)
+- [迁移学习指导](#迁移学习指导.md)
+- [高级参考](#高级参考.md)
+基本信息
+
+**发布者(Publisher):Huawei**
+
+**应用领域(Application Domain): Natural Lannguage Processing**
+
+**版本(Version):1.1**
+
+**修改时间(Modified) :2022.02.16**
+
+**大小(Size):90M**
+
+**框架(Framework):TensorFlow_2.4.1**
+
+**模型格式(Model Format):ckpt**
+
+**精度(Precision):Mixed**
+
+**处理器(Processor):昇腾910**
+
+**应用级别(Categories):Research**
+
+**描述(Description):使用transformer进行文本分类**
+
+概述
+
+ Transformer是一个能够高效并行训练的序列到序列模型,该模型分为编码器(Encoder)和解码器(Decoder)两个部分,主要由多头注意力(Multi-head Attention)网络和前向(FeedForward)网络组成, 同时集成了位置编码(Position Encoding)、残差连接(Residual Connection)、层归一化(Layer Normalization)等多种技术。相比循环和卷积网络,注意力网络可以同时对任意两个输入位置的向量进行运算,提高了计算效率。 在包括翻译的多个自然语言处理任务上,该网络都取得了显著的提升
+
+- 参考论文:
+
+ [Ashish Vaswani, Noam Shazeer, Niki Parmar, JakobUszkoreit, Llion Jones, Aidan N Gomez, Ł ukaszKaiser, and Illia Polosukhin. 2017. Attention is all you need. In NIPS 2017, pages 5998–6008.](https://arxiv.org/abs/1706.03762)
+
+- 参考实现:
+
+ https://github.com/keras-team/keras-io/blob/master/examples/nlp/text_classification_with_transformer.py
+
+- 适配昇腾 AI 处理器的实现:
+
+ https://gitee.com/ascend/modelzoo/tree/master/built-in/TensorFlow2/Research/nlp/text_classification_with_transformer_ID2563_for_TensorFlow2.X
+
+- 通过Git获取对应commit_id的代码方法如下:
+
+ git clone {repository_url} # 克隆仓库的代码
+ cd {repository_name} # 切换到模型的代码仓目录
+ git checkout {branch} # 切换到对应分支
+ git reset --hard {commit_id} # 代码设置到对应的commit_id
+ cd {code_path} # 切换到模型代码所在路径,若仓库下只有该模型,则无需切换
+
+## 默认配置
+
+- 主要训练超参(单卡):
+ - batch_size: 32
+ - epochs: 2
+ - lr: 0.001
+
+## 支持特性
+
+| 特性列表 | 是否支持 |
+| ---------- | -------- |
+| 分布式训练 | 否 |
+| 混合精度 | 是 |
+| 数据并行 | 否 |
+
+## 混合精度训练
+
+昇腾910 AI处理器提供自动混合精度功能,可以针对全网中float32数据类型的算子,按照内置的优化策略,自动将部分float32的算子降低精度到float16,从而在精度损失很小的情况下提升系统性能并减少内存使用。
+
+## 开启混合精度
+
+
+```
+ npu_device.global_options().precision_mode='allow_mix_precision'
+ npu_device.open().as_default())
+```
+
+
+训练环境准备
+
+1. 硬件环境准备请参见各硬件产品文档"[驱动和固件安装升级指南]( https://support.huawei.com/enterprise/zh/category/ai-computing-platform-pid-1557196528909)"。需要在硬件设备上安装与CANN版本配套的固件与驱动。
+2. 宿主机上需要安装Docker并登录[Ascend Hub中心](https://ascendhub.huawei.com/#/detail?name=ascend-tensorflow-arm)获取镜像。
+
+ 当前模型支持的镜像列表如[表1](#zh-cn_topic_0000001074498056_table1519011227314)所示。
+
+ **表 1** 镜像列表
+
+
+ 镜像名称
+ |
+ 镜像版本
+ |
+ 配套CANN版本
+ |
+
+
+
+ |
+ 21.0.2
+ |
+ 5.0.2
+ |
+
+
+
+
+
+快速上手
+
+## 数据集准备
+
+1. 用户需自行下载keras.datasets.imdb训练数据集。
+
+## 模型训练
+
+- 单击“立即下载”,并选择合适的下载方式下载源码包。
+- 开始训练
+
+ 1. 启动训练之前,首先要配置程序运行相关环境变量。
+
+ 环境变量配置信息参见:
+
+ [Ascend 910训练平台环境变量设置](https://gitee.com/ascend/modelzoo/wikis/Ascend%20910%E8%AE%AD%E7%BB%83%E5%B9%B3%E5%8F%B0%E7%8E%AF%E5%A2%83%E5%8F%98%E9%87%8F%E8%AE%BE%E7%BD%AE?sort_id=3148819)
+
+ 2. 单卡训练
+
+ 2.1 配置train_full_1p.sh脚本中`data_path`(脚本路径text_classification_with_transformer_ID2563_for_TensorFlow2.X/test/train_full_1p.sh),请用户根据实际路径配置,数据集参数如下所示:
+
+ --data_path=/path/to/dataset/imdb.npz
+
+ 2.2 1p指令如下:
+
+ bash train_full_1p.sh --data_path=/path/to/dataset/imdb.npz
+
+
+迁移学习指导
+
+- 数据集准备。
+
+ 1. 获取数据。
+ 请参见“快速上手”中的数据集准备。
+
+- 模型训练。
+
+ 参考“模型训练”中训练步骤。
+
+- 模型评估。
+
+ 参考“模型训练”中验证步骤。
+
+高级参考
+
+## 脚本和示例代码
+
+```
+text_classification_with_transformer_ID2563_for_TensorFlow2.X/
+├── LICENSE
+├── modelzoo_level.txt
+├── README.md
+├── requirements.txt
+├── test
+│ ├── train_full_1p.sh
+│ ├── train_performance_1p.sh
+└── text_classification_with_transformer.py
+
+```
+
+## 脚本参数
+
+```
+--data_dir 训练数据集路径
+--epochs 训练epoch设置
+--batch_size 训练bs设置
+```
+
+## 训练过程
+
+1. 通过“模型训练”中的训练指令启动单卡训练。
+2. 将训练脚本(train_full_1p.sh)中的data_path设置为训练数据集的路径。具体的流程参见“模型训练”的示例。
+3. 模型存储路径为“curpath/output/ASCEND_DEVICE_ID”,包括训练的log文件。
+4. 以多卡训练为例,loss信息在文件curpath/output/{ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log中。
+
+## 推理/验证过程
+
+```
+ NA
+
+```
diff --git a/TensorFlow2/built-in/keras_sample/text_classification_with_transformer_ID2563_for_TensorFlow2.X/modelzoo_level.txt b/TensorFlow2/built-in/keras_sample/text_classification_with_transformer_ID2563_for_TensorFlow2.X/modelzoo_level.txt
new file mode 100644
index 0000000000000000000000000000000000000000..0b49b4fb26c2694a86567bea1b462e7dcb03cc31
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/text_classification_with_transformer_ID2563_for_TensorFlow2.X/modelzoo_level.txt
@@ -0,0 +1,3 @@
+FuncStatus:OK
+PerfStatus:OK
+PrecisionStatus:OK
\ No newline at end of file
diff --git a/TensorFlow2/built-in/keras_sample/text_classification_with_transformer_ID2563_for_TensorFlow2.X/npu_convert_dropout.py b/TensorFlow2/built-in/keras_sample/text_classification_with_transformer_ID2563_for_TensorFlow2.X/npu_convert_dropout.py
new file mode 100644
index 0000000000000000000000000000000000000000..95f8689ce4da26c08f18a0fcb49c42eb7f1c8b06
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/text_classification_with_transformer_ID2563_for_TensorFlow2.X/npu_convert_dropout.py
@@ -0,0 +1,54 @@
+#!/usr/bin/env python3
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============================================================================
+# Copyright 2021 Huawei Technologies Co., Ltd
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+from keras import backend
+from keras.utils import control_flow_util
+from keras.layers.core import Dropout
+from tensorflow.python.ops import array_ops
+from tensorflow.python.ops import nn
+import npu_ops
+
+def dropout_call(self, inputs, training=None):
+ """Make Keras Dropout to execute NPU dropout"""
+ if training is None:
+ training = backend.learning_phase()
+
+ def dropped_inputs():
+ return npu_ops.dropout(
+ inputs,
+ noise_shape=self._get_noise_shape(inputs),
+ seed=self.seed,
+ keep_prob=1 - self.rate)
+
+ output = control_flow_util.smart_cond(training,
+ dropped_inputs,
+ lambda : array_ops.identity(inputs))
+
+ return output
+
+Dropout.call = dropout_call
diff --git a/TensorFlow2/built-in/keras_sample/text_classification_with_transformer_ID2563_for_TensorFlow2.X/npu_ops.py b/TensorFlow2/built-in/keras_sample/text_classification_with_transformer_ID2563_for_TensorFlow2.X/npu_ops.py
new file mode 100644
index 0000000000000000000000000000000000000000..fa6f8f211c19e1bce9d78a90c7c11b6121efdbd7
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/text_classification_with_transformer_ID2563_for_TensorFlow2.X/npu_ops.py
@@ -0,0 +1,256 @@
+# Copyright 2016 The TensorFlow Authors. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ==============================================================================
+# ============================================================================
+# Copyright 2021 Huawei Technologies Co., Ltd
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============================================================================
+
+"""Ops for collective operations implemented using hccl."""
+from __future__ import absolute_import
+from __future__ import division
+from __future__ import print_function
+
+
+import numbers
+from tensorflow.python.ops import array_ops
+from tensorflow.python.framework import tensor_shape
+from tensorflow.python.framework import ops
+from tensorflow.python.eager import context
+
+from npu_device import gen_npu_ops
+
+
+DEFAULT_GRAPH_SEED = 87654321
+_MAXINT32 = 2**31 - 1
+def LARSV2(input_weight,
+ input_grad,
+ weight_decay,
+ learning_rate,
+ hyperpara=0.001,
+ epsilon=0.00001,
+ use_clip=False,
+ name=None):
+ if context.executing_eagerly():
+ raise RuntimeError("tf.LARSV2() is not compatible with "
+ "eager execution.")
+
+ return gen_npu_ops.lars_v2(input_weight=input_weight,
+ input_grad=input_grad,
+ weight_decay=weight_decay,
+ learning_rate=learning_rate,
+ hyperpara=hyperpara,
+ epsilon=epsilon,
+ use_clip=use_clip,
+ name=name)
+
+
+def _truncate_seed(seed):
+ return seed % _MAXINT32 # Truncate to fit into 32-bit integer
+
+def get_seed(op_seed):
+ global_seed = ops.get_default_graph().seed
+
+ if global_seed is not None:
+ if op_seed is None:
+ op_seed = ops.get_default_graph()._last_id
+
+ seeds = _truncate_seed(global_seed), _truncate_seed(op_seed)
+ else:
+ if op_seed is not None:
+ seeds = DEFAULT_GRAPH_SEED, _truncate_seed(op_seed)
+ else:
+ seeds = None, None
+ # Avoid (0, 0) as the C++ ops interpret it as nondeterminism, which would
+ # be unexpected since Python docs say nondeterminism is (None, None).
+ if seeds == (0, 0):
+ return (0, _MAXINT32)
+ return seeds
+
+def _get_noise_shape(x, noise_shape):
+ # If noise_shape is none return immediately.
+ if noise_shape is None:
+ return array_ops.shape(x)
+
+ try:
+ # Best effort to figure out the intended shape.
+ # If not possible, let the op to handle it.
+ # In eager mode exception will show up.
+ noise_shape_ = tensor_shape.as_shape(noise_shape)
+ except (TypeError, ValueError):
+ return noise_shape
+
+ if x.shape.dims is not None and len(x.shape.dims) == len(noise_shape_.dims):
+ new_dims = []
+ for i, dim in enumerate(x.shape.dims):
+ if noise_shape_.dims[i].value is None and dim.value is not None:
+ new_dims.append(dim.value)
+ else:
+ new_dims.append(noise_shape_.dims[i].value)
+ return tensor_shape.TensorShape(new_dims)
+
+ return noise_shape
+
+def dropout(x, keep_prob, noise_shape=None, seed=None, name=None):
+ """The gradient for `gelu`.
+
+ Args:
+ x: A tensor with type is float.
+ keep_prob: A tensor, float, rate of every element reserved.
+ noise_shape: A 1-D tensor, with type int32, shape of keep/drop what random
+ generated.
+ seed: Random seed.
+ name: Layer name.
+
+ Returns:
+ A tensor.
+ """
+ if context.executing_eagerly():
+ raise RuntimeError("tf.dropout() is not compatible with "
+ "eager execution.")
+ x = ops.convert_to_tensor(x, name="x")
+ if not x.dtype.is_floating:
+ raise ValueError("x has to be a floating point tensor since it's going to"
+ " be scaled. Got a %s tensor instead." % x.dtype)
+ if isinstance(keep_prob, numbers.Real) and not 0 < keep_prob <= 1:
+ raise ValueError("keep_prob must be a scalar tensor or a float in the "
+ "range (0, 1], got %g" % keep_prob)
+ if isinstance(keep_prob, float) and keep_prob == 1:
+ return x
+ seed, seed2 = get_seed(seed)
+ noise_shape = _get_noise_shape(x, noise_shape)
+ gen_out = gen_npu_ops.drop_out_gen_mask(noise_shape, keep_prob, seed, seed2, name)
+ result = gen_npu_ops.drop_out_do_mask(x, gen_out, keep_prob, name)
+ return result
+
+@ops.RegisterGradient("DropOutDoMask")
+def _DropOutDoMaskGrad(op, grad):
+ result = gen_npu_ops.drop_out_do_mask(grad, op.inputs[1], op.inputs[2])
+ return [result, None, None]
+
+def basic_lstm_cell(x, h, c, w, b, keep_prob, forget_bias, state_is_tuple,
+ activation, name=None):
+ if context.executing_eagerly():
+ raise RuntimeError("tf.basic_lstm_cell() is not compatible with "
+ "eager execution.")
+ x = ops.convert_to_tensor(x, name="x")
+ h = ops.convert_to_tensor(h, name="h")
+ c = ops.convert_to_tensor(c, name="c")
+ w = ops.convert_to_tensor(w, name="w")
+ b = ops.convert_to_tensor(b, name="b")
+ result = gen_npu_ops.basic_lstm_cell(x, h, c, w, b, keep_prob, forget_bias, state_is_tuple,
+ activation, name)
+ return result
+
+@ops.RegisterGradient("BasicLSTMCell")
+def basic_lstm_cell_grad(op, dct, dht, dit, djt, dft, dot, dtanhct):
+
+ dgate, dct_1 = gen_npu_ops.basic_lstm_cell_c_state_grad(op.inputs[2], dht, dct, op.outputs[2], op.outputs[3], op.outputs[4], op.outputs[5], op.outputs[6], forget_bias=op.get_attr("forget_bias"), activation=op.get_attr("activation"))
+ dw, db = gen_npu_ops.basic_lstm_cell_weight_grad(op.inputs[0], op.inputs[1], dgate)
+ dxt, dht = gen_npu_ops.basic_lstm_cell_input_grad(dgate, op.inputs[3], keep_prob=op.get_attr("keep_prob"))
+
+ return [dxt, dht, dct_1, dw, db]
+
+def adam_apply_one_assign(input0, input1, input2, input3, input4,
+ mul0_x, mul1_x, mul2_x, mul3_x, add2_y, name=None):
+ if context.executing_eagerly():
+ raise RuntimeError("tf.adam_apply_one_assign() is not compatible with "
+ "eager execution.")
+ result = gen_npu_ops.adam_apply_one_assign(input0, input1, input2, input3, input4,
+ mul0_x, mul1_x, mul2_x, mul3_x, add2_y,name)
+ return result
+
+def adam_apply_one_with_decay_assign(input0, input1, input2, input3, input4,
+ mul0_x, mul1_x, mul2_x, mul3_x, mul4_x, add2_y, name=None):
+ if context.executing_eagerly():
+ raise RuntimeError("tf.adam_apply_one_with_decay_assign() is not compatible with "
+ "eager execution.")
+ result = gen_npu_ops.adam_apply_one_with_decay_assign(input0, input1, input2, input3, input4,
+ mul0_x, mul1_x, mul2_x, mul3_x, mul4_x, add2_y, name)
+ return result
+
+@ops.RegisterGradient("DynamicGruV2")
+def dynamic_gru_v2_grad(op, dy, doutput_h, dupdate, dreset, dnew, dhidden_new):
+ (x, weight_input, weight_hidden, bias_input, bias_hidden, seq_length, init_h) = op.inputs
+ (y, output_h, update, reset, new, hidden_new) = op.outputs
+ (dw_input, dw_hidden, db_input, db_hidden, dx, dh_prev) = gen_npu_ops.dynamic_gru_v2_grad(x, weight_input, weight_hidden, y, init_h, output_h, dy, doutput_h, update, reset, new, hidden_new, direction=op.get_attr("direction"), cell_depth=op.get_attr("cell_depth"), keep_prob=op.get_attr("keep_prob"), cell_clip=op.get_attr("cell_clip"), num_proj=op.get_attr("num_proj"), time_major=op.get_attr("time_major"), gate_order=op.get_attr("gate_order"), reset_after=op.get_attr("reset_after"))
+
+ return (dx, dw_input, dw_hidden, db_input, db_hidden, seq_length, dh_prev)
+
+@ops.RegisterGradient("DynamicRnn")
+def dynamic_rnn_grad(op, dy, dh, dc, di, dj, df, do, dtanhc):
+ (x, w, b, seq_length, init_h, init_c) = op.inputs
+ (y, output_h, output_c, i, j, f, o, tanhc) = op.outputs
+ (dw, db, dx, dh_prev, dc_prev) = gen_npu_ops.dynamic_rnn_grad(x, w, b, y, init_h[-1], init_c[-1], output_h, output_c, dy, dh[-1], dc[-1], i, j, f, o, tanhc, cell_type=op.get_attr("cell_type"), direction=op.get_attr("direction"), cell_depth=op.get_attr("cell_depth"), use_peephole=op.get_attr("use_peephole"), keep_prob=op.get_attr("keep_prob"), cell_clip=op.get_attr("cell_clip"), num_proj=op.get_attr("num_proj"), time_major=op.get_attr("time_major"), forget_bias=op.get_attr("forget_bias"))
+
+ return (dx, dw, db, seq_length, dh_prev, dc_prev)
+
+def lamb_apply_optimizer_assign(input0,input1,input2,input3,mul0_x,mul1_x,mul2_x,
+ mul3_x,add2_y,steps,do_use_weight,weight_decay_rate,name=None):
+ if context.executing_eagerly():
+ raise RuntimeError("tf.lamb_apply_optimizer_assign() is not compatible with eager execution")
+ update,nextv,nextm=gen_npu_ops.lamb_apply_optimizer_assign(input0,input1,input2,input3,mul0_x,mul1_x,mul2_x,
+ mul3_x,add2_y,steps,do_use_weight,weight_decay_rate,name)
+ return update,nextv,nextm
+
+def lamb_apply_weight_assign(input0,input1,input2,input3,input4,name=None):
+ if context.executing_eagerly():
+ raise RuntimeError("tf.lamb_apply_weight_assign() is not compatible with eager execution")
+ result = gen_npu_ops.lamb_apply_weight_assign(input0,input1,input2,input3,input4,name)
+ return result
+
+def dropout_v3(x, keep_prob, noise_shape=None, seed=None, name=None):
+ """ The gradient for gelu
+
+ Args:
+ x: A tensor with type is float
+ keep_prob: A tensor, float, rate of every element reserved
+ noise_shape: A 1-D tensor, with type int32, shape of keep/drop what random generated.
+ seed: Random seed.
+ name: Layer name.
+
+ Returns:
+ A tensor.
+ """
+ x = ops.convert_to_tensor(x,name="x")
+ if not x.dtype.is_floating:
+ raise ValueError("x has to be a floating point tensor since it's going to be scaled. Got a %s tensor instead." % x.dtype)
+
+ if isinstance(keep_prob,numbers.Real) and not 0 < keep_prob <=1:
+ raise ValueError("Keep_prob must be a scalar tensor or a float in the range (0,1], got %g" % keep_prob)
+
+ if isinstance(keep_prob,float) and keep_prob==1:
+ return x
+
+ seed, seed2 = get_seed(seed)
+ noise_shape = _get_noise_shape(x,noise_shape)
+ gen_out = gen_npu_ops.drop_out_gen_mask_v3(noise_shape,keep_prob,seed,seed2,name)
+ result = gen_npu_ops.drop_out_do_mask_v3(x, gen_out, keep_prob, name)
+ return result
+
+@ops.RegisterGradient("DropOutDoMaskV3")
+def _DropOutDoMaskV3Grad(op,grad):
+ result = gen_npu_ops.drop_out_do_mask_v3(grad, op.inputs[1], op.inputs[2])
+ return [result, None, None]
\ No newline at end of file
diff --git a/TensorFlow2/built-in/keras_sample/text_classification_with_transformer_ID2563_for_TensorFlow2.X/requirements.txt b/TensorFlow2/built-in/keras_sample/text_classification_with_transformer_ID2563_for_TensorFlow2.X/requirements.txt
new file mode 100644
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
diff --git a/TensorFlow2/built-in/keras_sample/text_classification_with_transformer_ID2563_for_TensorFlow2.X/test/train_full_1p.sh b/TensorFlow2/built-in/keras_sample/text_classification_with_transformer_ID2563_for_TensorFlow2.X/test/train_full_1p.sh
new file mode 100644
index 0000000000000000000000000000000000000000..bb931cf8d54bf90e3b2b6689f1bac265910372c8
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/text_classification_with_transformer_ID2563_for_TensorFlow2.X/test/train_full_1p.sh
@@ -0,0 +1,178 @@
+#!/bin/bash
+
+#当前路径,不需要修改
+cur_path=`pwd`/../
+
+#集合通信参数,不需要修改
+export RANK_SIZE=1
+export JOB_ID=10087
+RANK_ID_START=$ASCEND_DEVICE_ID
+
+# 数据集路径,保持为空,不需要修改
+data_path=""
+
+#基础参数,需要模型审视修改
+#网络名称,同目录名称
+Network="text_classification_with_transformer_ID2563_for_TensorFlow2.X"
+#训练epoch
+train_epochs=2
+#训练batch_size
+batch_size=32
+
+#维测参数,precision_mode需要模型审视修改
+precision_mode="allow_mix_precision"
+#维持参数,以下不需要修改
+over_dump=False
+if [[ $over_dump == True ]];then
+ over_dump_path=$cur_path/test/overflow_dump
+fi
+data_dump_flag=False
+data_dump_step="10"
+profiling=False
+use_mixlist=False
+mixlist_file="ops_info.json"
+fusion_off_flag=False
+fusion_off_file="fusion_switch.cfg"
+
+# 帮助信息,不需要修改
+if [[ $1 == --help || $1 == -h ]];then
+ echo"usage:./train_performance_1p.sh "
+ echo " "
+ echo "parameter explain:
+ --precision_mode precision mode(allow_fp32_to_fp16/force_fp16/must_keep_origin_dtype/allow_mix_precision)
+ --over_dump if or not over detection, default is False
+ --data_dump_flag data dump flag, default is False
+ --data_dump_step data dump step, default is 10
+ --profiling if or not profiling for performance debug, default is False
+ --data_path source data of training
+ -h/--help show help message
+ "
+ exit 1
+fi
+
+#参数校验,不需要修改
+for para in $*
+do
+ if [[ $para == --precision_mode* ]];then
+ precision_mode=`echo ${para#*=}`
+ elif [[ $para == --over_dump* ]];then
+ over_dump=`echo ${para#*=}`
+ over_dump_path=${cur_path}/output/overflow_dump
+ mkdir -p ${over_dump_path}
+ elif [[ $para == --data_dump_flag* ]];then
+ data_dump_flag=`echo ${para#*=}`
+ data_dump_path=${cur_path}/output/data_dump
+ mkdir -p ${data_dump_path}
+ elif [[ $para == --data_dump_step* ]];then
+ data_dump_step=`echo ${para#*=}`
+ elif [[ $para == --profiling* ]];then
+ profiling=`echo ${para#*=}`
+ profiling_dump_path=${cur_path}/output/profiling
+ mkdir -p ${profiling_dump_path}
+ elif [[ $para == --data_path* ]];then
+ data_path=`echo ${para#*=}`
+ elif [[ $para == --use_mixlist* ]];then
+ use_mixlist=`echo ${para#*=}`
+ elif [[ $para == --mixlist_file* ]];then
+ mixlist_file=`echo ${para#*=}`
+ elif [[ $para == --fusion_off_flag* ]];then
+ fusion_off_flag=`echo ${para#*=}`
+ elif [[ $para == --fusion_off_file* ]];then
+ fusion_off_file=`echo ${para#*=}`
+ fi
+done
+
+#校验是否传入data_path,不需要修改
+if [[ $data_path == "" ]];then
+ echo "[Error] para \"data_path\" must be confing"
+ exit 1
+fi
+
+#训练开始时间,不需要修改
+start_time=$(date +%s)
+
+#进入训练脚本目录,需要模型审视修改
+cd $cur_path/
+
+for((RANK_ID=$RANK_ID_START;RANK_ID<$((RANK_SIZE+RANK_ID_START));RANK_ID++));
+do
+ #设置环境变量,不需要修改
+ echo "Device ID: $ASCEND_DEVICE_ID"
+ export RANK_ID=$RANK_ID
+
+ if [ -d $cur_path/test/output ];then
+ rm -rf $cur_path/test/output/*
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+ else
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+ fi
+
+
+
+ #执行训练脚本,以下传参不需要修改,其他需要模型审视修改
+ nohup python3 text_classification_with_transformer.py --data_dir=$data_path \
+ --epochs=$train_epochs \
+ --batch_size=$batch_size \
+ --precision_mode=${precision_mode} \
+ --over_dump=${over_dump} \
+ --over_dump_path=${over_dump_path} \
+ --data_dump_flag=${data_dump_flag} \
+ --data_dump_step=${data_dump_step} \
+ --data_dump_path=${data_dump_path} \
+ --profiling=${profiling} \
+ --use_mixlist=${use_mixlist} \
+ --fusion_off_flag=${fusion_off_flag} \
+ --mixlist_file=${mixlist_file} \
+ --fusion_off_file=${fusion_off_file} \
+ --profiling_dump_path=${profiling_dump_path} > ${cur_path}/test/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 &
+done
+wait
+
+#conda deactivate
+#训练结束时间,不需要修改
+end_time=$(date +%s)
+e2e_time=$(( $end_time - $start_time ))
+
+#结果打印,不需要修改
+echo "------------------ Final result ------------------"
+#输出性能FPS,需要模型审视修改
+wait
+FPS=`grep imgs/s $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | awk 'END {print $4}'`
+TrainingTime=`awk 'BEGIN{printf "%.2f\n",'${batch_size}'*1000/'${FPS}'}'`
+#打印,不需要修改
+echo "Final Performance images/sec : $FPS"
+
+#输出训练精度,需要模型审视修改
+train_accuracy=`grep " val_accuracy" $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | awk 'END {print $NF}'`
+#打印,不需要修改
+echo "Final Train Accuracy : ${train_accuracy}"
+
+
+#精度看护结果汇总
+#训练用例信息,不需要修改
+BatchSize=${batch_size}
+DeviceType=`uname -m`
+CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}p_acc
+
+##获取性能数据,不需要修改
+#吞吐量
+ActualFPS=${FPS}
+#单迭代训练时长
+TrainingTime=${TrainingTime}
+
+#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视
+grep ",loss:" $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | awk '{print $3}' >> $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt
+#最后一个迭代loss值,不需要修改
+ActualLoss=`awk 'END {print $1}' $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt`
+
+#关键信息打印到${CaseName}.log中,不需要修改
+echo "Network = ${Network}" > $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "RankSize = ${RANK_SIZE}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "BatchSize = ${BatchSize}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "DeviceType = ${DeviceType}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "CaseName = ${CaseName}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualFPS = ${ActualFPS}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainingTime = ${TrainingTime}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualLoss = ${ActualLoss}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
\ No newline at end of file
diff --git a/TensorFlow2/built-in/keras_sample/text_classification_with_transformer_ID2563_for_TensorFlow2.X/test/train_performance_1p.sh b/TensorFlow2/built-in/keras_sample/text_classification_with_transformer_ID2563_for_TensorFlow2.X/test/train_performance_1p.sh
new file mode 100644
index 0000000000000000000000000000000000000000..42b3ff4e8ab75d6723df7578dc94c7a9291e4d7b
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/text_classification_with_transformer_ID2563_for_TensorFlow2.X/test/train_performance_1p.sh
@@ -0,0 +1,178 @@
+#!/bin/bash
+
+#当前路径,不需要修改
+cur_path=`pwd`/../
+
+#集合通信参数,不需要修改
+export RANK_SIZE=1
+export JOB_ID=10087
+RANK_ID_START=$ASCEND_DEVICE_ID
+
+# 数据集路径,保持为空,不需要修改
+data_path=""
+
+#基础参数,需要模型审视修改
+#网络名称,同目录名称
+Network="text_classification_with_transformer_ID2563_for_TensorFlow2.X"
+#训练epoch
+train_epochs=2
+#训练batch_size
+batch_size=32
+
+#维测参数,precision_mode需要模型审视修改
+precision_mode="allow_mix_precision"
+#维持参数,以下不需要修改
+over_dump=False
+if [[ $over_dump == True ]];then
+ over_dump_path=$cur_path/test/overflow_dump
+fi
+data_dump_flag=False
+data_dump_step="10"
+profiling=False
+use_mixlist=False
+mixlist_file="ops_info.json"
+fusion_off_flag=False
+fusion_off_file="fusion_switch.cfg"
+
+# 帮助信息,不需要修改
+if [[ $1 == --help || $1 == -h ]];then
+ echo"usage:./train_performance_1p.sh "
+ echo " "
+ echo "parameter explain:
+ --precision_mode precision mode(allow_fp32_to_fp16/force_fp16/must_keep_origin_dtype/allow_mix_precision)
+ --over_dump if or not over detection, default is False
+ --data_dump_flag data dump flag, default is False
+ --data_dump_step data dump step, default is 10
+ --profiling if or not profiling for performance debug, default is False
+ --data_path source data of training
+ -h/--help show help message
+ "
+ exit 1
+fi
+
+#参数校验,不需要修改
+for para in $*
+do
+ if [[ $para == --precision_mode* ]];then
+ precision_mode=`echo ${para#*=}`
+ elif [[ $para == --over_dump* ]];then
+ over_dump=`echo ${para#*=}`
+ over_dump_path=${cur_path}/output/overflow_dump
+ mkdir -p ${over_dump_path}
+ elif [[ $para == --data_dump_flag* ]];then
+ data_dump_flag=`echo ${para#*=}`
+ data_dump_path=${cur_path}/output/data_dump
+ mkdir -p ${data_dump_path}
+ elif [[ $para == --data_dump_step* ]];then
+ data_dump_step=`echo ${para#*=}`
+ elif [[ $para == --profiling* ]];then
+ profiling=`echo ${para#*=}`
+ profiling_dump_path=${cur_path}/output/profiling
+ mkdir -p ${profiling_dump_path}
+ elif [[ $para == --data_path* ]];then
+ data_path=`echo ${para#*=}`
+ elif [[ $para == --use_mixlist* ]];then
+ use_mixlist=`echo ${para#*=}`
+ elif [[ $para == --mixlist_file* ]];then
+ mixlist_file=`echo ${para#*=}`
+ elif [[ $para == --fusion_off_flag* ]];then
+ fusion_off_flag=`echo ${para#*=}`
+ elif [[ $para == --fusion_off_file* ]];then
+ fusion_off_file=`echo ${para#*=}`
+ fi
+done
+
+#校验是否传入data_path,不需要修改
+if [[ $data_path == "" ]];then
+ echo "[Error] para \"data_path\" must be confing"
+ exit 1
+fi
+
+#训练开始时间,不需要修改
+start_time=$(date +%s)
+
+#进入训练脚本目录,需要模型审视修改
+cd $cur_path/
+
+for((RANK_ID=$RANK_ID_START;RANK_ID<$((RANK_SIZE+RANK_ID_START));RANK_ID++));
+do
+ #设置环境变量,不需要修改
+ echo "Device ID: $ASCEND_DEVICE_ID"
+ export RANK_ID=$RANK_ID
+
+ if [ -d $cur_path/test/output ];then
+ rm -rf $cur_path/test/output/*
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+ else
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+ fi
+
+
+
+ #执行训练脚本,以下传参不需要修改,其他需要模型审视修改
+ nohup python3 text_classification_with_transformer.py --data_dir=$data_path \
+ --epochs=$train_epochs \
+ --batch_size=$batch_size \
+ --precision_mode=${precision_mode} \
+ --over_dump=${over_dump} \
+ --over_dump_path=${over_dump_path} \
+ --data_dump_flag=${data_dump_flag} \
+ --data_dump_step=${data_dump_step} \
+ --data_dump_path=${data_dump_path} \
+ --profiling=${profiling} \
+ --use_mixlist=${use_mixlist} \
+ --fusion_off_flag=${fusion_off_flag} \
+ --mixlist_file=${mixlist_file} \
+ --fusion_off_file=${fusion_off_file} \
+ --profiling_dump_path=${profiling_dump_path} > ${cur_path}/test/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 &
+done
+wait
+
+#conda deactivate
+#训练结束时间,不需要修改
+end_time=$(date +%s)
+e2e_time=$(( $end_time - $start_time ))
+
+#结果打印,不需要修改
+echo "------------------ Final result ------------------"
+#输出性能FPS,需要模型审视修改
+wait
+FPS=`grep imgs/s $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | awk 'END {print $4}'`
+TrainingTime=`awk 'BEGIN{printf "%.2f\n",'${batch_size}'*1000/'${FPS}'}'`
+#打印,不需要修改
+echo "Final Performance images/sec : $FPS"
+
+#输出训练精度,需要模型审视修改
+train_accuracy=`grep " val_accuracy" $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | awk 'END {print $NF}'`
+#打印,不需要修改
+echo "Final Train Accuracy : ${train_accuracy}"
+
+
+#精度看护结果汇总
+#训练用例信息,不需要修改
+BatchSize=${batch_size}
+DeviceType=`uname -m`
+CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}p_perf
+
+##获取性能数据,不需要修改
+#吞吐量
+ActualFPS=${FPS}
+#单迭代训练时长
+TrainingTime=${TrainingTime}
+
+#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视
+grep ",loss:" $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | awk '{print $3}' >> $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt
+#最后一个迭代loss值,不需要修改
+ActualLoss=`awk 'END {print $1}' $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt`
+
+#关键信息打印到${CaseName}.log中,不需要修改
+echo "Network = ${Network}" > $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "RankSize = ${RANK_SIZE}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "BatchSize = ${BatchSize}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "DeviceType = ${DeviceType}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "CaseName = ${CaseName}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualFPS = ${ActualFPS}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainingTime = ${TrainingTime}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualLoss = ${ActualLoss}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
\ No newline at end of file
diff --git a/TensorFlow2/built-in/keras_sample/text_classification_with_transformer_ID2563_for_TensorFlow2.X/test/train_performance_1p_dynamic.sh b/TensorFlow2/built-in/keras_sample/text_classification_with_transformer_ID2563_for_TensorFlow2.X/test/train_performance_1p_dynamic.sh
new file mode 100644
index 0000000000000000000000000000000000000000..c979030a8d8882af6a3df9bdb6b460865d26cf31
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/text_classification_with_transformer_ID2563_for_TensorFlow2.X/test/train_performance_1p_dynamic.sh
@@ -0,0 +1,179 @@
+#!/bin/bash
+
+#当前路径,不需要修改
+cur_path=`pwd`/../
+
+#集合通信参数,不需要修改
+export RANK_SIZE=1
+export JOB_ID=10087
+RANK_ID_START=$ASCEND_DEVICE_ID
+
+# 数据集路径,保持为空,不需要修改
+data_path=""
+
+#基础参数,需要模型审视修改
+#网络名称,同目录名称
+Network="text_classification_with_transformer_ID2563_for_TensorFlow2.X"
+#训练epoch
+train_epochs=2
+#训练batch_size
+batch_size=32
+
+#维测参数,precision_mode需要模型审视修改
+precision_mode="allow_mix_precision"
+#维持参数,以下不需要修改
+over_dump=False
+if [[ $over_dump == True ]];then
+ over_dump_path=$cur_path/test/overflow_dump
+fi
+data_dump_flag=False
+data_dump_step="10"
+profiling=False
+use_mixlist=False
+mixlist_file="ops_info.json"
+fusion_off_flag=False
+fusion_off_file="fusion_switch.cfg"
+
+# 帮助信息,不需要修改
+if [[ $1 == --help || $1 == -h ]];then
+ echo"usage:./train_performance_1p.sh "
+ echo " "
+ echo "parameter explain:
+ --precision_mode precision mode(allow_fp32_to_fp16/force_fp16/must_keep_origin_dtype/allow_mix_precision)
+ --over_dump if or not over detection, default is False
+ --data_dump_flag data dump flag, default is False
+ --data_dump_step data dump step, default is 10
+ --profiling if or not profiling for performance debug, default is False
+ --data_path source data of training
+ -h/--help show help message
+ "
+ exit 1
+fi
+
+#参数校验,不需要修改
+for para in $*
+do
+ if [[ $para == --precision_mode* ]];then
+ precision_mode=`echo ${para#*=}`
+ elif [[ $para == --over_dump* ]];then
+ over_dump=`echo ${para#*=}`
+ over_dump_path=${cur_path}/output/overflow_dump
+ mkdir -p ${over_dump_path}
+ elif [[ $para == --data_dump_flag* ]];then
+ data_dump_flag=`echo ${para#*=}`
+ data_dump_path=${cur_path}/output/data_dump
+ mkdir -p ${data_dump_path}
+ elif [[ $para == --data_dump_step* ]];then
+ data_dump_step=`echo ${para#*=}`
+ elif [[ $para == --profiling* ]];then
+ profiling=`echo ${para#*=}`
+ profiling_dump_path=${cur_path}/output/profiling
+ mkdir -p ${profiling_dump_path}
+ elif [[ $para == --data_path* ]];then
+ data_path=`echo ${para#*=}`
+ elif [[ $para == --use_mixlist* ]];then
+ use_mixlist=`echo ${para#*=}`
+ elif [[ $para == --mixlist_file* ]];then
+ mixlist_file=`echo ${para#*=}`
+ elif [[ $para == --fusion_off_flag* ]];then
+ fusion_off_flag=`echo ${para#*=}`
+ elif [[ $para == --fusion_off_file* ]];then
+ fusion_off_file=`echo ${para#*=}`
+ fi
+done
+
+#校验是否传入data_path,不需要修改
+if [[ $data_path == "" ]];then
+ echo "[Error] para \"data_path\" must be confing"
+ exit 1
+fi
+
+#训练开始时间,不需要修改
+start_time=$(date +%s)
+
+#进入训练脚本目录,需要模型审视修改
+cd $cur_path/
+
+for((RANK_ID=$RANK_ID_START;RANK_ID<$((RANK_SIZE+RANK_ID_START));RANK_ID++));
+do
+ #设置环境变量,不需要修改
+ echo "Device ID: $ASCEND_DEVICE_ID"
+ export RANK_ID=$RANK_ID
+
+ if [ -d $cur_path/test/output ];then
+ rm -rf $cur_path/test/output/*
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+ else
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+ fi
+
+
+
+ #执行训练脚本,以下传参不需要修改,其他需要模型审视修改
+ nohup python3 text_classification_with_transformer.py --data_dir=$data_path \
+ --epochs=$train_epochs \
+ --batch_size=$batch_size \
+ --static=0 \
+ --precision_mode=${precision_mode} \
+ --over_dump=${over_dump} \
+ --over_dump_path=${over_dump_path} \
+ --data_dump_flag=${data_dump_flag} \
+ --data_dump_step=${data_dump_step} \
+ --data_dump_path=${data_dump_path} \
+ --profiling=${profiling} \
+ --use_mixlist=${use_mixlist} \
+ --fusion_off_flag=${fusion_off_flag} \
+ --mixlist_file=${mixlist_file} \
+ --fusion_off_file=${fusion_off_file} \
+ --profiling_dump_path=${profiling_dump_path} > ${cur_path}/test/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 &
+done
+wait
+
+#conda deactivate
+#训练结束时间,不需要修改
+end_time=$(date +%s)
+e2e_time=$(( $end_time - $start_time ))
+
+#结果打印,不需要修改
+echo "------------------ Final result ------------------"
+#输出性能FPS,需要模型审视修改
+wait
+FPS=`grep imgs/s $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | awk 'END {print $4}'`
+TrainingTime=`awk 'BEGIN{printf "%.2f\n",'${batch_size}'*1000/'${FPS}'}'`
+#打印,不需要修改
+echo "Final Performance images/sec : $FPS"
+
+#输出训练精度,需要模型审视修改
+train_accuracy=`grep " val_accuracy" $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | awk 'END {print $NF}'`
+#打印,不需要修改
+echo "Final Train Accuracy : ${train_accuracy}"
+
+
+#精度看护结果汇总
+#训练用例信息,不需要修改
+BatchSize=${batch_size}
+DeviceType=`uname -m`
+CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}p_perf
+
+##获取性能数据,不需要修改
+#吞吐量
+ActualFPS=${FPS}
+#单迭代训练时长
+TrainingTime=${TrainingTime}
+
+#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视
+grep ",loss:" $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | awk '{print $3}' >> $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt
+#最后一个迭代loss值,不需要修改
+ActualLoss=`awk 'END {print $1}' $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt`
+
+#关键信息打印到${CaseName}.log中,不需要修改
+echo "Network = ${Network}" > $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "RankSize = ${RANK_SIZE}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "BatchSize = ${BatchSize}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "DeviceType = ${DeviceType}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "CaseName = ${CaseName}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualFPS = ${ActualFPS}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainingTime = ${TrainingTime}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualLoss = ${ActualLoss}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
\ No newline at end of file
diff --git a/TensorFlow2/built-in/keras_sample/text_classification_with_transformer_ID2563_for_TensorFlow2.X/test/train_performance_1p_static.sh b/TensorFlow2/built-in/keras_sample/text_classification_with_transformer_ID2563_for_TensorFlow2.X/test/train_performance_1p_static.sh
new file mode 100644
index 0000000000000000000000000000000000000000..129098ad5766b812edcd5046579b79df7812b957
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/text_classification_with_transformer_ID2563_for_TensorFlow2.X/test/train_performance_1p_static.sh
@@ -0,0 +1,178 @@
+#!/bin/bash
+
+#当前路径,不需要修改
+cur_path=`pwd`/../
+
+#集合通信参数,不需要修改
+export RANK_SIZE=1
+export JOB_ID=10087
+RANK_ID_START=$ASCEND_DEVICE_ID
+
+# 数据集路径,保持为空,不需要修改
+data_path=""
+
+#基础参数,需要模型审视修改
+#网络名称,同目录名称
+Network="text_classification_with_transformer_ID2563_for_TensorFlow2.X"
+#训练epoch
+train_epochs=2
+#训练batch_size
+batch_size=32
+
+#维测参数,precision_mode需要模型审视修改
+precision_mode="allow_mix_precision"
+#维持参数,以下不需要修改
+over_dump=False
+if [[ $over_dump == True ]];then
+ over_dump_path=$cur_path/test/overflow_dump
+fi
+data_dump_flag=False
+data_dump_step="10"
+profiling=False
+use_mixlist=False
+mixlist_file="ops_info.json"
+fusion_off_flag=False
+fusion_off_file="fusion_switch.cfg"
+
+# 帮助信息,不需要修改
+if [[ $1 == --help || $1 == -h ]];then
+ echo"usage:./train_performance_1p.sh "
+ echo " "
+ echo "parameter explain:
+ --precision_mode precision mode(allow_fp32_to_fp16/force_fp16/must_keep_origin_dtype/allow_mix_precision)
+ --over_dump if or not over detection, default is False
+ --data_dump_flag data dump flag, default is False
+ --data_dump_step data dump step, default is 10
+ --profiling if or not profiling for performance debug, default is False
+ --data_path source data of training
+ -h/--help show help message
+ "
+ exit 1
+fi
+
+#参数校验,不需要修改
+for para in $*
+do
+ if [[ $para == --precision_mode* ]];then
+ precision_mode=`echo ${para#*=}`
+ elif [[ $para == --over_dump* ]];then
+ over_dump=`echo ${para#*=}`
+ over_dump_path=${cur_path}/output/overflow_dump
+ mkdir -p ${over_dump_path}
+ elif [[ $para == --data_dump_flag* ]];then
+ data_dump_flag=`echo ${para#*=}`
+ data_dump_path=${cur_path}/output/data_dump
+ mkdir -p ${data_dump_path}
+ elif [[ $para == --data_dump_step* ]];then
+ data_dump_step=`echo ${para#*=}`
+ elif [[ $para == --profiling* ]];then
+ profiling=`echo ${para#*=}`
+ profiling_dump_path=${cur_path}/output/profiling
+ mkdir -p ${profiling_dump_path}
+ elif [[ $para == --data_path* ]];then
+ data_path=`echo ${para#*=}`
+ elif [[ $para == --use_mixlist* ]];then
+ use_mixlist=`echo ${para#*=}`
+ elif [[ $para == --mixlist_file* ]];then
+ mixlist_file=`echo ${para#*=}`
+ elif [[ $para == --fusion_off_flag* ]];then
+ fusion_off_flag=`echo ${para#*=}`
+ elif [[ $para == --fusion_off_file* ]];then
+ fusion_off_file=`echo ${para#*=}`
+ fi
+done
+
+#校验是否传入data_path,不需要修改
+if [[ $data_path == "" ]];then
+ echo "[Error] para \"data_path\" must be confing"
+ exit 1
+fi
+
+#训练开始时间,不需要修改
+start_time=$(date +%s)
+
+#进入训练脚本目录,需要模型审视修改
+cd $cur_path/
+
+for((RANK_ID=$RANK_ID_START;RANK_ID<$((RANK_SIZE+RANK_ID_START));RANK_ID++));
+do
+ #设置环境变量,不需要修改
+ echo "Device ID: $ASCEND_DEVICE_ID"
+ export RANK_ID=$RANK_ID
+
+ if [ -d $cur_path/test/output ];then
+ rm -rf $cur_path/test/output/*
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+ else
+ mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID
+ fi
+
+
+
+ #执行训练脚本,以下传参不需要修改,其他需要模型审视修改
+ nohup python3 text_classification_with_transformer.py --data_dir=$data_path \
+ --epochs=$train_epochs \
+ --batch_size=$batch_size \
+ --precision_mode=${precision_mode} \
+ --over_dump=${over_dump} \
+ --over_dump_path=${over_dump_path} \
+ --data_dump_flag=${data_dump_flag} \
+ --data_dump_step=${data_dump_step} \
+ --data_dump_path=${data_dump_path} \
+ --profiling=${profiling} \
+ --use_mixlist=${use_mixlist} \
+ --fusion_off_flag=${fusion_off_flag} \
+ --mixlist_file=${mixlist_file} \
+ --fusion_off_file=${fusion_off_file} \
+ --profiling_dump_path=${profiling_dump_path} > ${cur_path}/test/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 &
+done
+wait
+
+#conda deactivate
+#训练结束时间,不需要修改
+end_time=$(date +%s)
+e2e_time=$(( $end_time - $start_time ))
+
+#结果打印,不需要修改
+echo "------------------ Final result ------------------"
+#输出性能FPS,需要模型审视修改
+wait
+FPS=`grep imgs/s $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | awk 'END {print $4}'`
+TrainingTime=`awk 'BEGIN{printf "%.2f\n",'${batch_size}'*1000/'${FPS}'}'`
+#打印,不需要修改
+echo "Final Performance images/sec : $FPS"
+
+#输出训练精度,需要模型审视修改
+train_accuracy=`grep " val_accuracy" $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | awk 'END {print $NF}'`
+#打印,不需要修改
+echo "Final Train Accuracy : ${train_accuracy}"
+
+
+#精度看护结果汇总
+#训练用例信息,不需要修改
+BatchSize=${batch_size}
+DeviceType=`uname -m`
+CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}p_perf
+
+##获取性能数据,不需要修改
+#吞吐量
+ActualFPS=${FPS}
+#单迭代训练时长
+TrainingTime=${TrainingTime}
+
+#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视
+grep ",loss:" $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | awk '{print $3}' >> $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt
+#最后一个迭代loss值,不需要修改
+ActualLoss=`awk 'END {print $1}' $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt`
+
+#关键信息打印到${CaseName}.log中,不需要修改
+echo "Network = ${Network}" > $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "RankSize = ${RANK_SIZE}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "BatchSize = ${BatchSize}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "DeviceType = ${DeviceType}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "CaseName = ${CaseName}_static" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualFPS = ${ActualFPS}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainingTime = ${TrainingTime}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualLoss = ${ActualLoss}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
\ No newline at end of file
diff --git a/TensorFlow2/built-in/keras_sample/text_classification_with_transformer_ID2563_for_TensorFlow2.X/text_classification_with_transformer.py b/TensorFlow2/built-in/keras_sample/text_classification_with_transformer_ID2563_for_TensorFlow2.X/text_classification_with_transformer.py
new file mode 100644
index 0000000000000000000000000000000000000000..e05d2cdb0ba4fa368fc956075f9ef215c56807cb
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/text_classification_with_transformer_ID2563_for_TensorFlow2.X/text_classification_with_transformer.py
@@ -0,0 +1,328 @@
+#
+# Copyright 2017 The TensorFlow Authors. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============================================================================
+# Copyright 2021 Huawei Technologies Co., Ltd
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+"""
+Title: Text classification with Transformer
+Author: [Apoorv Nandan](https://twitter.com/NandanApoorv)
+Date created: 2020/05/10
+Last modified: 2020/05/10
+Description: Implement a Transformer block as a Keras layer and use it for text classification.
+"""
+"""
+## Setup
+"""
+import os
+import time
+import numpy as np
+import tensorflow as tf
+from tensorflow import keras
+from tensorflow.keras import layers
+import npu_device
+import npu_convert_dropout
+import argparse
+import ast
+#===============================NPU Migration=========================================
+parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
+parser.add_argument('--precision_mode', default="allow_mix_precision", type=str,help='the path to save over dump data')
+parser.add_argument('--over_dump', dest='over_dump', type=ast.literal_eval,
+ help='if or not over detection, default is False')
+parser.add_argument('--data_dump_flag', dest='data_dump_flag', type=ast.literal_eval,
+ help='data dump flag, default is False')
+parser.add_argument('--data_dump_step', default="10",
+ help='data dump step, default is 10')
+parser.add_argument('--profiling', dest='profiling', type=ast.literal_eval,help='if or not profiling for performance debug, default is False')
+parser.add_argument('--profiling_dump_path', default="/home/data", type=str,help='the path to save profiling data')
+parser.add_argument('--over_dump_path', default="/home/data", type=str,help='the path to save over dump data')
+parser.add_argument('--data_dump_path', default="/home/data", type=str,help='the path to save dump data')
+parser.add_argument('--use_mixlist', dest='use_mixlist', type=ast.literal_eval,
+ help='use_mixlist flag, default is False')
+parser.add_argument('--fusion_off_flag', dest='fusion_off_flag', type=ast.literal_eval,
+ help='fusion_off flag, default is False')
+parser.add_argument('--mixlist_file', default="ops_info.json", type=str,help='mixlist file name, default is ops_info.json')
+parser.add_argument('--fusion_off_file', default="fusion_switch.cfg", type=str,help='fusion_off file name, default is fusion_switch.cfg')
+parser.add_argument('--data_dir', default='./',help="""directory to data""")
+parser.add_argument('--batch_size', default=32, type=int,help="""batch size for 1p""")
+parser.add_argument('--epochs', default=2, type=int,help="""epochs""")
+parser.add_argument('--static', default=1, type=int,help="""static shape""")
+args = parser.parse_args()
+
+def npu_config():
+ if args.data_dump_flag:
+ npu_device.global_options().dump_config.enable_dump = True
+ npu_device.global_options().dump_config.dump_path = args.data_dump_path
+ npu_device.global_options().dump_config.dump_step = args.data_dump_step
+ npu_device.global_options().dump_config.dump_mode = "all"
+
+ if args.over_dump:
+ npu_device.global_options().dump_config.enable_dump_debug = True
+ npu_device.global_options().dump_config.dump_path = args.over_dump_path
+ npu_device.global_options().dump_config.dump_debug_mode = "all"
+
+ if args.profiling:
+ npu_device.global_options().profiling_config.enable_profiling = True
+ profiling_options = '{"output":"' + args.profiling_dump_path + '", \
+ "training_trace":"on", \
+ "task_trace":"on", \
+ "aicpu":"on", \
+ "aic_metrics":"PipeUtilization",\
+ "fp_point":"", \
+ "bp_point":""}'
+ npu_device.global_options().profiling_config.profiling_options = profiling_options
+ npu_device.global_options().precision_mode = args.precision_mode
+ if args.use_mixlist and args.precision_mode=='allow_mix_precision':
+ npu_device.global_options().modify_mixlist="../configs/"+args.mixlist_file
+ if args.fusion_off_flag:
+ npu_device.global_options().fusion_switch_file="../configs/"+args.fusion_off_file
+ npu_device.open().as_default()
+#===============================NPU Migration=========================================
+npu_config()
+data_dir = args.data_dir
+
+"""
+## Implement a Transformer block as a layer
+"""
+class TransformerBlock(layers.Layer):
+ def __init__(self, embed_dim, num_heads, ff_dim, rate=0.1):
+ super(TransformerBlock, self).__init__()
+ self.att = layers.MultiHeadAttention(num_heads=num_heads, key_dim=embed_dim)
+ self.ffn = keras.Sequential(
+ [layers.Dense(ff_dim, activation="relu"), layers.Dense(embed_dim),]
+ )
+ self.layernorm1 = layers.LayerNormalization(epsilon=1e-6)
+ self.layernorm2 = layers.LayerNormalization(epsilon=1e-6)
+ self.dropout1 = layers.Dropout(rate)
+ self.dropout2 = layers.Dropout(rate)
+
+ def call(self, inputs, training):
+ attn_output = self.att(inputs, inputs)
+ attn_output = self.dropout1(attn_output, training=training)
+ out1 = self.layernorm1(inputs + attn_output)
+ ffn_output = self.ffn(out1)
+ ffn_output = self.dropout2(ffn_output, training=training)
+ return self.layernorm2(out1 + ffn_output)
+
+
+"""
+## Implement embedding layer
+
+Two seperate embedding layers, one for tokens, one for token index (positions).
+"""
+
+
+class TokenAndPositionEmbedding(layers.Layer):
+ def __init__(self, maxlen, vocab_size, embed_dim):
+ super(TokenAndPositionEmbedding, self).__init__()
+ self.token_emb = layers.Embedding(input_dim=vocab_size, output_dim=embed_dim)
+ self.pos_emb = layers.Embedding(input_dim=maxlen, output_dim=embed_dim)
+
+ def call(self, x):
+ maxlen = tf.shape(x)[-1]
+ positions = tf.range(start=0, limit=maxlen, delta=1)
+ positions = self.pos_emb(positions)
+ x = self.token_emb(x)
+ return x + positions
+
+class LossHistory(tf.keras.callbacks.Callback):
+ def __init__(self, batch_size, log_steps=50, initial_step=0):
+ self.batch_size = batch_size
+ super(LossHistory, self).__init__()
+ self.steps_before_epoch = initial_step
+ self.last_log_step = initial_step
+ self.log_steps = log_steps
+ self.steps_in_epoch = 0
+ self.start_time = None
+
+ @property
+ def global_steps(self):
+ """The current 1-indexed global step."""
+ return self.steps_before_epoch + self.steps_in_epoch
+
+ def on_batch_begin(self, batch, logs={}):
+ if not self.start_time:
+ self.start_time = time.time()
+
+ def on_batch_end(self, batch, logs={}):
+ loss = logs.get('loss')
+ self.steps_in_epoch = batch + 1
+ steps_since_last_log = self.global_steps - self.last_log_step
+ if steps_since_last_log >= self.log_steps:
+ now = time.time()
+ elapsed_time = now - self.start_time
+ steps_per_second = steps_since_last_log / elapsed_time
+ examples_per_second = steps_per_second * self.batch_size
+ print(
+ 'TimeHistory: %.2f seconds, %.2f imgs/s between steps %d '
+ 'and %d'%(elapsed_time, examples_per_second, self.last_log_step,
+ self.global_steps),flush=True)
+ self.last_log_step = self.global_steps
+ self.start_time = None
+ print('step:%d ,loss: %f '%(batch, loss), flush=True)
+
+ def on_epoch_begin(self, epoch, logs={}):
+ if not self.start_time:
+ self.start_time = time.time()
+ self.epoch_start = time.time()
+
+ def on_epoch_end(self, epoch, logs={}):
+ epoch_run_time = time.time() - self.epoch_start
+ self.steps_before_epoch += self.steps_in_epoch
+ self.steps_in_epoch = 0
+
+logger = LossHistory(args.batch_size)
+
+"""
+## Download and prepare dataset
+"""
+
+vocab_size = 20000 # Only consider the top 20k words
+maxlen = 200 # Only consider the first 200 words of each movie review
+#(x_train, y_train), (x_val, y_val) = keras.datasets.imdb.load_data(num_words=vocab_size)
+def load_data(path='imdb.npz',
+ num_words=None,
+ skip_top=0,
+ maxlen=None,
+ seed=113,
+ start_char=1,
+ oov_char=2,
+ index_from=3,
+ static=1,
+ **kwargs):
+ # Legacy support
+ if 'nb_words' in kwargs:
+ logging.warning('The `nb_words` argument in `load_data` '
+ 'has been renamed `num_words`.')
+ num_words = kwargs.pop('nb_words')
+ if kwargs:
+ raise TypeError(f'Unrecognized keyword arguments: {str(kwargs)}.')
+
+ # origin_folder = 'https://storage.googleapis.com/tensorflow/tf-keras-datasets/'
+ # path = get_file(
+ # path,
+ # origin=origin_folder + 'imdb.npz',
+ # fi le_hash=
+ # '69664113be75683a8fe16e3ed0ab59fda8886cb3cd7ada244f7d9544e4676b9f')
+ with np.load(path, allow_pickle=True) as f: # pylint: disable=unexpected-keyword-arg
+ x_train, labels_train = f['x_train'], f['y_train']
+ x_test, labels_test = f['x_test'], f['y_test']
+
+ rng = np.random.RandomState(seed)
+ indices = np.arange(len(x_train))
+ rng.shuffle(indices)
+ x_train = x_train[indices]
+ labels_train = labels_train[indices]
+
+ indices = np.arange(len(x_test))
+ rng.shuffle(indices)
+ x_test = x_test[indices]
+ labels_test = labels_test[indices]
+
+ if start_char is not None:
+ x_train = [[start_char] + [w + index_from for w in x] for x in x_train]
+ x_test = [[start_char] + [w + index_from for w in x] for x in x_test]
+ elif index_from:
+ x_train = [[w + index_from for w in x] for x in x_train]
+ x_test = [[w + index_from for w in x] for x in x_test]
+
+ if maxlen:
+ x_train, labels_train = _remove_long_seq(maxlen, x_train, labels_train)
+ x_test, labels_test = _remove_long_seq(maxlen, x_test, labels_test)
+ if not x_train or not x_test:
+ raise ValueError('After filtering for sequences shorter than maxlen='
+ f'{str(maxlen)}, no sequence was kept. Increase maxlen.')
+
+ xs = x_train + x_test
+ labels = np.concatenate([labels_train, labels_test])
+
+ if not num_words:
+ num_words = max(max(x) for x in xs)
+
+ # by convention, use 2 as OOV word
+ # reserve 'index_from' (=3 by default) characters:
+ # 0 (padding), 1 (start), 2 (OOV)
+ if oov_char is not None:
+ xs = [
+ [w if (skip_top <= w < num_words) else oov_char for w in x] for x in xs
+ ]
+ else:
+ xs = [[w for w in x if skip_top <= w < num_words] for x in xs]
+
+ idx = len(x_train)
+ if static:
+ x_train, y_train = np.array(xs[:24992], dtype='object'), labels[:24992]
+ x_test, y_test = np.array(xs[idx:idx+24992], dtype='object'), labels[idx:idx+24992]
+ else:
+ x_train, y_train = np.array(xs[:idx], dtype='object'), labels[:idx]
+ x_test, y_test = np.array(xs[idx:], dtype='object'), labels[idx:]
+ return (x_train, y_train), (x_test, y_test)
+
+data_path = os.path.join(data_dir, 'imdb.npz')
+(x_train, y_train), (x_val, y_val) = load_data(path=data_path, num_words=vocab_size, static=args.static)
+
+print(len(x_train), "Training sequences")
+print(len(x_val), "Validation sequences")
+x_train = keras.preprocessing.sequence.pad_sequences(x_train, maxlen=maxlen)
+x_val = keras.preprocessing.sequence.pad_sequences(x_val, maxlen=maxlen)
+
+"""
+## Create classifier model using transformer layer
+
+Transformer layer outputs one vector for each time step of our input sequence.
+Here, we take the mean across all time steps and
+use a feed forward network on top of it to classify text.
+"""
+
+
+embed_dim = 32 # Embedding size for each token
+num_heads = 2 # Number of attention heads
+ff_dim = 32 # Hidden layer size in feed forward network inside transformer
+
+inputs = layers.Input(shape=(maxlen,))
+embedding_layer = TokenAndPositionEmbedding(maxlen, vocab_size, embed_dim)
+x = embedding_layer(inputs)
+transformer_block = TransformerBlock(embed_dim, num_heads, ff_dim)
+x = transformer_block(x)
+x = layers.GlobalAveragePooling1D()(x)
+x = layers.Dropout(0.1)(x)
+x = layers.Dense(20, activation="relu")(x)
+x = layers.Dropout(0.1)(x)
+outputs = layers.Dense(2, activation="softmax")(x)
+
+model = keras.Model(inputs=inputs, outputs=outputs)
+
+
+"""
+## Train and Evaluate
+"""
+
+model.compile(
+ optimizer="adam", loss="sparse_categorical_crossentropy", metrics=["accuracy"]
+)
+history = model.fit(
+ x_train, y_train, batch_size=args.batch_size, epochs=args.epochs, validation_data=(x_val, y_val), verbose=2, callbacks=[logger]
+)
diff --git a/TensorFlow2/built-in/keras_sample/word2vec_ID2886_for_TensorFlow2.X/LICENSE b/TensorFlow2/built-in/keras_sample/word2vec_ID2886_for_TensorFlow2.X/LICENSE
new file mode 100644
index 0000000000000000000000000000000000000000..ab652360b248f2947c2e3ccf306ca128660ea731
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/word2vec_ID2886_for_TensorFlow2.X/LICENSE
@@ -0,0 +1,284 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+------------------
+Files: third_party/compute_library/...
+
+MIT License
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+
+------------------
+Files: ACKNOWLEDGEMENTS
+LICENSE
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+------------------
+Files: third_party/hexagon
+
+Copyright (c) 2016-2019, The Linux Foundation. All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted (subject to the limitations in the
+disclaimer below) provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+
+ * Neither the name of The Linux Foundation nor the names of its
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
+GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
+HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/TensorFlow2/built-in/keras_sample/word2vec_ID2886_for_TensorFlow2.X/README.md b/TensorFlow2/built-in/keras_sample/word2vec_ID2886_for_TensorFlow2.X/README.md
new file mode 100644
index 0000000000000000000000000000000000000000..34b6528466daf9c093cad089f473b191f995d326
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/word2vec_ID2886_for_TensorFlow2.X/README.md
@@ -0,0 +1,187 @@
+- [基本信息](#基本信息.md)
+- [概述](#概述.md)
+- [训练环境准备](#训练环境准备.md)
+- [快速上手](#快速上手.md)
+- [迁移学习指导](#迁移学习指导.md)
+- [高级参考](#高级参考.md)
+基本信息
+
+**发布者(Publisher):Huawei**
+
+**应用领域(Application Domain):Natural Language Processing**
+
+**版本(Version):1.1**
+
+**修改时间(Modified) :2022.04.11**
+
+**大小(Size):64.2KB**
+
+**框架(Framework):TensorFlow_2.6.2**
+
+**模型格式(Model Format):h5**
+
+**精度(Precision):Mixed**
+
+**处理器(Processor):昇腾910**
+
+**应用级别(Categories):Research**
+
+**描述(Description):基于skip-gram的词向量训练代码**
+
+概述
+
+## 简述
+ 基于skip-gram的词向量训练代码。
+
+
+- 参考论文:
+
+ [Distributed representations of words and phrases and their compositionality](https://arxiv.org/abs/1310.4546)
+
+- 参考实现:
+
+ [https://github.com/Deermini/word2vec-tensorflow](https://github.com/Deermini/word2vec-tensorflow)
+
+- 适配昇腾 AI 处理器的实现:skip
+
+ [https://gitee.com/jelly_111/research_tf2/tree/master/word2vec_ID2886_for_TensorFlow2.X](https://gitee.com/jelly_111/research_tf2/tree/master/word2vec_ID2886_for_TensorFlow2.X)
+
+- 通过Git获取对应commit\_id的代码方法如下:
+ ```
+ git clone {repository_url} # 克隆仓库的代码
+ cd {repository_name} # 切换到模型的代码仓目录
+ git checkout {branch} # 切换到对应分支
+ git reset --hard {commit_id} # 代码设置到对应的commit_id
+ cd {code_path} # 切换到模型代码所在路径,若仓库下只有该模型,则无需切换
+ ```
+
+## 默认配置
+- 训练超参(单卡):
+
+ Batch Size = 128
+
+ train steps = 3000000
+
+ learning rate = 0.001
+
+
+
+## 支持特性
+
+| 特性列表 | 是否支持 |
+| ---------- | -------- |
+| 分布式训练 | 否 |
+| 混合精度 | 是 |
+| 数据并行 | 否 |
+
+## 混合精度训练
+
+昇腾910 AI处理器提供自动混合精度功能,可以针对全网中float32数据类型的算子,按照内置的优化策略,自动将部分float32的算子降低精度到float16,从而在精度损失很小的情况下提升系统性能并减少内存使用。
+
+## 开启混合精度
+拉起脚本中,传入--precision_mode='allow_mix_precision'
+
+```
+./train_performance_1p.sh --help
+parameter explain:
+ --precision_mode precision mode(allow_fp32_to_fp16/force_fp16/must_keep_origin_dtype/allow_mix_precision)
+ --over_dump if or not over detection, default is False
+ --data_dump_flag data dump flag, default is False
+ --data_dump_step data dump step, default is 10
+ --profiling if or not profiling for performance debug, default is False
+ --data_path source data of training
+ -h/--help show help message
+```
+
+对应代码:
+
+```
+ npu_device.global_options().precision_mode='allow_mix_precision'
+ npu_device.open().as_default()
+```
+
+训练环境准备
+
+- 硬件环境和运行环境准备请参见《[CANN软件安装指南](https://support.huawei.com/enterprise/zh/ascend-computing/cann-pid-251168373?category=installation-update)》
+- 运行以下命令安装依赖。
+```
+pip3 install requirements.txt
+```
+说明:依赖配置文件requirements.txt文件位于模型的根目录
+
+快速上手
+
+## 数据集准备
+
+1. 请用户自行下载cnews数据集
+
+## 模型训练
+- 单击“立即下载”,并选择合适的下载方式下载源码包。
+- 开始训练。
+
+ 1. 启动训练之前,首先要配置程序运行相关环境变量。
+
+ 环境变量配置信息参见:
+
+ [Ascend 910训练平台环境变量设置](https://gitee.com/ascend/modelzoo/wikis/Ascend%20910%E8%AE%AD%E7%BB%83%E5%B9%B3%E5%8F%B0%E7%8E%AF%E5%A2%83%E5%8F%98%E9%87%8F%E8%AE%BE%E7%BD%AE?sort_id=3148819)
+
+ 2. 单卡训练
+
+ 2.1 单卡训练指令(脚本位于word2vec_ID2886_for_TensorFlow2.X/test/),请确保下面例子中的“--data_path”修改为用户的数据集的路径。
+
+ bash test/train_performance_1p.sh --data_path=/home/cnews
+
+高级参考
+
+- 数据集准备。
+
+ 1. 获取数据。
+ 请参见“快速上手”中的数据集准备。
+
+- 模型训练。
+
+ 参考“模型训练”中训练步骤。
+
+高级参考
+
+## 脚本和示例代码
+```
+word2vec_ID2886_for_TensorFlow2.X
+|-- LICENSE
+|-- README.md
+|-- requirements.txt
+|-- stop_words.txt
+|-- modelzoo_level.txt
+|-- word2vec_chinese.py
+|-- test
+| |-- train_full_1p.sh
+| |-- train_performance_1p.sh
+
+```
+
+## 脚本参数
+
+```
+--data_dir The location of the input data.
+--ckpt_path The location of the model checkpoint files
+--batch_size Batch size for training and evaluation
+--train_step train step num
+```
+
+## 训练过程
+
+1. 通过“模型训练”中的训练指令启动单卡训练。
+2. 将训练脚本(train_full_1p.sh)中的data_path设置为训练数据集的路径。具体的流程参见“模型训练”的示例。
+3. 模型存储路径为“curpath/output/ASCEND_DEVICE_ID”,包括训练的log文件。
+4. 以多卡训练为例,loss信息在文件curpath/output/{ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log中。
+
+## 推理/验证过程
+
+```
+ NA
+
+```
+
+
+
+
diff --git a/TensorFlow2/built-in/keras_sample/word2vec_ID2886_for_TensorFlow2.X/configs/ops_info.json b/TensorFlow2/built-in/keras_sample/word2vec_ID2886_for_TensorFlow2.X/configs/ops_info.json
new file mode 100644
index 0000000000000000000000000000000000000000..cad5f688980bfc4d3ec670562480d66aa74ac30f
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/word2vec_ID2886_for_TensorFlow2.X/configs/ops_info.json
@@ -0,0 +1,13 @@
+{
+ "black-list":{
+ "to-add":[
+ "SquaredDifference",
+ "AddN",
+ "Add",
+ "ConfusionSoftmaxGrad",
+ "ReduceSumD",
+ "SoftmaxCrossEntropyWithLogits",
+ "StridedSliceD"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/TensorFlow2/built-in/keras_sample/word2vec_ID2886_for_TensorFlow2.X/images/tsne2.png b/TensorFlow2/built-in/keras_sample/word2vec_ID2886_for_TensorFlow2.X/images/tsne2.png
new file mode 100644
index 0000000000000000000000000000000000000000..3de1aacf231338b2348281998c6fd5cd0c3c1177
Binary files /dev/null and b/TensorFlow2/built-in/keras_sample/word2vec_ID2886_for_TensorFlow2.X/images/tsne2.png differ
diff --git a/TensorFlow2/built-in/keras_sample/word2vec_ID2886_for_TensorFlow2.X/modelzoo_level.txt b/TensorFlow2/built-in/keras_sample/word2vec_ID2886_for_TensorFlow2.X/modelzoo_level.txt
new file mode 100644
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
diff --git a/TensorFlow2/built-in/keras_sample/word2vec_ID2886_for_TensorFlow2.X/requirements.txt b/TensorFlow2/built-in/keras_sample/word2vec_ID2886_for_TensorFlow2.X/requirements.txt
new file mode 100644
index 0000000000000000000000000000000000000000..4631eb7dd4215a679459efe39bca0587aa8985d0
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/word2vec_ID2886_for_TensorFlow2.X/requirements.txt
@@ -0,0 +1,4 @@
+jieba
+sklearn
+matplotlib
+scipy
\ No newline at end of file
diff --git a/TensorFlow2/built-in/keras_sample/word2vec_ID2886_for_TensorFlow2.X/stop_words.txt b/TensorFlow2/built-in/keras_sample/word2vec_ID2886_for_TensorFlow2.X/stop_words.txt
new file mode 100644
index 0000000000000000000000000000000000000000..87cf4baaa39dca1eadfe9d260c0ec9e0204821b0
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/word2vec_ID2886_for_TensorFlow2.X/stop_words.txt
@@ -0,0 +1,1893 @@
+"
+
+#
+$
+%
+&
+'
+(
+)
+*
++
+,
+-
+--
+.
+..
+...
+......
+...................
+./
+.一
+.数
+.日
+/
+//
+0
+1
+2
+3
+4
+5
+6
+7
+8
+9
+:
+://
+::
+;
+<
+=
+>
+>>
+?
+@
+A
+Lex
+[
+\
+]
+^
+_
+`
+exp
+sub
+sup
+|
+}
+~
+~~~~
+·
+×
+×××
+Δ
+Ψ
+γ
+μ
+φ
+φ.
+В
+—
+——
+———
+‘
+’
+’‘
+“
+”
+”,
+…
+……
+…………………………………………………③
+′∈
+′|
+℃
+Ⅲ
+↑
+→
+∈[
+∪φ∈
+≈
+①
+②
+②c
+③
+③]
+④
+⑤
+⑥
+⑦
+⑧
+⑨
+⑩
+──
+■
+▲
+
+、
+。
+〈
+〉
+《
+》
+》),
+」
+『
+』
+【
+】
+〔
+〕
+〕〔
+㈧
+一
+一.
+一一
+一下
+一个
+一些
+一何
+一切
+一则
+一则通过
+一天
+一定
+一方面
+一旦
+一时
+一来
+一样
+一次
+一片
+一番
+一直
+一致
+一般
+一起
+一转眼
+一边
+一面
+七
+万一
+三
+三天两头
+三番两次
+三番五次
+上
+上下
+上升
+上去
+上来
+上述
+上面
+下
+下列
+下去
+下来
+下面
+不
+不一
+不下
+不久
+不了
+不亦乐乎
+不仅
+不仅...而且
+不仅仅
+不仅仅是
+不会
+不但
+不但...而且
+不光
+不免
+不再
+不力
+不单
+不变
+不只
+不可
+不可开交
+不可抗拒
+不同
+不外
+不外乎
+不够
+不大
+不如
+不妨
+不定
+不对
+不少
+不尽
+不尽然
+不巧
+不已
+不常
+不得
+不得不
+不得了
+不得已
+不必
+不怎么
+不怕
+不惟
+不成
+不拘
+不择手段
+不敢
+不料
+不断
+不日
+不时
+不是
+不曾
+不止
+不止一次
+不比
+不消
+不满
+不然
+不然的话
+不特
+不独
+不由得
+不知不觉
+不管
+不管怎样
+不经意
+不胜
+不能
+不能不
+不至于
+不若
+不要
+不论
+不起
+不足
+不过
+不迭
+不问
+不限
+与
+与其
+与其说
+与否
+与此同时
+专门
+且
+且不说
+且说
+两者
+严格
+严重
+个
+个人
+个别
+中小
+中间
+丰富
+串行
+临
+临到
+为
+为主
+为了
+为什么
+为什麽
+为何
+为止
+为此
+为着
+主张
+主要
+举凡
+举行
+乃
+乃至
+乃至于
+么
+之
+之一
+之前
+之后
+之後
+之所以
+之类
+乌乎
+乎
+乒
+乘
+乘势
+乘机
+乘胜
+乘虚
+乘隙
+九
+也
+也好
+也就是说
+也是
+也罢
+了
+了解
+争取
+二
+二来
+二话不说
+二话没说
+于
+于是
+于是乎
+云云
+云尔
+互
+互相
+五
+些
+交口
+亦
+产生
+亲口
+亲手
+亲眼
+亲自
+亲身
+人
+人人
+人们
+人家
+人民
+什么
+什么样
+什麽
+仅
+仅仅
+今
+今后
+今天
+今年
+今後
+介于
+仍
+仍旧
+仍然
+从
+从不
+从严
+从中
+从事
+从今以后
+从优
+从古到今
+从古至今
+从头
+从宽
+从小
+从新
+从无到有
+从早到晚
+从未
+从来
+从此
+从此以后
+从而
+从轻
+从速
+从重
+他
+他人
+他们
+他是
+他的
+代替
+以
+以上
+以下
+以为
+以便
+以免
+以前
+以及
+以后
+以外
+以後
+以故
+以期
+以来
+以至
+以至于
+以致
+们
+任
+任何
+任凭
+任务
+企图
+伙同
+会
+伟大
+传
+传说
+传闻
+似乎
+似的
+但
+但凡
+但愿
+但是
+何
+何乐而不为
+何以
+何况
+何处
+何妨
+何尝
+何必
+何时
+何止
+何苦
+何须
+余外
+作为
+你
+你们
+你是
+你的
+使
+使得
+使用
+例如
+依
+依据
+依照
+依靠
+便
+便于
+促进
+保持
+保管
+保险
+俺
+俺们
+倍加
+倍感
+倒不如
+倒不如说
+倒是
+倘
+倘使
+倘或
+倘然
+倘若
+借
+借以
+借此
+假使
+假如
+假若
+偏偏
+做到
+偶尔
+偶而
+傥然
+像
+儿
+允许
+元/吨
+充其极
+充其量
+充分
+先不先
+先后
+先後
+先生
+光
+光是
+全体
+全力
+全年
+全然
+全身心
+全部
+全都
+全面
+八
+八成
+公然
+六
+兮
+共
+共同
+共总
+关于
+其
+其一
+其中
+其二
+其他
+其余
+其后
+其它
+其实
+其次
+具体
+具体地说
+具体来说
+具体说来
+具有
+兼之
+内
+再
+再其次
+再则
+再有
+再次
+再者
+再者说
+再说
+冒
+冲
+决不
+决定
+决非
+况且
+准备
+凑巧
+凝神
+几
+几乎
+几度
+几时
+几番
+几经
+凡
+凡是
+凭
+凭借
+出
+出于
+出去
+出来
+出现
+分别
+分头
+分期
+分期分批
+切
+切不可
+切切
+切勿
+切莫
+则
+则甚
+刚
+刚好
+刚巧
+刚才
+初
+别
+别人
+别处
+别是
+别的
+别管
+别说
+到
+到了儿
+到处
+到头
+到头来
+到底
+到目前为止
+前后
+前此
+前者
+前进
+前面
+加上
+加之
+加以
+加入
+加强
+动不动
+动辄
+勃然
+匆匆
+十分
+千
+千万
+千万千万
+半
+单
+单单
+单纯
+即
+即令
+即使
+即便
+即刻
+即如
+即将
+即或
+即是说
+即若
+却
+却不
+历
+原来
+去
+又
+又及
+及
+及其
+及时
+及至
+双方
+反之
+反之亦然
+反之则
+反倒
+反倒是
+反应
+反手
+反映
+反而
+反过来
+反过来说
+取得
+取道
+受到
+变成
+古来
+另
+另一个
+另一方面
+另外
+另悉
+另方面
+另行
+只
+只当
+只怕
+只是
+只有
+只消
+只要
+只限
+叫
+叫做
+召开
+叮咚
+叮当
+可
+可以
+可好
+可是
+可能
+可见
+各
+各个
+各人
+各位
+各地
+各式
+各种
+各级
+各自
+合理
+同
+同一
+同时
+同样
+后
+后来
+后者
+后面
+向
+向使
+向着
+吓
+吗
+否则
+吧
+吧哒
+吱
+呀
+呃
+呆呆地
+呐
+呕
+呗
+呜
+呜呼
+呢
+周围
+呵
+呵呵
+呸
+呼哧
+呼啦
+咋
+和
+咚
+咦
+咧
+咱
+咱们
+咳
+哇
+哈
+哈哈
+哉
+哎
+哎呀
+哎哟
+哗
+哗啦
+哟
+哦
+哩
+哪
+哪个
+哪些
+哪儿
+哪天
+哪年
+哪怕
+哪样
+哪边
+哪里
+哼
+哼唷
+唉
+唯有
+啊
+啊呀
+啊哈
+啊哟
+啐
+啥
+啦
+啪达
+啷当
+喀
+喂
+喏
+喔唷
+喽
+嗡
+嗡嗡
+嗬
+嗯
+嗳
+嘎
+嘎嘎
+嘎登
+嘘
+嘛
+嘻
+嘿
+嘿嘿
+四
+因
+因为
+因了
+因此
+因着
+因而
+固
+固然
+在
+在下
+在于
+地
+均
+坚决
+坚持
+基于
+基本
+基本上
+处在
+处处
+处理
+复杂
+多
+多么
+多亏
+多多
+多多少少
+多多益善
+多少
+多年前
+多年来
+多数
+多次
+够瞧的
+大
+大不了
+大举
+大事
+大体
+大体上
+大凡
+大力
+大多
+大多数
+大大
+大家
+大张旗鼓
+大批
+大抵
+大概
+大略
+大约
+大致
+大都
+大量
+大面儿上
+失去
+奇
+奈
+奋勇
+她
+她们
+她是
+她的
+好
+好在
+好的
+好象
+如
+如上
+如上所述
+如下
+如今
+如何
+如其
+如前所述
+如同
+如常
+如是
+如期
+如果
+如次
+如此
+如此等等
+如若
+始而
+姑且
+存在
+存心
+孰料
+孰知
+宁
+宁可
+宁愿
+宁肯
+它
+它们
+它们的
+它是
+它的
+安全
+完全
+完成
+定
+实现
+实际
+宣布
+容易
+密切
+对
+对于
+对应
+对待
+对方
+对比
+将
+将才
+将要
+将近
+小
+少数
+尔
+尔后
+尔尔
+尔等
+尚且
+尤其
+就
+就地
+就是
+就是了
+就是说
+就此
+就算
+就要
+尽
+尽可能
+尽如人意
+尽心尽力
+尽心竭力
+尽快
+尽早
+尽然
+尽管
+尽管如此
+尽量
+局外
+居然
+届时
+属于
+屡
+屡屡
+屡次
+屡次三番
+岂
+岂但
+岂止
+岂非
+川流不息
+左右
+巨大
+巩固
+差一点
+差不多
+己
+已
+已矣
+已经
+巴
+巴巴
+带
+帮助
+常
+常常
+常言说
+常言说得好
+常言道
+平素
+年复一年
+并
+并不
+并不是
+并且
+并排
+并无
+并没
+并没有
+并肩
+并非
+广大
+广泛
+应当
+应用
+应该
+庶乎
+庶几
+开外
+开始
+开展
+引起
+弗
+弹指之间
+强烈
+强调
+归
+归根到底
+归根结底
+归齐
+当
+当下
+当中
+当儿
+当前
+当即
+当口儿
+当地
+当场
+当头
+当庭
+当时
+当然
+当真
+当着
+形成
+彻夜
+彻底
+彼
+彼时
+彼此
+往
+往往
+待
+待到
+很
+很多
+很少
+後来
+後面
+得
+得了
+得出
+得到
+得天独厚
+得起
+心里
+必
+必定
+必将
+必然
+必要
+必须
+快
+快要
+忽地
+忽然
+怎
+怎么
+怎么办
+怎么样
+怎奈
+怎样
+怎麽
+怕
+急匆匆
+怪
+怪不得
+总之
+总是
+总的来看
+总的来说
+总的说来
+总结
+总而言之
+恍然
+恐怕
+恰似
+恰好
+恰如
+恰巧
+恰恰
+恰恰相反
+恰逢
+您
+您们
+您是
+惟其
+惯常
+意思
+愤然
+愿意
+慢说
+成为
+成年
+成年累月
+成心
+我
+我们
+我是
+我的
+或
+或则
+或多或少
+或是
+或曰
+或者
+或许
+战斗
+截然
+截至
+所
+所以
+所在
+所幸
+所有
+所谓
+才
+才能
+扑通
+打
+打从
+打开天窗说亮话
+扩大
+把
+抑或
+抽冷子
+拦腰
+拿
+按
+按时
+按期
+按照
+按理
+按说
+挨个
+挨家挨户
+挨次
+挨着
+挨门挨户
+挨门逐户
+换句话说
+换言之
+据
+据实
+据悉
+据我所知
+据此
+据称
+据说
+掌握
+接下来
+接着
+接著
+接连不断
+放量
+故
+故意
+故此
+故而
+敞开儿
+敢
+敢于
+敢情
+数/
+整个
+断然
+方
+方便
+方才
+方能
+方面
+旁人
+无
+无宁
+无法
+无论
+既
+既...又
+既往
+既是
+既然
+日复一日
+日渐
+日益
+日臻
+日见
+时候
+昂然
+明显
+明确
+是
+是不是
+是以
+是否
+是的
+显然
+显著
+普通
+普遍
+暗中
+暗地里
+暗自
+更
+更为
+更加
+更进一步
+曾
+曾经
+替
+替代
+最
+最后
+最大
+最好
+最後
+最近
+最高
+有
+有些
+有关
+有利
+有力
+有及
+有所
+有效
+有时
+有点
+有的
+有的是
+有着
+有著
+望
+朝
+朝着
+末##末
+本
+本人
+本地
+本着
+本身
+权时
+来
+来不及
+来得及
+来看
+来着
+来自
+来讲
+来说
+极
+极为
+极了
+极其
+极力
+极大
+极度
+极端
+构成
+果然
+果真
+某
+某个
+某些
+某某
+根据
+根本
+格外
+梆
+概
+次第
+欢迎
+欤
+正值
+正在
+正如
+正巧
+正常
+正是
+此
+此中
+此后
+此地
+此处
+此外
+此时
+此次
+此间
+殆
+毋宁
+每
+每个
+每天
+每年
+每当
+每时每刻
+每每
+每逢
+比
+比及
+比如
+比如说
+比方
+比照
+比起
+比较
+毕竟
+毫不
+毫无
+毫无例外
+毫无保留地
+汝
+沙沙
+没
+没奈何
+没有
+沿
+沿着
+注意
+活
+深入
+清楚
+满
+满足
+漫说
+焉
+然
+然则
+然后
+然後
+然而
+照
+照着
+牢牢
+特别是
+特殊
+特点
+犹且
+犹自
+独
+独自
+猛然
+猛然间
+率尔
+率然
+现代
+现在
+理应
+理当
+理该
+瑟瑟
+甚且
+甚么
+甚或
+甚而
+甚至
+甚至于
+用
+用来
+甫
+甭
+由
+由于
+由是
+由此
+由此可见
+略
+略为
+略加
+略微
+白
+白白
+的
+的确
+的话
+皆可
+目前
+直到
+直接
+相似
+相信
+相反
+相同
+相对
+相对而言
+相应
+相当
+相等
+省得
+看
+看上去
+看出
+看到
+看来
+看样子
+看看
+看见
+看起来
+真是
+真正
+眨眼
+着
+着呢
+矣
+矣乎
+矣哉
+知道
+砰
+确定
+碰巧
+社会主义
+离
+种
+积极
+移动
+究竟
+穷年累月
+突出
+突然
+窃
+立
+立刻
+立即
+立地
+立时
+立马
+竟
+竟然
+竟而
+第
+第二
+等
+等到
+等等
+策略地
+简直
+简而言之
+简言之
+管
+类如
+粗
+精光
+紧接着
+累年
+累次
+纯
+纯粹
+纵
+纵令
+纵使
+纵然
+练习
+组成
+经
+经常
+经过
+结合
+结果
+给
+绝
+绝不
+绝对
+绝非
+绝顶
+继之
+继后
+继续
+继而
+维持
+综上所述
+缕缕
+罢了
+老
+老大
+老是
+老老实实
+考虑
+者
+而
+而且
+而况
+而又
+而后
+而外
+而已
+而是
+而言
+而论
+联系
+联袂
+背地里
+背靠背
+能
+能否
+能够
+腾
+自
+自个儿
+自从
+自各儿
+自后
+自家
+自己
+自打
+自身
+臭
+至
+至于
+至今
+至若
+致
+般的
+良好
+若
+若夫
+若是
+若果
+若非
+范围
+莫
+莫不
+莫不然
+莫如
+莫若
+莫非
+获得
+藉以
+虽
+虽则
+虽然
+虽说
+蛮
+行为
+行动
+表明
+表示
+被
+要
+要不
+要不是
+要不然
+要么
+要是
+要求
+见
+规定
+觉得
+譬喻
+譬如
+认为
+认真
+认识
+让
+许多
+论
+论说
+设使
+设或
+设若
+诚如
+诚然
+话说
+该
+该当
+说明
+说来
+说说
+请勿
+诸
+诸位
+诸如
+谁
+谁人
+谁料
+谁知
+谨
+豁然
+贼死
+赖以
+赶
+赶快
+赶早不赶晚
+起
+起先
+起初
+起头
+起来
+起见
+起首
+趁
+趁便
+趁势
+趁早
+趁机
+趁热
+趁着
+越是
+距
+跟
+路经
+转动
+转变
+转贴
+轰然
+较
+较为
+较之
+较比
+边
+达到
+达旦
+迄
+迅速
+过
+过于
+过去
+过来
+运用
+近
+近几年来
+近年来
+近来
+还
+还是
+还有
+还要
+这
+这一来
+这个
+这么
+这么些
+这么样
+这么点儿
+这些
+这会儿
+这儿
+这就是说
+这时
+这样
+这次
+这点
+这种
+这般
+这边
+这里
+这麽
+进入
+进去
+进来
+进步
+进而
+进行
+连
+连同
+连声
+连日
+连日来
+连袂
+连连
+迟早
+迫于
+适应
+适当
+适用
+逐步
+逐渐
+通常
+通过
+造成
+逢
+遇到
+遭到
+遵循
+遵照
+避免
+那
+那个
+那么
+那么些
+那么样
+那些
+那会儿
+那儿
+那时
+那末
+那样
+那般
+那边
+那里
+那麽
+部分
+都
+鄙人
+采取
+里面
+重大
+重新
+重要
+鉴于
+针对
+长期以来
+长此下去
+长线
+长话短说
+问题
+间或
+防止
+阿
+附近
+陈年
+限制
+陡然
+除
+除了
+除却
+除去
+除外
+除开
+除此
+除此之外
+除此以外
+除此而外
+除非
+随
+随后
+随时
+随着
+随著
+隔夜
+隔日
+难得
+难怪
+难说
+难道
+难道说
+集中
+零
+需要
+非但
+非常
+非徒
+非得
+非特
+非独
+靠
+顶多
+顷
+顷刻
+顷刻之间
+顷刻间
+顺
+顺着
+顿时
+颇
+风雨无阻
+饱
+首先
+马上
+高低
+高兴
+默然
+默默地
+齐
+︿
+!
+#
+$
+%
+&
+'
+(
+)
+)÷(1-
+)、
+*
++
++ξ
+++
+,
+,也
+-
+-β
+--
+-[*]-
+.
+/
+0
+0:2
+1
+1.
+12%
+2
+2.3%
+3
+4
+5
+5:0
+6
+7
+8
+9
+:
+;
+<
+<±
+<Δ
+<λ
+<φ
+<<
+=
+=″
+=☆
+=(
+=-
+=[
+={
+>
+>λ
+?
+@
+A
+LI
+R.L.
+ZXFITL
+[
+[①①]
+[①②]
+[①③]
+[①④]
+[①⑤]
+[①⑥]
+[①⑦]
+[①⑧]
+[①⑨]
+[①A]
+[①B]
+[①C]
+[①D]
+[①E]
+[①]
+[①a]
+[①c]
+[①d]
+[①e]
+[①f]
+[①g]
+[①h]
+[①i]
+[①o]
+[②
+[②①]
+[②②]
+[②③]
+[②④
+[②⑤]
+[②⑥]
+[②⑦]
+[②⑧]
+[②⑩]
+[②B]
+[②G]
+[②]
+[②a]
+[②b]
+[②c]
+[②d]
+[②e]
+[②f]
+[②g]
+[②h]
+[②i]
+[②j]
+[③①]
+[③⑩]
+[③F]
+[③]
+[③a]
+[③b]
+[③c]
+[③d]
+[③e]
+[③g]
+[③h]
+[④]
+[④a]
+[④b]
+[④c]
+[④d]
+[④e]
+[⑤]
+[⑤]]
+[⑤a]
+[⑤b]
+[⑤d]
+[⑤e]
+[⑤f]
+[⑥]
+[⑦]
+[⑧]
+[⑨]
+[⑩]
+[*]
+[-
+[]
+]
+]∧′=[
+][
+_
+a]
+b]
+c]
+e]
+f]
+ng昉
+{
+{-
+|
+}
+}>
+~
+~±
+~+
+¥
diff --git a/TensorFlow2/built-in/keras_sample/word2vec_ID2886_for_TensorFlow2.X/test/train_full_1p.sh b/TensorFlow2/built-in/keras_sample/word2vec_ID2886_for_TensorFlow2.X/test/train_full_1p.sh
new file mode 100644
index 0000000000000000000000000000000000000000..ffa2ee90c99c6440576800e7ff6a540de6d288a3
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/word2vec_ID2886_for_TensorFlow2.X/test/train_full_1p.sh
@@ -0,0 +1,173 @@
+#!/bin/bash
+#当前路径,不需要修改
+cur_path=`pwd`/../
+#集合通信参数,不需要修改
+export RANK_SIZE=1
+export JOB_ID=10087
+RANK_ID_START=0
+# 数据集路径,保持为空,不需要修改
+data_path=""
+#设置默认日志级别,不需要修改
+#export ASCEND_GLOBAL_LOG_LEVEL=3
+#基础参数,需要模型审视修改
+#网络名称,同目录名称
+Network="word2vec_ID2886_for_TensorFlow2.X"
+#训练epoch
+train_epochs=1
+#训练batch_size
+batch_size=128
+#训练step
+train_steps=3000000
+#学习率
+learning_rate=1
+############维测参数##############
+precision_mode="allow_mix_precision"
+#维持参数,以下不需要修改
+over_dump=False
+if [[ $over_dump == True ]];then
+ over_dump_path=$cur_path/test/overflow_dump #此处cur_path为代码根目录
+ mkdir -p ${over_dump_path}
+fi
+data_dump_flag=False
+data_dump_step="10"
+profiling=False
+use_mixlist=True
+mixlist_file="./configs/ops_info.json"
+fusion_off_flag=False
+fusion_off_file="./configs/fusion_switch.cfg"
+auto_tune=False
+############维测参数##############
+# 帮助信息,不需要修改
+if [[ $1 == --help || $1 == -h ]];then
+ echo"usage:./train_performance_1p.sh "
+ echo " "
+ echo "parameter explain:
+ --precision_mode precision mode(allow_fp32_to_fp16/force_fp16/must_keep_origin_dtype/allow_mix_precision)
+ --over_dump if or not over detection, default is False
+ --data_dump_flag data dump flag, default is False
+ --data_dump_step data dump step, default is 10
+ --profiling if or not profiling for performance debug, default is False
+ --autotune whether to enable autotune, default is False
+ --data_path source data of training
+ -h/--help show help message
+ "
+ exit 1
+fi
+
+#参数校验,不需要修改
+for para in $*
+do
+ if [[ $para == --data_path* ]];then
+ data_path=`echo ${para#*=}`
+ elif [[ $para == --train_steps* ]];then
+ train_steps=`echo ${para#*=}`
+ elif [[ $para == --precision_mode* ]];then
+ precision_mode=`echo ${para#*=}`
+ elif [[ $para == --over_dump* ]];then
+ over_dump=`echo ${para#*=}`
+ over_dump_path=${cur_path}/output/overflow_dump
+ mkdir -p ${over_dump_path}
+ elif [[ $para == --data_dump_flag* ]];then
+ data_dump_flag=`echo ${para#*=}`
+ data_dump_path=${cur_path}/output/data_dump
+ mkdir -p ${data_dump_path}
+ elif [[ $para == --data_dump_step* ]];then
+ data_dump_step=`echo ${para#*=}`
+ elif [[ $para == --profiling* ]];then
+ profiling=`echo ${para#*=}`
+ profiling_dump_path=${cur_path}/output/profiling
+ mkdir -p ${profiling_dump_path}
+ elif [[ $para == --use_mixlist* ]];then
+ use_mixlist=`echo ${para#*=}`
+ elif [[ $para == --mixlist_file* ]];then
+ mixlist_file=`echo ${para#*=}`
+ elif [[ $para == --fusion_off_flag* ]];then
+ fusion_off_flag=`echo ${para#*=}`
+ elif [[ $para == --fusion_off_file* ]];then
+ fusion_off_file=`echo ${para#*=}`
+ elif [[ $para == --auto_tune* ]];then
+ auto_tune=`echo ${para#*=}`
+ fi
+done
+
+#校验是否传入data_path,不需要修改
+if [[ $data_path == "" ]];then
+ echo "[Error] para \"data_path\" must be confing"
+ exit 1
+fi
+
+#进入训练脚本目录,需要模型审视修改
+cd $cur_path
+#设置环境变量,不需要修改
+echo "Device ID: $ASCEND_DEVICE_ID"
+
+#创建DeviceID输出目录,不需要修改
+if [ -d ${cur_path}/test/output/${ASCEND_DEVICE_ID} ];then
+ rm -rf ${cur_path}/test/output/${ASCEND_DEVICE_ID}
+ mkdir -p ${cur_path}/test/output/$ASCEND_DEVICE_ID/ckpt
+else
+ mkdir -p ${cur_path}/test/output/$ASCEND_DEVICE_ID/ckpt
+fi
+#执行训练脚本,以下传参不需要修改,其他需要模型审视修改
+
+#训练开始时间,不需要修改
+start_time=$(date +%s)
+#python3 word2vec_chinese.py -dataset_dir=$data_path $step --precision_mode=$precision_mode > ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1
+nohup python3 word2vec_chinese.py \
+ --dataset_dir=$data_path \
+ --step=$train_steps \
+ --precision_mode=${precision_mode} \
+ --over_dump=${over_dump} \
+ --over_dump_path=${over_dump_path} \
+ --data_dump_flag=${data_dump_flag} \
+ --data_dump_step=${data_dump_step} \
+ --data_dump_path=${data_dump_path} \
+ --profiling=${profiling} \
+ --use_mixlist=${use_mixlist} \
+ --fusion_off_flag=${fusion_off_flag} \
+ --mixlist_file=${mixlist_file} \
+ --fusion_off_file=${fusion_off_file} \
+ --profiling_dump_path=${profiling_dump_path} \
+ --auto_tune=${auto_tune} > ${cur_path}/test/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1
+#训练结束时间,不需要修改
+end_time=$(date +%s)
+e2e_time=$(( $end_time - $start_time ))
+#结果打印,不需要修改
+echo "------------------ Final result ------------------"
+#输出性能FPS,需要模型审视修改
+train_time=`grep -a 'time cost' $cur_path/test/output/$ASCEND_DEVICE_ID/train_${ASCEND_DEVICE_ID}.log |awk 'END {print $9}'`
+FPS=`awk 'BEGIN{printf "%.2f\n",'2000'*'${batch_size}'/'${train_time}'}'`
+#打印,不需要修改
+echo "Final Performance images/sec : $train_time"
+#输出训练精度,需要模型审视修改
+train_accuracy=`grep -a 'loss' $cur_path/test/output/$ASCEND_DEVICE_ID/train_${ASCEND_DEVICE_ID}.log |awk 'END{print $5}' | awk -F ',' '{print $1}'`
+
+#打印,不需要修改
+echo "Final Train Accuracy : ${train_accuracy}"
+echo "E2E Training Duration sec : $e2e_time"
+#稳定性精度看护结果汇总
+#训练用例信息,不需要修改
+BatchSize=${batch_size}
+DeviceType=`uname -m`
+CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc'
+##获取性能数据
+#吞吐量,不需要修改
+ActualFPS=${FPS}
+#单迭代训练时长,不需要修改
+TrainingTime=$train_time
+#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视
+grep loss $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | awk -F"loss = " '{print $2}' | awk -F ',' '{print $1}' > $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt
+#最后一个迭代loss值,不需要修改
+ActualLoss=`awk 'END {print}' $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt`
+
+#关键信息打印到${CaseName}.log中,不需要修改
+echo "Network = ${Network}" > $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "RankSize = ${RANK_SIZE}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "BatchSize = ${BatchSize}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "DeviceType = ${DeviceType}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "CaseName = ${CaseName}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualFPS = ${ActualFPS}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainingTime = ${TrainingTime}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualLoss = ${ActualLoss}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
diff --git a/TensorFlow2/built-in/keras_sample/word2vec_ID2886_for_TensorFlow2.X/test/train_performance_1p.sh b/TensorFlow2/built-in/keras_sample/word2vec_ID2886_for_TensorFlow2.X/test/train_performance_1p.sh
new file mode 100644
index 0000000000000000000000000000000000000000..b8955010a6f7eb0055996205ee0439d54a204c22
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/word2vec_ID2886_for_TensorFlow2.X/test/train_performance_1p.sh
@@ -0,0 +1,173 @@
+#!/bin/bash
+#当前路径,不需要修改
+cur_path=`pwd`/../
+#集合通信参数,不需要修改
+export RANK_SIZE=1
+export JOB_ID=10087
+RANK_ID_START=0
+# 数据集路径,保持为空,不需要修改
+data_path=""
+#设置默认日志级别,不需要修改
+#export ASCEND_GLOBAL_LOG_LEVEL=3
+#基础参数,需要模型审视修改
+#网络名称,同目录名称
+Network="word2vec_ID2886_for_TensorFlow2.X"
+#训练epoch
+train_epochs=1
+#训练batch_size
+batch_size=128
+#训练step
+train_steps=30000
+#学习率
+learning_rate=1
+############维测参数##############
+precision_mode="allow_mix_precision"
+#维持参数,以下不需要修改
+over_dump=False
+if [[ $over_dump == True ]];then
+ over_dump_path=$cur_path/test/overflow_dump #此处cur_path为代码根目录
+ mkdir -p ${over_dump_path}
+fi
+data_dump_flag=False
+data_dump_step="10"
+profiling=False
+use_mixlist=True
+mixlist_file="./configs/ops_info.json"
+fusion_off_flag=False
+fusion_off_file="./configs/fusion_switch.cfg"
+auto_tune=False
+############维测参数##############
+# 帮助信息,不需要修改
+if [[ $1 == --help || $1 == -h ]];then
+ echo"usage:./train_performance_1p.sh "
+ echo " "
+ echo "parameter explain:
+ --precision_mode precision mode(allow_fp32_to_fp16/force_fp16/must_keep_origin_dtype/allow_mix_precision)
+ --over_dump if or not over detection, default is False
+ --data_dump_flag data dump flag, default is False
+ --data_dump_step data dump step, default is 10
+ --profiling if or not profiling for performance debug, default is False
+ --autotune whether to enable autotune, default is False
+ --data_path source data of training
+ -h/--help show help message
+ "
+ exit 1
+fi
+
+#参数校验,不需要修改
+for para in $*
+do
+ if [[ $para == --data_path* ]];then
+ data_path=`echo ${para#*=}`
+ elif [[ $para == --train_steps* ]];then
+ train_steps=`echo ${para#*=}`
+ elif [[ $para == --precision_mode* ]];then
+ precision_mode=`echo ${para#*=}`
+ elif [[ $para == --over_dump* ]];then
+ over_dump=`echo ${para#*=}`
+ over_dump_path=${cur_path}/output/overflow_dump
+ mkdir -p ${over_dump_path}
+ elif [[ $para == --data_dump_flag* ]];then
+ data_dump_flag=`echo ${para#*=}`
+ data_dump_path=${cur_path}/output/data_dump
+ mkdir -p ${data_dump_path}
+ elif [[ $para == --data_dump_step* ]];then
+ data_dump_step=`echo ${para#*=}`
+ elif [[ $para == --profiling* ]];then
+ profiling=`echo ${para#*=}`
+ profiling_dump_path=${cur_path}/output/profiling
+ mkdir -p ${profiling_dump_path}
+ elif [[ $para == --use_mixlist* ]];then
+ use_mixlist=`echo ${para#*=}`
+ elif [[ $para == --mixlist_file* ]];then
+ mixlist_file=`echo ${para#*=}`
+ elif [[ $para == --fusion_off_flag* ]];then
+ fusion_off_flag=`echo ${para#*=}`
+ elif [[ $para == --fusion_off_file* ]];then
+ fusion_off_file=`echo ${para#*=}`
+ elif [[ $para == --auto_tune* ]];then
+ auto_tune=`echo ${para#*=}`
+ fi
+done
+
+#校验是否传入data_path,不需要修改
+if [[ $data_path == "" ]];then
+ echo "[Error] para \"data_path\" must be confing"
+ exit 1
+fi
+
+#进入训练脚本目录,需要模型审视修改
+cd $cur_path
+#设置环境变量,不需要修改
+echo "Device ID: $ASCEND_DEVICE_ID"
+
+#创建DeviceID输出目录,不需要修改
+if [ -d ${cur_path}/test/output/${ASCEND_DEVICE_ID} ];then
+ rm -rf ${cur_path}/test/output/${ASCEND_DEVICE_ID}
+ mkdir -p ${cur_path}/test/output/$ASCEND_DEVICE_ID/ckpt
+else
+ mkdir -p ${cur_path}/test/output/$ASCEND_DEVICE_ID/ckpt
+fi
+#执行训练脚本,以下传参不需要修改,其他需要模型审视修改
+
+#训练开始时间,不需要修改
+start_time=$(date +%s)
+#python3 word2vec_chinese.py -dataset_dir=$data_path $step --precision_mode=$precision_mode > ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1
+nohup python3 word2vec_chinese.py \
+ --dataset_dir=$data_path \
+ --step=$train_steps \
+ --precision_mode=${precision_mode} \
+ --over_dump=${over_dump} \
+ --over_dump_path=${over_dump_path} \
+ --data_dump_flag=${data_dump_flag} \
+ --data_dump_step=${data_dump_step} \
+ --data_dump_path=${data_dump_path} \
+ --profiling=${profiling} \
+ --use_mixlist=${use_mixlist} \
+ --fusion_off_flag=${fusion_off_flag} \
+ --mixlist_file=${mixlist_file} \
+ --fusion_off_file=${fusion_off_file} \
+ --profiling_dump_path=${profiling_dump_path} \
+ --auto_tune=${auto_tune} > ${cur_path}/test/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1
+#训练结束时间,不需要修改
+end_time=$(date +%s)
+e2e_time=$(( $end_time - $start_time ))
+#结果打印,不需要修改
+echo "------------------ Final result ------------------"
+#输出性能FPS,需要模型审视修改
+train_time=`grep -a 'time cost' $cur_path/test/output/$ASCEND_DEVICE_ID/train_${ASCEND_DEVICE_ID}.log |awk 'END {print $9}'`
+FPS=`awk 'BEGIN{printf "%.2f\n",'2000'*'${batch_size}'/'${train_time}'}'`
+#打印,不需要修改
+echo "Final Performance images/sec : $train_time"
+#输出训练精度,需要模型审视修改
+train_accuracy=`grep -a 'loss' $cur_path/test/output/$ASCEND_DEVICE_ID/train_${ASCEND_DEVICE_ID}.log |awk 'END{print $5}' | awk -F ',' '{print $1}'`
+
+#打印,不需要修改
+echo "Final Train Accuracy : ${train_accuracy}"
+echo "E2E Training Duration sec : $e2e_time"
+#稳定性精度看护结果汇总
+#训练用例信息,不需要修改
+BatchSize=${batch_size}
+DeviceType=`uname -m`
+CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf'
+##获取性能数据
+#吞吐量,不需要修改
+ActualFPS=${FPS}
+#单迭代训练时长,不需要修改
+TrainingTime=$train_time
+#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视
+grep loss $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | awk -F"loss = " '{print $2}' | awk -F ',' '{print $1}' > $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt
+#最后一个迭代loss值,不需要修改
+ActualLoss=`awk 'END {print}' $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt`
+
+#关键信息打印到${CaseName}.log中,不需要修改
+echo "Network = ${Network}" > $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "RankSize = ${RANK_SIZE}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "BatchSize = ${BatchSize}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "DeviceType = ${DeviceType}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "CaseName = ${CaseName}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualFPS = ${ActualFPS}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainingTime = ${TrainingTime}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualLoss = ${ActualLoss}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log
diff --git a/TensorFlow2/built-in/keras_sample/word2vec_ID2886_for_TensorFlow2.X/word2vec_chinese.py b/TensorFlow2/built-in/keras_sample/word2vec_ID2886_for_TensorFlow2.X/word2vec_chinese.py
new file mode 100644
index 0000000000000000000000000000000000000000..f82016aa13853a9e0cd7a0bb02af3ef6ccc055c5
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/word2vec_ID2886_for_TensorFlow2.X/word2vec_chinese.py
@@ -0,0 +1,362 @@
+#!usr/bin/env python
+# -*- coding:utf-8 -*-
+#
+# Copyright 2017 The TensorFlow Authors. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============================================================================
+# Copyright 2021 Huawei Technologies Co., Ltd
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+from __future__ import absolute_import
+from __future__ import division
+from __future__ import print_function
+
+import collections
+import math
+import random
+import jieba
+import numpy as np
+from six.moves import xrange
+import tensorflow as tf
+import time
+import sys
+import os
+import argparse
+import ast
+
+import npu_device
+from npu_device.compat.v1.npu_init import *
+npu_device.compat.enable_v1()
+
+parser = argparse.ArgumentParser(description='config')
+parser.add_argument('--dataset_dir', type=str, default='./cnews', help='dataset dir')
+parser.add_argument('--step', type=int, default=30000, help='train steps')
+parser.add_argument('--precision_mode', type=str, default='allow_mix_precision', help='precision mode')
+
+#===============================NPU Migration=========================================
+parser.add_argument('--over_dump', dest='over_dump', type=ast.literal_eval,
+ help='if or not over detection, default is False')
+parser.add_argument('--data_dump_flag', dest='data_dump_flag', type=ast.literal_eval,
+ help='data dump flag, default is False')
+parser.add_argument('--data_dump_step', default="10",
+ help='data dump step, default is 10')
+parser.add_argument('--profiling', dest='profiling', type=ast.literal_eval,help='if or not profiling for performance debug, default is False')
+parser.add_argument('--profiling_dump_path', default="/home/data", type=str,help='the path to save profiling data')
+parser.add_argument('--over_dump_path', default="/home/data", type=str,help='the path to save over dump data')
+parser.add_argument('--data_dump_path', default="/home/data", type=str,help='the path to save dump data')
+parser.add_argument('--use_mixlist', dest='use_mixlist', type=ast.literal_eval,
+ help='use_mixlist flag, default is False')
+parser.add_argument('--fusion_off_flag', dest='fusion_off_flag', type=ast.literal_eval,
+ help='fusion_off flag, default is False')
+parser.add_argument('--mixlist_file', default="ops_info.json", type=str,help='mixlist file name, default is ops_info.json')
+parser.add_argument('--fusion_off_file', default="fusion_switch.cfg", type=str,help='fusion_off file name, default is fusion_switch.cfg')
+parser.add_argument('--auto_tune', dest='auto_tune', type=ast.literal_eval, help='autotune, default is False')
+#===============================NPU Migration=========================================
+
+FLAGS = parser.parse_args()
+
+def npu_tf_optimizer(opt):
+ npu_opt = NPUDistributedOptimizer(opt)
+ # if FLAGS.precision_mode == "allow_mix_precision":
+ # loss_scale_manager = ExponentialUpdateLossScaleManager(
+ # init_loss_scale=2**32,
+ # incr_every_n_steps=1000,
+ # decr_every_n_nan_or_inf=2,
+ # decr_ratio=0.5)
+ # npu_opt = NPULossScaleOptimizer(npu_opt, loss_scale_manager)
+ return npu_opt
+
+def npu_session_config_init(session_config=None):
+ session_config = tf.compat.v1.ConfigProto()
+ custom_op = session_config.graph_options.rewrite_options.custom_optimizers.add()
+ custom_op.name = 'NpuOptimizer'
+ custom_op.parameter_map["enable_data_pre_proc"].b = True
+ custom_op.parameter_map["iterations_per_loop"].i = 10
+ if FLAGS.data_dump_flag:
+ custom_op.parameter_map["enable_dump"].b = True
+ custom_op.parameter_map["dump_path"].s = tf.compat.as_bytes(FLAGS.data_dump_path)
+ custom_op.parameter_map["dump_step"].s = tf.compat.as_bytes(FLAGS.data_dump_step)
+ custom_op.parameter_map["dump_mode"].s = tf.compat.as_bytes("all")
+ if FLAGS.over_dump:
+ custom_op.parameter_map["enable_dump_debug"].b = True
+ custom_op.parameter_map["dump_path"].s = tf.compat.as_bytes(FLAGS.over_dump_path)
+ custom_op.parameter_map["dump_debug_mode"].s = tf.compat.as_bytes("all")
+ if FLAGS.profiling:
+ custom_op.parameter_map["precision_mode"].b = True
+ profiling_options = '{"output":"' + FLAGS.profiling_dump_path + '", \
+ "training_trace":"on", \
+ "task_trace":"on", \
+ "aicpu":"on", \
+ "aic_metrics":"PipeUtilization",\
+ "fp_point":"", \
+ "bp_point":""}'
+ custom_op.parameter_map["profiling_options"].s = tf.compat.as_bytes(profiling_options)
+ custom_op.parameter_map["precision_mode"].s = tf.compat.as_bytes(FLAGS.precision_mode)
+ if FLAGS.use_mixlist and FLAGS.precision_mode=='allow_mix_precision':
+ custom_op.parameter_map["modify_mixlist"].s = tf.compat.as_bytes(FLAGS.mixlist_file)
+ if FLAGS.fusion_off_flag:
+ custom_op.parameter_map["sfusion_switch_file"].s = tf.compat.as_bytes(FLAGS.fusion_off_file)
+ if FLAGS.auto_tune:
+ custom_op.parameter_map["auto_tune_mode"].s = tf.compat.as_bytes("RL,GA")
+ session_config.graph_options.rewrite_options.remapping = RewriterConfig.OFF
+ session_config.graph_options.rewrite_options.memory_optimization = RewriterConfig.OFF
+ return session_config
+
+# Step 1: Download the data.
+# Read the data into a list of strings.
+def read_data():
+ global FLAGS
+ """
+ 对要训练的文本进行处理,最后把文本的内容的所有词放在一个列表中
+ """
+ #读取停用词
+ stop_words = []
+ with open('stop_words.txt',"r",encoding="UTF-8") as f:
+ line = f.readline()
+ while line:
+ stop_words.append(line[:(-1)])
+ line = f.readline()
+ stop_words = set(stop_words)
+ print('停用词读取完毕,共{n}个词'.format(n=len(stop_words)))
+
+ # 读取文本,预处理,分词,得到词典
+ raw_word_list = []
+ # with open('doupocangqiong.txt',"r", encoding='UTF-8') as f:
+ val_txt = os.path.join(FLAGS.dataset_dir, './cnews.val.txt')
+ with open(val_txt, 'r', encoding='UTF-8') as f:
+ line = f.readline()
+ while line:
+ while ('\n' in line):
+ line = line.replace('\n','')
+ while (' ' in line):
+ line = line.replace(' ','')
+ if (len(line)>0): # 如果句子非空
+ raw_words = list(jieba.cut(line,cut_all=False))
+ raw_word_list.extend(raw_words)
+ line=f.readline()
+ return raw_word_list
+
+#step 1:读取文件中的内容组成一个列表
+words = read_data()
+print('Data size', len(words))
+
+# Step 2: Build the dictionary and replace rare words with UNK token.
+vocabulary_size = 50000
+
+def build_dataset(words):
+ count = [['UNK', (-1)]]
+ count.extend(collections.Counter(words).most_common(vocabulary_size - 1))
+ print("count",len(count))
+ dictionary = dict()
+ for (word, _) in count:
+ dictionary[word] = len(dictionary)
+ data = list()
+ unk_count = 0
+ for word in words:
+ if (word in dictionary):
+ index = dictionary[word]
+ else:
+ index = 0
+ unk_count += 1
+ data.append(index)
+ count[0][1] = unk_count
+ reverse_dictionary = dict(zip(dictionary.values(), dictionary.keys()))
+ return data, count, dictionary, reverse_dictionary
+
+data, count, dictionary, reverse_dictionary = build_dataset(words)
+#删除words节省内存
+del words
+print('Most common words (+UNK)', count[:5])
+print('Sample data', data[:10], [reverse_dictionary[i] for i in data[:10]])
+
+data_index = 0
+
+
+# Step 3: Function to generate a training batch for the skip-gram model.
+def generate_batch(batch_size, num_skips, skip_window):
+ global data_index
+ assert batch_size % num_skips == 0
+ assert num_skips <= 2 * skip_window
+ batch = np.ndarray(shape=(batch_size), dtype=np.int32)
+ labels = np.ndarray(shape=(batch_size, 1), dtype=np.int32)
+ span = 2 * skip_window + 1 # [ skip_window target skip_window ]
+ buffer = collections.deque(maxlen=span)
+ for _ in range(span):
+ buffer.append(data[data_index])
+ data_index = (data_index + 1) % len(data)
+ for i in range(batch_size // num_skips):
+ target = skip_window # target label at the center of the buffer
+ targets_to_avoid = [skip_window]
+ for j in range(num_skips):
+ while target in targets_to_avoid:
+ target = random.randint(0, span - 1)
+ targets_to_avoid.append(target)
+ batch[i * num_skips + j] = buffer[skip_window]
+ labels[i * num_skips + j, 0] = buffer[target]
+ buffer.append(data[data_index])
+ data_index = (data_index + 1) % len(data)
+ return batch, labels
+
+batch, labels = generate_batch(batch_size=8, num_skips=2, skip_window=1)
+for i in range(8):
+ print(batch[i], reverse_dictionary[batch[i]],'->', labels[i, 0], reverse_dictionary[labels[i, 0]])
+
+# Step 4: Build and train a skip-gram model.
+batch_size = 128
+embedding_size = 128
+skip_window = 1
+num_skips = 2
+valid_size = 9 #切记这个数字要和len(valid_word)对应,要不然会报错哦
+valid_window = 100
+num_sampled = 64 # Number of negative examples to sample.
+
+#验证集
+# valid_word = ['萧炎','灵魂','火焰','萧薰儿','药老','天阶',"云岚宗","乌坦城","惊诧"]
+valid_word = ['城市', '记者', '体育', '教练', '足球', '赛季', '奥运会', '丑闻', '足协']
+valid_examples =[dictionary[li] for li in valid_word]
+
+graph = tf.Graph()
+with graph.as_default():
+ # Input data.
+ train_inputs = tf.compat.v1.placeholder(tf.int32, shape=[batch_size])
+ train_labels = tf.compat.v1.placeholder(tf.int32, shape=[batch_size, 1])
+ valid_dataset = tf.constant(valid_examples, dtype=tf.int32)
+
+ # Ops and variables pinned to the CPU because of missing GPU implementation
+ with tf.device('/cpu:0'):
+ # Look up embeddings for inputs.
+ embeddings = tf.Variable(
+ tf.random.uniform([vocabulary_size, embedding_size], -1.0, 1.0))
+ embed = tf.nn.embedding_lookup(params=embeddings, ids=train_inputs)
+
+ # Construct the variables for the NCE loss
+ nce_weights = tf.Variable(
+ tf.random.truncated_normal([vocabulary_size, embedding_size],
+ stddev=1.0 / math.sqrt(embedding_size)))
+ nce_biases = tf.Variable(tf.zeros([vocabulary_size]),dtype=tf.float32)
+
+ # Compute the average NCE loss for the batch.
+ # tf.nce_loss automatically draws a new sample of the negative labels each
+ # time we evaluate the loss.
+ loss = tf.reduce_mean(input_tensor=tf.nn.nce_loss(weights=nce_weights,
+ biases=nce_biases,
+ inputs=embed,
+ labels=train_labels,
+ num_sampled=num_sampled,
+ num_classes=vocabulary_size))
+
+ # Construct the SGD optimizer using a learning rate of 1.0.
+ optimizer = npu_tf_optimizer(tf.compat.v1.train.GradientDescentOptimizer(1.0)).minimize(loss)
+
+ # Compute the cosine similarity between minibatch examples and all embeddings.
+ norm = tf.sqrt(tf.reduce_sum(input_tensor=tf.square(embeddings), axis=1, keepdims=True))
+ normalized_embeddings = embeddings / norm
+ valid_embeddings = tf.nn.embedding_lookup(params=normalized_embeddings, ids=valid_dataset)
+ similarity = tf.matmul(valid_embeddings, normalized_embeddings, transpose_b=True)
+
+ # Add variable initializer.
+ init = tf.compat.v1.global_variables_initializer()
+
+# Step 5: Begin training.
+num_steps = FLAGS.step
+
+with tf.compat.v1.Session(graph=graph, config=npu_session_config_init()) as session:
+ # We must initialize all variables before we use them.
+ init.run()
+ print("Initialized")
+
+ average_loss = 0
+ duration = 0
+
+ for step in xrange(num_steps):
+ start_time = time.time()
+ batch_inputs, batch_labels = generate_batch(batch_size, num_skips, skip_window)
+ feed_dict = {train_inputs: batch_inputs, train_labels: batch_labels}
+
+ # We perform one update step by evaluating the optimizer op (including it
+ # in the list of returned values for session.run()
+ _, loss_val = session.run([optimizer, loss], feed_dict=feed_dict)
+ average_loss += loss_val
+ duration += (time.time() - start_time)
+
+ if step % 200 == 0:
+ if step > 0:
+ average_loss /= 200
+ # The average loss is an estimate of the loss over the last 2000 batches.
+ # print("Average loss at step ", step, ": ", average_loss)
+ print('step= ', step, 'loss = {:3f}, time cost = {:4f} s'.format(average_loss, duration))
+ average_loss = 0
+ duration=0
+
+ # Note that this is expensive (~20% slowdown if computed every 500 steps)
+ if step % 10000 == 0:
+ sim = similarity.eval()
+ for i in xrange(valid_size):
+ valid_word = reverse_dictionary[valid_examples[i]]
+ top_k = 8 # number of nearest neighbors
+ nearest = (-sim[i, :]).argsort()[:top_k]
+ log_str = "Nearest to %s:" % valid_word
+ for k in xrange(top_k):
+ close_word = reverse_dictionary[nearest[k]]
+ log_str = "%s %s," % (log_str, close_word)
+ print(log_str)
+ final_embeddings = normalized_embeddings.eval()
+
+# Step 6: Visualize the embeddings.
+def plot_with_labels(low_dim_embs, labels, filename='images/tsne3.png',fonts=None):
+ assert low_dim_embs.shape[0] >= len(labels), "More labels than embeddings"
+ plt.figure(figsize=(18, 18)) # in inches
+ for i, label in enumerate(labels):
+ x, y = low_dim_embs[i, :]
+ plt.scatter(x, y)
+ plt.annotate(label,
+ fontproperties=fonts,
+ xy=(x, y),
+ xytext=(5, 2),
+ textcoords='offset points',
+ ha='right',
+ va='bottom')
+
+ plt.savefig(filename,dpi=800)
+
+try:
+ from sklearn.manifold import TSNE
+ import matplotlib.pyplot as plt
+ from matplotlib.font_manager import FontProperties
+
+ #为了在图片上能显示出中文
+ # font = FontProperties(fname=r"c:\windows\fonts\simsun.ttc", size=14)
+ f_name = os.path.join(FLAGS.dataset_dir, "./SIMSUN.TTC")
+ font = FontProperties(fname=f_name, size=14)
+
+ tsne = TSNE(perplexity=30, n_components=2, init='pca', n_iter=5000)
+ plot_only = 500
+ low_dim_embs = tsne.fit_transform(final_embeddings[:plot_only, :])
+ labels = [reverse_dictionary[i] for i in xrange(plot_only)]
+ plot_with_labels(low_dim_embs, labels,fonts=font)
+
+
+except ImportError:
+ print("Please install sklearn, matplotlib, and scipy to visualize embeddings.")
\ No newline at end of file
diff --git a/TensorFlow2/built-in/keras_sample/zero_dce_ID2548_for_TensorFlow2.X/LICENSE b/TensorFlow2/built-in/keras_sample/zero_dce_ID2548_for_TensorFlow2.X/LICENSE
new file mode 100644
index 0000000000000000000000000000000000000000..51d555a151df9c6c96d16137aa4bcf6142a447ef
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/zero_dce_ID2548_for_TensorFlow2.X/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2018 Ke YU
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/TensorFlow2/built-in/keras_sample/zero_dce_ID2548_for_TensorFlow2.X/README.md b/TensorFlow2/built-in/keras_sample/zero_dce_ID2548_for_TensorFlow2.X/README.md
new file mode 100644
index 0000000000000000000000000000000000000000..350ffb972893fb0dae1e06242d3592320eedb80e
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/zero_dce_ID2548_for_TensorFlow2.X/README.md
@@ -0,0 +1,197 @@
+- [基本信息](#基本信息.md)
+- [概述](#概述.md)
+- [训练环境准备](#训练环境准备.md)
+- [快速上手](#快速上手.md)
+- [迁移学习指导](#迁移学习指导.md)
+- [高级参考](#高级参考.md)
+基本信息
+
+**发布者(Publisher):Huawei**
+
+**应用领域(Application Domain):Image Classification**
+
+**版本(Version):1.1**
+
+**修改时间(Modified) :2022.4.8**
+
+**大小(Size):324KB**
+
+**框架(Framework):TensorFlow_2.4.1**
+
+**模型格式(Model Format):ckpt**
+
+**精度(Precision):Mixed**
+
+**处理器(Processor):昇腾910**
+
+**应用级别(Categories):Official**
+
+**描述(Description):基于TensorFlow框架的计算机视觉和模式识别网络训练代码**
+
+概述
+
+## 简述
+
+- 参考论文:
+
+ https://arxiv.org/abs/1810.03312
+
+- 参考实现:
+
+ https://github.com/yuke93/RL-Restore
+
+
+- 适配昇腾 AI 处理器的实现:
+
+ skip
+
+- 通过Git获取对应commit\_id的代码方法如下:
+
+ git clone {repository_url} # 克隆仓库的代码
+ cd {repository_name} # 切换到模型的代码仓目录
+ git checkout {branch} # 切换到对应分支
+ git reset --hard {commit_id} # 代码设置到对应的commit_id
+ cd {code_path} # 切换到模型代码所在路径,若仓库下只有该模型,则无需切换
+
+
+## 默认配置
+- 网络结构
+ - 24-layer, 1024-hidden, 16-heads, 340M parameters
+
+- 训练超参(单卡):
+ - Batch size: 16
+ - Train epoch: 100
+
+
+## 支持特性
+
+| 特性列表 | 是否支持 |
+|-------|------|
+| 分布式训练 | 否 |
+| 混合精度 | 是 |
+| 数据并行 | 否 |
+
+
+## 混合精度训练
+
+昇腾910 AI处理器提供自动混合精度功能,可以针对全网中float32数据类型的算子,按照内置的优化策略,自动将部分float32的算子降低精度到float16,从而在精度损失很小的情况下提升系统性能并减少内存使用。
+
+## 开启混合精度
+拉起脚本中,传入--precision_mode='allow_mix_precision'
+
+```
+ ./train_full_1p.sh --help
+
+parameter explain:
+ --precision_mode precision mode(allow_fp32_to_fp16/force_fp16/must_keep_origin_dtype/allow_mix_precision)
+ --over_dump if or not over detection, default is False
+ --data_dump_flag data dump flag, default is False
+ --data_dump_step data dump step, default is 10
+ --profiling if or not profiling for performance debug, default is False
+ --data_path source data of training
+ -h/--help show help message
+```
+
+相关代码示例:
+
+```
+flags.DEFINE_string(name='precision_mode', default= 'allow_fp32_to_fp16',
+ help='allow_fp32_to_fp16/force_fp16/ '
+ 'must_keep_origin_dtype/allow_mix_precision.')
+
+npu_device.global_options().precision_mode=FLAGS.precision_mode
+```
+
+训练环境准备
+
+- 硬件环境和运行环境准备请参见《[CANN软件安装指南](https://support.huawei.com/enterprise/zh/ascend-computing/cann-pid-251168373?category=installation-update)》
+- 运行以下命令安装依赖。
+```
+pip3 install requirements.txt
+```
+说明:依赖配置文件requirements.txt文件位于模型的根目录
+
+快速上手
+
+## 数据集准备
+
+1、用户自行准备好数据集。使用的数据集是lol_dataset
+
+数据集目录参考如下:
+
+```
+├── lol_dataset
+│ ├──eval15
+│ │ ├──high
+ ├──......
+│ │ ├──low
+ ├──......
+│ ├──our485
+│ │ ├──high
+ ├──......
+│ │ ├──low
+ ├──......
+```
+
+
+
+## 模型训练
+- 单击“立即下载”,并选择合适的下载方式下载源码包。
+
+- 开始训练。
+
+ 1. 启动训练之前,首先要配置程序运行相关环境变量。
+
+ 环境变量配置信息参见:
+
+ [Ascend 910训练平台环境变量设置](https://gitee.com/ascend/modelzoo/wikis/Ascend%20910%E8%AE%AD%E7%BB%83%E5%B9%B3%E5%8F%B0%E7%8E%AF%E5%A2%83%E5%8F%98%E9%87%8F%E8%AE%BE%E7%BD%AE?sort_id=3148819)
+
+
+ 2. 单卡训练
+
+ 2.1 单卡训练指令(脚本位于zero_dce_ID2548_for_TensorFlow2.X/test/train_full_1p.sh),其中“--data_path”修改为数据集的的路径。
+
+
+高级参考
+
+## 脚本和示例代码
+
+```
+|--test #训练脚本目录
+| |--train_full_1p.sh
+| |--train_performance_1p.sh
+| |--......
+|--zero_dce.py
+|--......
+```
+
+## 脚本参数
+
+```
+ --batch_size Total batch size for training,default:16
+ --epochs epochs ,default:100
+ --learning_rate learning_rate,default:1e-4
+ --data_path data_path,default:./lol_dataset
+ --log_steps steps per log,default:1e-4
+ --precision_mode the path to save over dump data,default:allow_mix_precision
+ --over_dump if or not over detection,default:False
+ --data_dump_flag data dump flag, default:False
+ --data_dump_step data dump step, default:10
+ --profiling profiling,default:False
+ --profiling_dump_path profiling_dump_path,default:/home/data
+ --over_dump_path over_dump_path,default:/home/data
+ --data_dump_path data_dump_path,default:/home/data
+ --use_mixlist use_mixlist flag,default:False
+ --fusion_off_flag fusion_off flag,default:False
+ --mixlist_file mixlist file name,default:ops_info.json
+ --fusion_off_file fusion_off_file,default:100
+ --auto_tune auto_tune flag, default:False
+```
+
+## 训练过程
+
+通过“模型训练”中的训练指令启动单卡训练。
+将训练脚本(train_full_1p.sh)中的data_path设置为训练数据集的路径。具体的流程参见“模型训练”的示例。
+
+
+
diff --git a/TensorFlow2/built-in/keras_sample/zero_dce_ID2548_for_TensorFlow2.X/modelzoo_level.txt b/TensorFlow2/built-in/keras_sample/zero_dce_ID2548_for_TensorFlow2.X/modelzoo_level.txt
new file mode 100644
index 0000000000000000000000000000000000000000..9f9b36084b426a5f1f9683f1e10fe071230705a1
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/zero_dce_ID2548_for_TensorFlow2.X/modelzoo_level.txt
@@ -0,0 +1,3 @@
+FuncStatus:OK
+PerfStatus:PERFECT
+PrecisionStatus:OK
\ No newline at end of file
diff --git a/TensorFlow2/built-in/keras_sample/zero_dce_ID2548_for_TensorFlow2.X/requirements.txt b/TensorFlow2/built-in/keras_sample/zero_dce_ID2548_for_TensorFlow2.X/requirements.txt
new file mode 100644
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
diff --git a/TensorFlow2/built-in/keras_sample/zero_dce_ID2548_for_TensorFlow2.X/test/train_full_1p.sh b/TensorFlow2/built-in/keras_sample/zero_dce_ID2548_for_TensorFlow2.X/test/train_full_1p.sh
new file mode 100644
index 0000000000000000000000000000000000000000..80ef963c31a957c7ad4b37c7603037450482a71f
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/zero_dce_ID2548_for_TensorFlow2.X/test/train_full_1p.sh
@@ -0,0 +1,231 @@
+#!/bin/bash
+
+#当前路径,不需要修改
+cur_path=`pwd`
+#export ASCEND_SLOG_PRINT_TO_STDOUT=1
+
+#集合通信参数,不需要修改
+
+export RANK_SIZE=1
+export JOB_ID=10087
+RANK_ID_START=0
+
+# 数据集路径,保持为空,不需要修改
+data_path=""
+
+#基础参数,需要模型审视修改
+#网络名称,同目录名称
+Network="zero_dce_ID2548_for_TensorFlow2.X"
+#训练epoch
+train_epochs=100
+#训练batch_size
+batch_size=16
+
+# #维测参数,precision_mode需要模型审视修改
+# precision_mode="allow_mix_precision"
+# #维持参数,以下不需要修改
+# over_dump=False
+# data_dump_flag=False
+# data_dump_step="10"
+# profiling=False
+# autotune=False
+
+############维测参数##############
+precision_mode="allow_mix_precision"
+#维持参数,以下不需要修改
+over_dump=False
+if [[ $over_dump == True ]];then
+ over_dump_path=$cur_path/test/overflow_dump #此处cur_path为代码根目录
+ mkdir -p ${over_dump_path}
+fi
+data_dump_flag=False
+data_dump_step="10"
+profiling=False
+use_mixlist=False
+mixlist_file="ops_info.json"
+fusion_off_flag=False
+fusion_off_file="fusion_switch.cfg"
+auto_tune=False
+############维测参数##############
+
+# 帮助信息,不需要修改
+if [[ $1 == --help || $1 == -h ]];then
+ echo"usage:./train_performance_1p.sh "
+ echo " "
+ echo "parameter explain:
+ --precision_mode precision mode(allow_fp32_to_fp16/force_fp16/must_keep_origin_dtype/allow_mix_precision)
+ --over_dump if or not over detection, default is False
+ --data_dump_flag data dump flag, default is False
+ --data_dump_step data dump step, default is 10
+ --profiling if or not profiling for performance debug, default is False
+ --data_path source data of training
+ --auto_tune if or not auto_tune, default is False
+ -h/--help show help message
+ "
+ exit 1
+fi
+
+# #参数校验,不需要修改
+# for para in $*
+# do
+# if [[ $para == --precision_mode* ]];then
+# precision_mode=`echo ${para#*=}`
+# elif [[ $para == --over_dump* ]];then
+# over_dump=`echo ${para#*=}`
+# over_dump_path=${cur_path}/output/overflow_dump
+# mkdir -p ${over_dump_path}
+# elif [[ $para == --data_dump_flag* ]];then
+# data_dump_flag=`echo ${para#*=}`
+# data_dump_path=${cur_path}/output/data_dump
+# mkdir -p ${data_dump_path}
+# elif [[ $para == --data_dump_step* ]];then
+# data_dump_step=`echo ${para#*=}`
+# elif [[ $para == --profiling* ]];then
+# profiling=`echo ${para#*=}`
+# profiling_dump_path=${cur_path}/output/profiling
+# mkdir -p ${profiling_dump_path}
+# elif [[ $para == --data_path* ]];then
+# data_path=`echo ${para#*=}`
+# fi
+# done
+
+############维测参数##############
+for para in $*
+do
+ if [[ $para == --precision_mode* ]];then
+ precision_mode=`echo ${para#*=}`
+ elif [[ $para == --over_dump* ]];then
+ over_dump=`echo ${para#*=}`
+ over_dump_path=${cur_path}/output/overflow_dump
+ mkdir -p ${over_dump_path}
+ elif [[ $para == --data_dump_flag* ]];then
+ data_dump_flag=`echo ${para#*=}`
+ data_dump_path=${cur_path}/output/data_dump
+ mkdir -p ${data_dump_path}
+ elif [[ $para == --data_dump_step* ]];then
+ data_dump_step=`echo ${para#*=}`
+ elif [[ $para == --profiling* ]];then
+ profiling=`echo ${para#*=}`
+ profiling_dump_path=${cur_path}/output/profiling
+ mkdir -p ${profiling_dump_path}
+ elif [[ $para == --data_path* ]];then
+ data_path=`echo ${para#*=}`
+ elif [[ $para == --use_mixlist* ]];then
+ use_mixlist=`echo ${para#*=}`
+ elif [[ $para == --mixlist_file* ]];then
+ mixlist_file=`echo ${para#*=}`
+ elif [[ $para == --fusion_off_flag* ]];then
+ fusion_off_flag=`echo ${para#*=}`
+ elif [[ $para == --fusion_off_file* ]];then
+ fusion_off_file=`echo ${para#*=}`
+ elif [[ $para == --auto_tune* ]];then
+ auto_tune=`echo ${para#*=}`
+ fi
+done
+############维测参数##############
+
+#校验是否传入data_path,不需要修改
+if [[ $data_path == "" ]];then
+ echo "[Error] para \"data_path\" must be confing"
+ exit 1
+fi
+
+#训练开始时间,不需要修改
+start_time=$(date +%s)
+
+#进入训练脚本目录,需要模型审视修改
+cd $cur_path/../
+
+for((RANK_ID=$RANK_ID_START;RANK_ID<$((RANK_SIZE+RANK_ID_START));RANK_ID++));
+do
+ #设置环境变量,不需要修改
+ echo "Device ID: $ASCEND_DEVICE_ID"
+ export RANK_ID=$RANK_ID
+
+
+
+ #创建DeviceID输出目录,不需要修改
+ if [ -d ${cur_path}/output/${ASCEND_DEVICE_ID} ];then
+ rm -rf ${cur_path}/output/${ASCEND_DEVICE_ID}
+ mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt
+ else
+ mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt
+ fi
+
+ #执行训练脚本,以下传参不需要修改,其他需要模型审视修改
+ python3 zero_dce.py \
+ --data_path=$data_path/lol_dataset/ \
+ --epochs=$train_epochs \
+ --batch_size=$batch_size \
+ --precision_mode=${precision_mode} \
+ --over_dump=${over_dump} \
+ --over_dump_path=${over_dump_path} \
+ --data_dump_flag=${data_dump_flag} \
+ --data_dump_step=${data_dump_step} \
+ --data_dump_path=${data_dump_path} \
+ --profiling=${profiling} \
+ --use_mixlist=${use_mixlist} \
+ --fusion_off_flag=${fusion_off_flag} \
+ --mixlist_file=${mixlist_file} \
+ --auto_tune=${auto_tune} \
+ --fusion_off_file=${fusion_off_file} \
+ --profiling_dump_path=${profiling_dump_path} > ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 &
+done
+wait
+
+#conda deactivate
+#训练结束时间,不需要修改
+end_time=$(date +%s)
+e2e_time=$(( $end_time - $start_time ))
+
+#结果打印,不需要修改
+echo "------------------ Final result ------------------"
+#输出性能FPS,需要模型审视修改
+# Time=`grep "ms/step" $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log| tail -n 1 | awk -F'-' '{print $2}' | awk -F' ' '{print $2}' | awk -F'ms' '{print $1}'`
+# FPS=`awk 'BEGIN{printf "%.2f\n",'1000'*'${batch_size}'/'${Time}'}'`
+single_batch_step_sec=`grep TimeHistory $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk 'END {print $4}'`
+FPS=`awk 'BEGIN{printf "%.2f\n",'${single_batch_step_sec}'}'`
+
+#打印,不需要修改
+echo "Final Performance images/sec : $FPS"
+
+#输出训练精度,需要模型审视修改
+#train_accuracy=null
+#打印,不需要修改
+echo "Final Train Accuracy : ${train_accuracy}"
+echo "E2E Training Duration sec : $e2e_time"
+
+#稳定性精度看护结果汇总
+#训练用例信息,不需要修改
+BatchSize=${batch_size}
+DeviceType=`uname -m`
+CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc'
+
+##获取性能数据
+#吞吐量,不需要修改
+ActualFPS=${FPS}
+#单迭代训练时长,不需要修改
+# TrainingTime=`awk 'BEGIN{printf "%.2f\n",'${BatchSize}'*1000/'${FPS}'}'`
+TrainingTime=`awk 'BEGIN{printf "%.2f\n",'${BatchSize}'*'${RANK_SIZE}'*1000/'${FPS}'}'`
+
+#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视
+# cat $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log| tr -d '\b\r' | grep -Eo "ms/step - total_loss: [0-9]*\.[0-9]*" | awk -F":" '{print $2}'>> $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt
+cat $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log| grep total_loss | awk -F " " '{print $6}' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt
+
+#最后一个迭代loss值,不需要修改
+# ActualLoss=`cat $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log| tr -d '\b\r' | grep -Eo "ms/step - total_loss: [0-9]*\.[0-9]*" | awk -F":" '{print $2}' | tail -n 1`
+ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt`
+
+train_accuracy=${ActualLoss}
+
+#关键信息打印到${CaseName}.log中,不需要修改
+echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log
diff --git a/TensorFlow2/built-in/keras_sample/zero_dce_ID2548_for_TensorFlow2.X/test/train_performance_1p.sh b/TensorFlow2/built-in/keras_sample/zero_dce_ID2548_for_TensorFlow2.X/test/train_performance_1p.sh
new file mode 100644
index 0000000000000000000000000000000000000000..458bef30169532e281a9655841dbd09d230fa047
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/zero_dce_ID2548_for_TensorFlow2.X/test/train_performance_1p.sh
@@ -0,0 +1,230 @@
+#!/bin/bash
+
+#当前路径,不需要修改
+cur_path=`pwd`
+#export ASCEND_SLOG_PRINT_TO_STDOUT=1
+
+#集合通信参数,不需要修改
+
+export RANK_SIZE=1
+export JOB_ID=10087
+RANK_ID_START=0
+
+# 数据集路径,保持为空,不需要修改
+data_path=""
+
+#基础参数,需要模型审视修改
+#网络名称,同目录名称
+Network="zero_dce_ID2548_for_TensorFlow2.X"
+#训练epoch
+train_epochs=50
+#训练batch_size
+batch_size=16
+
+# #维测参数,precision_mode需要模型审视修改
+# precision_mode="allow_mix_precision"
+# #维持参数,以下不需要修改
+# over_dump=False
+# data_dump_flag=False
+# data_dump_step="10"
+# profiling=False
+# autotune=False
+
+############维测参数##############
+precision_mode="allow_mix_precision"
+#维持参数,以下不需要修改
+over_dump=False
+if [[ $over_dump == True ]];then
+ over_dump_path=$cur_path/test/overflow_dump #此处cur_path为代码根目录
+ mkdir -p ${over_dump_path}
+fi
+data_dump_flag=False
+data_dump_step="10"
+profiling=False
+use_mixlist=False
+mixlist_file="ops_info.json"
+fusion_off_flag=False
+fusion_off_file="fusion_switch.cfg"
+auto_tune=False
+############维测参数##############
+
+# 帮助信息,不需要修改
+if [[ $1 == --help || $1 == -h ]];then
+ echo"usage:./train_performance_1p.sh "
+ echo " "
+ echo "parameter explain:
+ --precision_mode precision mode(allow_fp32_to_fp16/force_fp16/must_keep_origin_dtype/allow_mix_precision)
+ --over_dump if or not over detection, default is False
+ --data_dump_flag data dump flag, default is False
+ --data_dump_step data dump step, default is 10
+ --profiling if or not profiling for performance debug, default is False
+ --data_path source data of training
+ --auto_tune if or not auto_tune, default is False
+ -h/--help show help message
+ "
+ exit 1
+fi
+
+# #参数校验,不需要修改
+# for para in $*
+# do
+# if [[ $para == --precision_mode* ]];then
+# precision_mode=`echo ${para#*=}`
+# elif [[ $para == --over_dump* ]];then
+# over_dump=`echo ${para#*=}`
+# over_dump_path=${cur_path}/output/overflow_dump
+# mkdir -p ${over_dump_path}
+# elif [[ $para == --data_dump_flag* ]];then
+# data_dump_flag=`echo ${para#*=}`
+# data_dump_path=${cur_path}/output/data_dump
+# mkdir -p ${data_dump_path}
+# elif [[ $para == --data_dump_step* ]];then
+# data_dump_step=`echo ${para#*=}`
+# elif [[ $para == --profiling* ]];then
+# profiling=`echo ${para#*=}`
+# profiling_dump_path=${cur_path}/output/profiling
+# mkdir -p ${profiling_dump_path}
+# elif [[ $para == --data_path* ]];then
+# data_path=`echo ${para#*=}`
+# fi
+# done
+
+############维测参数##############
+for para in $*
+do
+ if [[ $para == --precision_mode* ]];then
+ precision_mode=`echo ${para#*=}`
+ elif [[ $para == --over_dump* ]];then
+ over_dump=`echo ${para#*=}`
+ over_dump_path=${cur_path}/output/overflow_dump
+ mkdir -p ${over_dump_path}
+ elif [[ $para == --data_dump_flag* ]];then
+ data_dump_flag=`echo ${para#*=}`
+ data_dump_path=${cur_path}/output/data_dump
+ mkdir -p ${data_dump_path}
+ elif [[ $para == --data_dump_step* ]];then
+ data_dump_step=`echo ${para#*=}`
+ elif [[ $para == --profiling* ]];then
+ profiling=`echo ${para#*=}`
+ profiling_dump_path=${cur_path}/output/profiling
+ mkdir -p ${profiling_dump_path}
+ elif [[ $para == --data_path* ]];then
+ data_path=`echo ${para#*=}`
+ elif [[ $para == --use_mixlist* ]];then
+ use_mixlist=`echo ${para#*=}`
+ elif [[ $para == --mixlist_file* ]];then
+ mixlist_file=`echo ${para#*=}`
+ elif [[ $para == --fusion_off_flag* ]];then
+ fusion_off_flag=`echo ${para#*=}`
+ elif [[ $para == --fusion_off_file* ]];then
+ fusion_off_file=`echo ${para#*=}`
+ elif [[ $para == --auto_tune* ]];then
+ auto_tune=`echo ${para#*=}`
+ fi
+done
+############维测参数##############
+
+#校验是否传入data_path,不需要修改
+if [[ $data_path == "" ]];then
+ echo "[Error] para \"data_path\" must be confing"
+ exit 1
+fi
+
+#训练开始时间,不需要修改
+start_time=$(date +%s)
+
+#进入训练脚本目录,需要模型审视修改
+cd $cur_path/../
+
+for((RANK_ID=$RANK_ID_START;RANK_ID<$((RANK_SIZE+RANK_ID_START));RANK_ID++));
+do
+ #设置环境变量,不需要修改
+ echo "Device ID: $ASCEND_DEVICE_ID"
+ export RANK_ID=$RANK_ID
+
+
+
+ #创建DeviceID输出目录,不需要修改
+ if [ -d ${cur_path}/output/${ASCEND_DEVICE_ID} ];then
+ rm -rf ${cur_path}/output/${ASCEND_DEVICE_ID}
+ mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt
+ else
+ mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt
+ fi
+
+ #执行训练脚本,以下传参不需要修改,其他需要模型审视修改
+ python3 zero_dce.py \
+ --data_path=$data_path/lol_dataset/ \
+ --epochs=$train_epochs \
+ --batch_size=$batch_size \
+ --precision_mode=${precision_mode} \
+ --over_dump=${over_dump} \
+ --over_dump_path=${over_dump_path} \
+ --data_dump_flag=${data_dump_flag} \
+ --data_dump_step=${data_dump_step} \
+ --data_dump_path=${data_dump_path} \
+ --profiling=${profiling} \
+ --use_mixlist=${use_mixlist} \
+ --fusion_off_flag=${fusion_off_flag} \
+ --mixlist_file=${mixlist_file} \
+ --auto_tune=${auto_tune} \
+ --fusion_off_file=${fusion_off_file} \
+ --profiling_dump_path=${profiling_dump_path} > ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 &
+done
+wait
+
+#conda deactivate
+#训练结束时间,不需要修改
+end_time=$(date +%s)
+e2e_time=$(( $end_time - $start_time ))
+
+#结果打印,不需要修改
+echo "------------------ Final result ------------------"
+#输出性能FPS,需要模型审视修改
+# Time=`grep "ms/step" $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log| tail -n 1 | awk -F'-' '{print $2}' | awk -F' ' '{print $2}' | awk -F'ms' '{print $1}'`
+# FPS=`awk 'BEGIN{printf "%.2f\n",'1000'*'${batch_size}'/'${Time}'}'`
+single_batch_step_sec=`grep TimeHistory $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk 'END {print $4}'`
+FPS=`awk 'BEGIN{printf "%.2f\n",'${single_batch_step_sec}'}'`
+
+#打印,不需要修改
+echo "Final Performance images/sec : $FPS"
+
+#输出训练精度,需要模型审视修改
+#train_accuracy=null
+#打印,不需要修改
+echo "Final Train Accuracy : ${train_accuracy}"
+echo "E2E Training Duration sec : $e2e_time"
+
+#稳定性精度看护结果汇总
+#训练用例信息,不需要修改
+BatchSize=${batch_size}
+DeviceType=`uname -m`
+CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf'
+
+##获取性能数据
+#吞吐量,不需要修改
+ActualFPS=${FPS}
+#单迭代训练时长,不需要修改
+# TrainingTime=`awk 'BEGIN{printf "%.2f\n",'${BatchSize}'*1000/'${FPS}'}'`
+TrainingTime=`awk 'BEGIN{printf "%.2f\n",'${BatchSize}'*'${RANK_SIZE}'*1000/'${FPS}'}'`
+
+#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视
+# cat $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log| tr -d '\b\r' | grep -Eo "ms/step - total_loss: [0-9]*\.[0-9]*" | awk -F":" '{print $2}'>> $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt
+cat $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log| grep total_loss | awk -F " " '{print $6}' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt
+
+#最后一个迭代loss值,不需要修改
+# ActualLoss=`cat $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log| tr -d '\b\r' | grep -Eo "ms/step - total_loss: [0-9]*\.[0-9]*" | awk -F":" '{print $2}' | tail -n 1`
+ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt`
+train_accuracy=${ActualLoss}
+
+#关键信息打印到${CaseName}.log中,不需要修改
+echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log
+echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log
diff --git a/TensorFlow2/built-in/keras_sample/zero_dce_ID2548_for_TensorFlow2.X/zero_dce.py b/TensorFlow2/built-in/keras_sample/zero_dce_ID2548_for_TensorFlow2.X/zero_dce.py
new file mode 100644
index 0000000000000000000000000000000000000000..367f3982f4046316db4ed9ce419e6d5d0e7d85af
--- /dev/null
+++ b/TensorFlow2/built-in/keras_sample/zero_dce_ID2548_for_TensorFlow2.X/zero_dce.py
@@ -0,0 +1,609 @@
+#
+# Copyright 2017 The TensorFlow Authors. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============================================================================
+# Copyright 2021 Huawei Technologies Co., Ltd
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+"""
+Title: Zero-DCE for low-light image enhancement
+Author: [Soumik Rakshit](http://github.com/soumik12345)
+Date created: 2021/09/18
+Last modified: 2021/09/19
+Description: Implementing Zero-Reference Deep Curve Estimation for low-light image enhancement.
+"""
+"""
+## Introduction
+
+**Zero-Reference Deep Curve Estimation** or **Zero-DCE** formulates low-light image
+enhancement as the task of estimating an image-specific
+[*tonal curve*](https://en.wikipedia.org/wiki/Curve_(tonality)) with a deep neural network.
+In this example, we train a lightweight deep network, **DCE-Net**, to estimate
+pixel-wise and high-order tonal curves for dynamic range adjustment of a given image.
+
+Zero-DCE takes a low-light image as input and produces high-order tonal curves as its output.
+These curves are then used for pixel-wise adjustment on the dynamic range of the input to
+obtain an enhanced image. The curve estimation process is done in such a way that it maintains
+the range of the enhanced image and preserves the contrast of neighboring pixels. This
+curve estimation is inspired by curves adjustment used in photo editing software such as
+Adobe Photoshop where users can adjust points throughout an image’s tonal range.
+
+Zero-DCE is appealing because of its relaxed assumptions with regard to reference images:
+it does not require any input/output image pairs during training.
+This is achieved through a set of carefully formulated non-reference loss functions,
+which implicitly measure the enhancement quality and guide the training of the network.
+
+### References
+
+- [Zero-Reference Deep Curve Estimation for Low-Light Image Enhancement](https://arxiv.org/pdf/2001.06826.pdf)
+- [Curves adjustment in Adobe Photoshop](https://helpx.adobe.com/photoshop/using/curves-adjustment.html)
+"""
+
+"""
+## Downloading LOLDataset
+
+The **LoL Dataset** has been created for low-light image enhancement. It provides 485
+images for training and 15 for testing. Each image pair in the dataset consists of a
+low-light input image and its corresponding well-exposed reference image.
+"""
+
+import npu_device
+import argparse
+import ast
+#===============================NPU Migration=========================================
+parser = argparse.ArgumentParser()
+parser.add_argument('--batch_size', type=int, default=16, help='batch_size')
+parser.add_argument('--epochs', type=int, default=100, help='epochs')
+parser.add_argument('--learning_rate', type=int, default=1e-4, help='learning_rate')
+parser.add_argument('--data_path', type=str, default='./lol_dataset', help='data path')
+parser.add_argument('--log_steps', type=int, default=25, help='steps per log')
+parser.add_argument('--precision_mode', default="allow_mix_precision", type=str,help='the path to save over dump data')
+parser.add_argument('--over_dump', dest='over_dump', type=ast.literal_eval,
+ help='if or not over detection, default is False')
+parser.add_argument('--data_dump_flag', dest='data_dump_flag', type=ast.literal_eval,
+ help='data dump flag, default is False')
+parser.add_argument('--data_dump_step', default="10",
+ help='data dump step, default is 10')
+parser.add_argument('--profiling', dest='profiling', type=ast.literal_eval,help='if or not profiling for performance debug, default is False')
+parser.add_argument('--profiling_dump_path', default="/home/data", type=str,help='the path to save profiling data')
+parser.add_argument('--over_dump_path', default="/home/data", type=str,help='the path to save over dump data')
+parser.add_argument('--data_dump_path', default="/home/data", type=str,help='the path to save dump data')
+parser.add_argument('--use_mixlist', dest='use_mixlist', type=ast.literal_eval,
+ help='use_mixlist flag, default is False')
+parser.add_argument('--fusion_off_flag', dest='fusion_off_flag', type=ast.literal_eval,
+ help='fusion_off flag, default is False')
+parser.add_argument('--mixlist_file', default="ops_info.json", type=str,help='mixlist file name, default is ops_info.json')
+parser.add_argument('--fusion_off_file', default="fusion_switch.cfg", type=str,help='fusion_off file name, default is fusion_switch.cfg')
+parser.add_argument('--auto_tune', dest='auto_tune', type=ast.literal_eval,
+ help='auto_tune flag, default is False')
+args = parser.parse_args()
+
+def npu_config():
+ if args.data_dump_flag:
+ npu_device.global_options().dump_config.enable_dump = True
+ npu_device.global_options().dump_config.dump_path = args.data_dump_path
+ npu_device.global_options().dump_config.dump_step = args.data_dump_step
+ npu_device.global_options().dump_config.dump_mode = "all"
+
+ if args.over_dump:
+ npu_device.global_options().dump_config.enable_dump_debug = True
+ npu_device.global_options().dump_config.dump_path = args.over_dump_path
+ npu_device.global_options().dump_config.dump_debug_mode = "all"
+
+ if args.profiling:
+ npu_device.global_options().profiling_config.enable_profiling = True
+ profiling_options = '{"output":"' + args.profiling_dump_path + '", \
+ "training_trace":"on", \
+ "task_trace":"on", \
+ "aicpu":"on", \
+ "aic_metrics":"PipeUtilization",\
+ "fp_point":"", \
+ "bp_point":""}'
+ npu_device.global_options().profiling_config.profiling_options = profiling_options
+ npu_device.global_options().precision_mode = args.precision_mode
+ if args.use_mixlist and args.precision_mode=='allow_mix_precision':
+ npu_device.global_options().modify_mixlist="../configs/"+args.mixlist_file
+ if args.fusion_off_flag:
+ npu_device.global_options().fusion_switch_file="../configs/"+args.fusion_off_file
+ if args.auto_tune:
+ npu_device.global_options().auto_tune_mode="RL,GA"
+ npu_device.open().as_default()
+#===============================NPU Migration=========================================
+npu_config()
+
+import os
+import time
+import random
+import numpy as np
+from glob import glob
+from PIL import Image, ImageOps
+import matplotlib.pyplot as plt
+
+import tensorflow as tf
+from tensorflow import keras
+from tensorflow.keras import layers
+
+# def init_arg():
+# parser = argparse.ArgumentParser()
+# parser.add_argument('--batch_size', type=int, default=16, help='batch_size')
+# parser.add_argument('--epochs', type=int, default=100, help='epochs')
+# parser.add_argument('--learning_rate', type=int, default=1e-4, help='learning_rate')
+# parser.add_argument('--data_path', type=str, default='./lol_dataset', help='data path')
+# return parser.parse_args()
+
+
+# args = init_arg()
+
+"""shell
+gdown https://drive.google.com/uc?id=1DdGIJ4PZPlF2ikl8mNM9V-PdVxVLbQi6
+unzip -q lol_dataset.zip
+"""
+
+"""
+## Creating a TensorFlow Dataset
+
+We use 300 low-light images from the LoL Dataset training set for training, and we use
+the remaining 185 low-light images for validation. We resize the images to size `256 x
+256` to be used for both training and validation. Note that in order to train the DCE-Net,
+we will not require the corresponding enhanced images.
+"""
+
+IMAGE_SIZE = 256
+BATCH_SIZE = args.batch_size
+MAX_TRAIN_IMAGES = 400
+
+
+def load_data(image_path):
+ image = tf.io.read_file(image_path)
+ image = tf.image.decode_png(image, channels=3)
+ image = tf.image.resize(images=image, size=[IMAGE_SIZE, IMAGE_SIZE])
+ image = image / 255.0
+ return image
+
+
+def data_generator(low_light_images):
+ dataset = tf.data.Dataset.from_tensor_slices((low_light_images))
+ dataset = dataset.map(load_data, num_parallel_calls=tf.data.AUTOTUNE)
+ dataset = dataset.batch(BATCH_SIZE, drop_remainder=True)
+ return dataset
+
+
+train_low_light_images = sorted(glob(args.data_path + "/our485/low/*"))[:MAX_TRAIN_IMAGES]
+val_low_light_images = sorted(glob(args.data_path + "/our485/low/*"))[MAX_TRAIN_IMAGES:]
+test_low_light_images = sorted(glob(args.data_path + "/eval15/low/*"))
+
+
+train_dataset = data_generator(train_low_light_images)
+val_dataset = data_generator(val_low_light_images)
+
+print("Train Dataset:", train_dataset)
+print("Validation Dataset:", val_dataset)
+
+"""
+## The Zero-DCE Framework
+
+The goal of DCE-Net is to estimate a set of best-fitting light-enhancement curves
+(LE-curves) given an input image. The framework then maps all pixels of the input’s RGB
+channels by applying the curves iteratively to obtain the final enhanced image.
+
+### Understanding light-enhancement curves
+
+A ligh-enhancement curve is a kind of curve that can map a low-light image
+to its enhanced version automatically,
+where the self-adaptive curve parameters are solely dependent on the input image.
+When designing such a curve, three objectives should be taken into account:
+
+- Each pixel value of the enhanced image should be in the normalized range `[0,1]`, in order to
+avoid information loss induced by overflow truncation.
+- It should be monotonous, to preserve the contrast between neighboring pixels.
+- The shape of this curve should be as simple as possible,
+and the curve should be differentiable to allow backpropagation.
+
+The light-enhancement curve is separately applied to three RGB channels instead of solely on the
+illumination channel. The three-channel adjustment can better preserve the inherent color and reduce
+the risk of over-saturation.
+
+
+
+### DCE-Net
+
+The DCE-Net is a lightweight deep neural network that learns the mapping between an input
+image and its best-fitting curve parameter maps. The input to the DCE-Net is a low-light
+image while the outputs are a set of pixel-wise curve parameter maps for corresponding
+higher-order curves. It is a plain CNN of seven convolutional layers with symmetrical
+concatenation. Each layer consists of 32 convolutional kernels of size 3×3 and stride 1
+followed by the ReLU activation function. The last convolutional layer is followed by the
+Tanh activation function, which produces 24 parameter maps for 8 iterations, where each
+iteration requires three curve parameter maps for the three channels.
+
+
+"""
+
+
+def build_dce_net():
+ input_img = keras.Input(shape=[None, None, 3])
+ conv1 = layers.Conv2D(
+ 32, (3, 3), strides=(1, 1), activation="relu", padding="same"
+ )(input_img)
+ conv2 = layers.Conv2D(
+ 32, (3, 3), strides=(1, 1), activation="relu", padding="same"
+ )(conv1)
+ conv3 = layers.Conv2D(
+ 32, (3, 3), strides=(1, 1), activation="relu", padding="same"
+ )(conv2)
+ conv4 = layers.Conv2D(
+ 32, (3, 3), strides=(1, 1), activation="relu", padding="same"
+ )(conv3)
+ int_con1 = layers.Concatenate(axis=-1)([conv4, conv3])
+ conv5 = layers.Conv2D(
+ 32, (3, 3), strides=(1, 1), activation="relu", padding="same"
+ )(int_con1)
+ int_con2 = layers.Concatenate(axis=-1)([conv5, conv2])
+ conv6 = layers.Conv2D(
+ 32, (3, 3), strides=(1, 1), activation="relu", padding="same"
+ )(int_con2)
+ int_con3 = layers.Concatenate(axis=-1)([conv6, conv1])
+ x_r = layers.Conv2D(24, (3, 3), strides=(1, 1), activation="tanh", padding="same")(
+ int_con3
+ )
+ return keras.Model(inputs=input_img, outputs=x_r)
+
+
+"""
+## Loss functions
+
+To enable zero-reference learning in DCE-Net, we use a set of differentiable
+zero-reference losses that allow us to evaluate the quality of enhanced images.
+"""
+
+"""
+### Color constancy loss
+
+The *color constancy loss* is used to correct the potential color deviations in the
+enhanced image.
+"""
+
+
+def color_constancy_loss(x):
+ mean_rgb = tf.reduce_mean(x, axis=(1, 2), keepdims=True)
+ mr, mg, mb = mean_rgb[:, :, :, 0], mean_rgb[:, :, :, 1], mean_rgb[:, :, :, 2]
+ d_rg = tf.square(mr - mg)
+ d_rb = tf.square(mr - mb)
+ d_gb = tf.square(mb - mg)
+ return tf.sqrt(tf.square(d_rg) + tf.square(d_rb) + tf.square(d_gb))
+
+
+"""
+### Exposure loss
+
+To restrain under-/over-exposed regions, we use the *exposure control loss*.
+It measures the distance between the average intensity value of a local region
+and a preset well-exposedness level (set to `0.6`).
+"""
+
+
+def exposure_loss(x, mean_val=0.6):
+ x = tf.reduce_mean(x, axis=3, keepdims=True)
+ mean = tf.nn.avg_pool2d(x, ksize=16, strides=16, padding="VALID")
+ return tf.reduce_mean(tf.square(mean - mean_val))
+
+
+"""
+### Illumination smoothness loss
+
+To preserve the monotonicity relations between neighboring pixels, the
+*illumination smoothness loss* is added to each curve parameter map.
+"""
+
+
+def illumination_smoothness_loss(x):
+ batch_size = tf.shape(x)[0]
+ h_x = tf.shape(x)[1]
+ w_x = tf.shape(x)[2]
+ count_h = (tf.shape(x)[2] - 1) * tf.shape(x)[3]
+ count_w = tf.shape(x)[2] * (tf.shape(x)[3] - 1)
+ h_tv = tf.reduce_sum(tf.square((x[:, 1:, :, :] - x[:, : h_x - 1, :, :])))
+ w_tv = tf.reduce_sum(tf.square((x[:, :, 1:, :] - x[:, :, : w_x - 1, :])))
+ batch_size = tf.cast(batch_size, dtype=tf.float32)
+ count_h = tf.cast(count_h, dtype=tf.float32)
+ count_w = tf.cast(count_w, dtype=tf.float32)
+ return 2 * (h_tv / count_h + w_tv / count_w) / batch_size
+
+
+"""
+### Spatial consistency loss
+
+The *spatial consistency loss* encourages spatial coherence of the enhanced image by
+preserving the contrast between neighboring regions across the input image and its enhanced version.
+"""
+
+
+class SpatialConsistencyLoss(keras.losses.Loss):
+ def __init__(self, **kwargs):
+ super(SpatialConsistencyLoss, self).__init__(reduction="none")
+
+ self.left_kernel = tf.constant(
+ [[[[0, 0, 0]], [[-1, 1, 0]], [[0, 0, 0]]]], dtype=tf.float32
+ )
+ self.right_kernel = tf.constant(
+ [[[[0, 0, 0]], [[0, 1, -1]], [[0, 0, 0]]]], dtype=tf.float32
+ )
+ self.up_kernel = tf.constant(
+ [[[[0, -1, 0]], [[0, 1, 0]], [[0, 0, 0]]]], dtype=tf.float32
+ )
+ self.down_kernel = tf.constant(
+ [[[[0, 0, 0]], [[0, 1, 0]], [[0, -1, 0]]]], dtype=tf.float32
+ )
+
+ def call(self, y_true, y_pred):
+
+ original_mean = tf.reduce_mean(y_true, 3, keepdims=True)
+ enhanced_mean = tf.reduce_mean(y_pred, 3, keepdims=True)
+ original_pool = tf.nn.avg_pool2d(
+ original_mean, ksize=4, strides=4, padding="VALID"
+ )
+ enhanced_pool = tf.nn.avg_pool2d(
+ enhanced_mean, ksize=4, strides=4, padding="VALID"
+ )
+
+ d_original_left = tf.nn.conv2d(
+ original_pool, self.left_kernel, strides=[1, 1, 1, 1], padding="SAME"
+ )
+ d_original_right = tf.nn.conv2d(
+ original_pool, self.right_kernel, strides=[1, 1, 1, 1], padding="SAME"
+ )
+ d_original_up = tf.nn.conv2d(
+ original_pool, self.up_kernel, strides=[1, 1, 1, 1], padding="SAME"
+ )
+ d_original_down = tf.nn.conv2d(
+ original_pool, self.down_kernel, strides=[1, 1, 1, 1], padding="SAME"
+ )
+
+ d_enhanced_left = tf.nn.conv2d(
+ enhanced_pool, self.left_kernel, strides=[1, 1, 1, 1], padding="SAME"
+ )
+ d_enhanced_right = tf.nn.conv2d(
+ enhanced_pool, self.right_kernel, strides=[1, 1, 1, 1], padding="SAME"
+ )
+ d_enhanced_up = tf.nn.conv2d(
+ enhanced_pool, self.up_kernel, strides=[1, 1, 1, 1], padding="SAME"
+ )
+ d_enhanced_down = tf.nn.conv2d(
+ enhanced_pool, self.down_kernel, strides=[1, 1, 1, 1], padding="SAME"
+ )
+
+ d_left = tf.square(d_original_left - d_enhanced_left)
+ d_right = tf.square(d_original_right - d_enhanced_right)
+ d_up = tf.square(d_original_up - d_enhanced_up)
+ d_down = tf.square(d_original_down - d_enhanced_down)
+ return d_left + d_right + d_up + d_down
+
+
+"""
+### Deep curve estimation model
+
+We implement the Zero-DCE framework as a Keras subclassed model.
+"""
+
+
+class ZeroDCE(keras.Model):
+ def __init__(self, **kwargs):
+ super(ZeroDCE, self).__init__(**kwargs)
+ self.dce_model = build_dce_net()
+
+ def compile(self, learning_rate, **kwargs):
+ super(ZeroDCE, self).compile(**kwargs)
+ self.optimizer = keras.optimizers.Adam(learning_rate=learning_rate)
+ self.spatial_constancy_loss = SpatialConsistencyLoss(reduction="none")
+
+ def get_enhanced_image(self, data, output):
+ r1 = output[:, :, :, :3]
+ r2 = output[:, :, :, 3:6]
+ r3 = output[:, :, :, 6:9]
+ r4 = output[:, :, :, 9:12]
+ r5 = output[:, :, :, 12:15]
+ r6 = output[:, :, :, 15:18]
+ r7 = output[:, :, :, 18:21]
+ r8 = output[:, :, :, 21:24]
+ x = data + r1 * (tf.square(data) - data)
+ x = x + r2 * (tf.square(x) - x)
+ x = x + r3 * (tf.square(x) - x)
+ enhanced_image = x + r4 * (tf.square(x) - x)
+ x = enhanced_image + r5 * (tf.square(enhanced_image) - enhanced_image)
+ x = x + r6 * (tf.square(x) - x)
+ x = x + r7 * (tf.square(x) - x)
+ enhanced_image = x + r8 * (tf.square(x) - x)
+ return enhanced_image
+
+ def call(self, data):
+ dce_net_output = self.dce_model(data)
+ return self.get_enhanced_image(data, dce_net_output)
+
+ def compute_losses(self, data, output):
+ enhanced_image = self.get_enhanced_image(data, output)
+ loss_illumination = 200 * illumination_smoothness_loss(output)
+ loss_spatial_constancy = tf.reduce_mean(
+ self.spatial_constancy_loss(enhanced_image, data)
+ )
+ loss_color_constancy = 5 * tf.reduce_mean(color_constancy_loss(enhanced_image))
+ loss_exposure = 10 * tf.reduce_mean(exposure_loss(enhanced_image))
+ total_loss = (
+ loss_illumination
+ + loss_spatial_constancy
+ + loss_color_constancy
+ + loss_exposure
+ )
+ return {
+ "total_loss": total_loss,
+ "illumination_smoothness_loss": loss_illumination,
+ "spatial_constancy_loss": loss_spatial_constancy,
+ "color_constancy_loss": loss_color_constancy,
+ "exposure_loss": loss_exposure,
+ }
+
+ def train_step(self, data):
+ with tf.GradientTape() as tape:
+ output = self.dce_model(data)
+ losses = self.compute_losses(data, output)
+ gradients = tape.gradient(
+ losses["total_loss"], self.dce_model.trainable_weights
+ )
+ self.optimizer.apply_gradients(zip(gradients, self.dce_model.trainable_weights))
+ return losses
+
+ def test_step(self, data):
+ output = self.dce_model(data)
+ return self.compute_losses(data, output)
+
+ def save_weights(self, filepath, overwrite=True, save_format=None, options=None):
+ """While saving the weights, we simply save the weights of the DCE-Net"""
+ self.dce_model.save_weights(
+ filepath, overwrite=overwrite, save_format=save_format, options=options
+ )
+
+ def load_weights(self, filepath, by_name=False, skip_mismatch=False, options=None):
+ """While loading the weights, we simply load the weights of the DCE-Net"""
+ self.dce_model.load_weights(
+ filepath=filepath,
+ by_name=by_name,
+ skip_mismatch=skip_mismatch,
+ options=options,
+ )
+
+"""
+## Add time history callbacks
+"""
+
+class TimeHistory(tf.keras.callbacks.Callback):
+ def __init__(self, batch_size, log_steps, initial_step=0):
+ self.batch_size = batch_size
+ super(TimeHistory, self).__init__()
+ self.steps_before_epoch = initial_step
+ self.last_log_step = initial_step
+ self.log_steps = log_steps
+ self.steps_in_epoch = 0
+ self.start_time = None
+
+ @property
+ def global_steps(self):
+ """The current 1-indexed global step."""
+ return self.steps_before_epoch + self.steps_in_epoch
+
+ def on_epoch_begin(self, epoch, logs=None):
+ if not self.start_time:
+ self.start_time = time.time()
+ self.epoch_start = time.time()
+
+ def on_batch_begin(self, batch, logs=None):
+ if not self.start_time:
+ self.start_time = time.time()
+
+ def on_batch_end(self, batch, logs=None):
+ self.steps_in_epoch = batch + 1
+ steps_since_last_log = self.global_steps - self.last_log_step
+ if steps_since_last_log >= self.log_steps:
+ now = time.time()
+ elapsed_time = now - self.start_time
+ steps_per_second = steps_since_last_log / elapsed_time
+ examples_per_second = steps_per_second * self.batch_size
+ print(
+ 'TimeHistory: %.2f seconds, %.2f examples/second between steps %d '
+ 'and %d'%(elapsed_time, examples_per_second, self.last_log_step,
+ self.global_steps),flush=True)
+ self.last_log_step = self.global_steps
+ self.start_time = None
+
+ def on_epoch_end(self, epoch, logs=None):
+ epoch_run_time = time.time() - self.epoch_start
+ self.steps_before_epoch += self.steps_in_epoch
+ self.steps_in_epoch = 0
+
+"""
+## Training
+"""
+
+ckpt_path = './ckpt/checkpoint'
+zero_dce_model = ZeroDCE()
+zero_dce_model.compile(learning_rate=args.learning_rate)
+history = zero_dce_model.fit(train_dataset, validation_data=val_dataset, epochs=args.epochs, verbose=2, callbacks=[TimeHistory(args.batch_size,args.log_steps)],)
+zero_dce_model.save_weights(ckpt_path)
+
+
+#def plot_result(item):
+# plt.plot(history.history[item], label=item)
+# plt.plot(history.history["val_" + item], label="val_" + item)
+# plt.xlabel("Epochs")
+# plt.ylabel(item)
+# plt.title("Train and Validation {} Over Epochs".format(item), fontsize=14)
+# plt.legend()
+# plt.grid()
+# plt.show()
+
+
+#plot_result("total_loss")
+#plot_result("illumination_smoothness_loss")
+#plot_result("spatial_constancy_loss")
+#plot_result("color_constancy_loss")
+#plot_result("exposure_loss")
+
+"""
+## Inference
+"""
+
+
+#def plot_results(images, titles, figure_size=(12, 12)):
+# fig = plt.figure(figsize=figure_size)
+# for i in range(len(images)):
+# fig.add_subplot(1, len(images), i + 1).set_title(titles[i])
+# _ = plt.imshow(images[i])
+# plt.axis("off")
+# plt.show()
+
+
+#def infer(original_image):
+# image = keras.preprocessing.image.img_to_array(original_image)
+# image = image.astype("float32") / 255.0
+# image = np.expand_dims(image, axis=0)
+# output_image = zero_dce_model(image)
+# output_image = tf.cast((output_image[0, :, :, :] * 255), dtype=np.uint8)
+# output_image = Image.fromarray(output_image.numpy())
+# return output_image
+
+
+"""
+### Inference on test images
+
+We compare the test images from LOLDataset enhanced by MIRNet with images enhanced via
+the `PIL.ImageOps.autocontrast()` function.
+"""
+
+#for val_image_file in test_low_light_images:
+# original_image = Image.open(val_image_file)
+# enhanced_image = infer(original_image)
+# plot_results(
+# [original_image, ImageOps.autocontrast(original_image), enhanced_image],
+# ["Original", "PIL Autocontrast", "Enhanced"],
+# (20, 12),
+# )