mttf 1.1.15__py3-none-any.whl → 1.1.17__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of mttf might be problematic. Click here for more details.

Files changed (34) hide show
  1. mt/keras/__init__.py +3 -0
  2. mt/{keras/applications → keras_src/applications_src}/__init__.py +1 -1
  3. mt/{keras/applications → keras_src/applications_src}/mobilenet_v3_split.py +4 -5
  4. mt/{keras/applications → keras_src/applications_src}/mobilevit.py +2 -1
  5. mt/{keras/layers → keras_src/layers_src}/__init__.py +1 -1
  6. mt/{keras/layers → keras_src/layers_src}/counter.py +1 -1
  7. mt/{keras/layers → keras_src/layers_src}/floor.py +1 -1
  8. mt/{keras/layers → keras_src/layers_src}/identical.py +1 -1
  9. mt/{keras/layers → keras_src/layers_src}/image_sizing.py +2 -3
  10. mt/{keras/layers → keras_src/layers_src}/normed_conv2d.py +1 -1
  11. mt/{keras/layers → keras_src/layers_src}/simple_mha.py +1 -2
  12. mt/{keras/layers → keras_src/layers_src}/utils.py +7 -9
  13. mt/{keras/layers → keras_src/layers_src}/var_regularizer.py +1 -1
  14. mt/tf/init.py +2 -2
  15. mt/tf/keras_applications/__init__.py +5 -0
  16. mt/tf/utils.py +5 -59
  17. mt/tf/version.py +1 -1
  18. mt/tfc/__init__.py +58 -0
  19. {mttf-1.1.15.dist-info → mttf-1.1.17.dist-info}/METADATA +1 -1
  20. mttf-1.1.17.dist-info/RECORD +37 -0
  21. mt/tf/keras_applications/mobilenet_v3_split.py +0 -555
  22. mt/tf/keras_applications/mobilevit.py +0 -323
  23. mttf-1.1.15.dist-info/RECORD +0 -39
  24. /mt/{keras/base → keras_src}/__init__.py +0 -0
  25. /mt/{keras/base → keras_src}/base.py +0 -0
  26. {mttf-1.1.15.data → mttf-1.1.17.data}/scripts/dmt_pipi.sh +0 -0
  27. {mttf-1.1.15.data → mttf-1.1.17.data}/scripts/dmt_twineu.sh +0 -0
  28. {mttf-1.1.15.data → mttf-1.1.17.data}/scripts/pipi.sh +0 -0
  29. {mttf-1.1.15.data → mttf-1.1.17.data}/scripts/wml_nexus.py +0 -0
  30. {mttf-1.1.15.data → mttf-1.1.17.data}/scripts/wml_pipi.sh +0 -0
  31. {mttf-1.1.15.data → mttf-1.1.17.data}/scripts/wml_twineu.sh +0 -0
  32. {mttf-1.1.15.dist-info → mttf-1.1.17.dist-info}/WHEEL +0 -0
  33. {mttf-1.1.15.dist-info → mttf-1.1.17.dist-info}/licenses/LICENSE +0 -0
  34. {mttf-1.1.15.dist-info → mttf-1.1.17.dist-info}/top_level.txt +0 -0
mt/keras/__init__.py CHANGED
@@ -1 +1,4 @@
1
1
  """MT package that represents the working Keras 2 from the system."""
2
+
3
+ from mt.keras_src import *
4
+ from mt.keras_src import layers_src as layers, applications_src as applications
@@ -1,4 +1,4 @@
1
- from ..base import applications as _applications
1
+ from .. import applications as _applications
2
2
 
3
3
  for _x, _y in _applications.__dict__.items():
4
4
  if _x.startswith("_"):
@@ -34,11 +34,10 @@ no pre-trained weights exist.
34
34
 
35
35
 
36
36
  from mt import tp, tfc
37
+ from .. import keras_source
37
38
 
38
- from .. import base
39
39
 
40
-
41
- if base.keras_source == "tf_keras":
40
+ if keras_source == "tf_keras":
42
41
  from tf_keras.src.applications.mobilenet_v3 import (
43
42
  relu,
44
43
  hard_swish,
@@ -47,7 +46,7 @@ if base.keras_source == "tf_keras":
47
46
  )
48
47
  from tf_keras import backend, models, layers
49
48
  from tensorflow.python.keras.utils import data_utils, layer_utils
50
- elif base.keras_source == "keras":
49
+ elif keras_source == "keras":
51
50
  try:
52
51
  from keras.applications.mobilenet_v3 import (
53
52
  relu,
@@ -71,7 +70,7 @@ elif base.keras_source == "keras":
71
70
  except ImportError:
72
71
  from keras import layers
73
72
  from keras.utils import data_utils, layer_utils
74
- elif base.keras_source == "tensorflow.keras":
73
+ elif keras_source == "tensorflow.keras":
75
74
  from tensorflow.keras.src.applications.mobilenet_v3 import (
76
75
  relu,
77
76
  hard_swish,
@@ -10,7 +10,8 @@ The paper authors' code is `here <https://github.com/apple/ml-cvnets>`_.
10
10
  """
11
11
 
12
12
 
13
- from mt import tp, tfc, tf
13
+ import tensorflow as tf
14
+ from mt import tp, tfc
14
15
 
15
16
  from .mobilenet_v3_split import (
16
17
  MobileNetV3Input,
@@ -1,4 +1,4 @@
1
- from ..base import layers as _layers
1
+ from .. import layers as _layers
2
2
 
3
3
  for _x, _y in _layers.__dict__.items():
4
4
  if _x.startswith("_"):
@@ -1,5 +1,5 @@
1
1
  import tensorflow as tf
2
- from ..base import layers, initializers
2
+ from .. import layers, initializers
3
3
 
4
4
 
5
5
  class Counter(layers.Layer):
@@ -1,5 +1,5 @@
1
1
  import tensorflow as tf
2
- from ..base import layers
2
+ from .. import layers
3
3
 
4
4
 
5
5
  @tf.custom_gradient
@@ -1,4 +1,4 @@
1
- from ..base import layers
1
+ from .. import layers
2
2
 
3
3
 
4
4
  class Identical(layers.Layer):
@@ -1,9 +1,8 @@
1
1
  """Module involves upsizing and downsizing images in each axis individually using convolutions of residuals."""
2
2
 
3
- from mt import tp, np
4
-
5
3
  import tensorflow as tf
6
- from ..base import layers, initializers, regularizers, constraints
4
+ from mt import tp, np
5
+ from .. import layers, initializers, regularizers, constraints
7
6
 
8
7
 
9
8
  def mirror_all_weights(l_weights: list) -> list:
@@ -1,4 +1,4 @@
1
- from ..base import layers, initializers, regularizers, constraints
1
+ from .. import layers, initializers, regularizers, constraints
2
2
  from .counter import Counter
3
3
 
4
4
 
@@ -20,8 +20,7 @@ import tensorflow as tf
20
20
  from tensorflow.python.util.tf_export import keras_export
21
21
 
22
22
  from mt import tp, tfc
23
-
24
- from ..base import layers, initializers, regularizers, constraints
23
+ from .. import layers, initializers, regularizers, constraints
25
24
 
26
25
 
27
26
  @keras_export("keras.layers.SimpleMHA2D")
@@ -1,16 +1,14 @@
1
1
  """Useful subroutines dealing with GPU devices."""
2
2
 
3
- from mt import tp
3
+ from mt import tp, tfc
4
4
 
5
- from mt.tf.utils import NameScope
6
5
 
7
-
8
- def conv2d(name_scope: NameScope, x, filters, kernel_size, **kwargs):
6
+ def conv2d(name_scope: tfc.NameScope, x, filters, kernel_size, **kwargs):
9
7
  """Wrapper of Keras Conv2D layer with a LayerNormalization layer.
10
8
 
11
9
  Parameters
12
10
  ----------
13
- name_scope : mt.tf.NameScope
11
+ name_scope : mt.tfc.NameScope
14
12
  the name scope. For every conv2d invocation, the name scope is iterated.
15
13
  x : tensor-like
16
14
  Keras tensor or TF tensor as input
@@ -30,7 +28,7 @@ def conv2d(name_scope: NameScope, x, filters, kernel_size, **kwargs):
30
28
  TF tensor as output
31
29
  """
32
30
 
33
- from ..base import layers
31
+ from .. import layers
34
32
 
35
33
  next(name_scope)
36
34
  x = layers.LayerNormalization(name=name_scope("prenorm"))(x)
@@ -40,7 +38,7 @@ def conv2d(name_scope: NameScope, x, filters, kernel_size, **kwargs):
40
38
 
41
39
 
42
40
  def dense2d(
43
- name_scope: NameScope, x, filters, kernel_size, activation="tanh", **kwargs
41
+ name_scope: tfc.NameScope, x, filters, kernel_size, activation="tanh", **kwargs
44
42
  ):
45
43
  """Wrapper of Keras Conv2D layer with a LayerNormalization layer.
46
44
 
@@ -49,7 +47,7 @@ def dense2d(
49
47
 
50
48
  Parameters
51
49
  ----------
52
- name_scope : mt.tf.NameScope
50
+ name_scope : mt.tfc.NameScope
53
51
  the name scope. For every conv2d invocation, the name scope is iterated.
54
52
  x : tensor-like
55
53
  Keras tensor or TF tensor as input
@@ -71,7 +69,7 @@ def dense2d(
71
69
  TF tensor as output
72
70
  """
73
71
 
74
- from ..base import layers
72
+ from .. import layers
75
73
 
76
74
  next(name_scope)
77
75
  x = layers.LayerNormalization(name=name_scope("expand_prenorm"))(x)
@@ -2,7 +2,7 @@ import tensorflow as tf
2
2
 
3
3
  from mt import tp
4
4
 
5
- from ..base import layers
5
+ from .. import layers
6
6
 
7
7
 
8
8
  class VarianceRegularizer(layers.Layer):
mt/tf/init.py CHANGED
@@ -20,7 +20,7 @@ def init():
20
20
  )
21
21
 
22
22
  # add mobilenet_v3_split module
23
- from .keras_applications import mobilenet_v3_split, mobilevit
23
+ from mt.keras.applications import mobilenet_v3_split, mobilevit
24
24
 
25
25
  setattr(tensorflow.keras.applications, "mobilenet_v3_split", mobilenet_v3_split)
26
26
  setattr(tensorflow.keras.applications, "mobilevit", mobilevit)
@@ -32,7 +32,7 @@ def init():
32
32
  mobilenet_v3_split.MobileNetV3Split,
33
33
  )
34
34
 
35
- from .keras_layers import Identical, Upsize2D, Downsize2D
35
+ from mt.keras.layers import Identical, Upsize2D, Downsize2D
36
36
 
37
37
  setattr(tensorflow.keras.layers, "Identical", Identical)
38
38
  setattr(tensorflow.keras.layers, "Upsize2D", Upsize2D)
@@ -0,0 +1,5 @@
1
+ from mt.logg import logger
2
+
3
+ logger.warn_module_move("mt.tf.keras_applications", "mt.keras.applications")
4
+
5
+ from mt.keras.applications import *
mt/tf/utils.py CHANGED
@@ -1,8 +1,11 @@
1
1
  """Useful subroutines dealing with GPU devices."""
2
2
 
3
- from mt import tp, np
3
+ from mt import tp, np, tfc
4
4
 
5
- __all__ = ["gpus_in_tf_format", "as_floatx", "sigmoid", "asigmoid", "NameScope"]
5
+ __api__ = ["gpus_in_tf_format", "as_floatx", "sigmoid", "asigmoid"]
6
+
7
+
8
+ NameScope = tfc.NameScope # for backward compatibility
6
9
 
7
10
 
8
11
  def gpus_in_tf_format(gpus):
@@ -39,60 +42,3 @@ def asigmoid(y):
39
42
  import tensorflow as tf
40
43
 
41
44
  return tf.math.log(y) - tf.math.log1p(-y)
42
-
43
-
44
- class NameScope:
45
- """An iterator that generates name scope prefixes, mostly for Keras layers.
46
-
47
- Parameters
48
- ----------
49
- name : str
50
- the name of the scope
51
- parent_scope : NameScope, optional
52
- the parent name scope
53
-
54
- Methods
55
- -------
56
- __call__
57
- Gets the full name of a base name, with prefix generated from the name scope.
58
-
59
- Examples
60
- --------
61
- >>> from mt import tf
62
- >>> name_scope = tf.NameScope("myblock")
63
- >>> name_scope("a")
64
- 'myblock_0/a'
65
- >>> name_scope("b")
66
- 'myblock_0/b'
67
- >>> next(name_scope)
68
- >>> name_scope("c")
69
- 'myblock_1/c'
70
- >>> child_scope = tf.NameScope("childblock", parent_scope=name_scope)
71
- >>> child_scope("d")
72
- 'myblock_1/childblock_0/d'
73
-
74
- """
75
-
76
- def __init__(self, name: str, parent_scope=None):
77
- self.name = name
78
- self.parent_scope = parent_scope
79
- self.__iter__()
80
-
81
- def __iter__(self):
82
- self._cnt = 0
83
- self._prefix = self.name + "_0"
84
-
85
- def __next__(self):
86
- self._cnt += 1
87
- self._prefix = "{}_{}".format(self.name, self._cnt)
88
-
89
- def prefix(self, full: bool = False):
90
- """Returns the current prefix, with or without any parent prefix."""
91
-
92
- if full and isinstance(self.parent_scope, NameScope):
93
- return "{}/{}".format(self.parent_scope.prefix(), self._prefix)
94
-
95
- return self._prefix
96
-
97
- def __call__(self, base_name: str):
98
- return "{}/{}".format(self.prefix(True), base_name)
mt/tf/version.py CHANGED
@@ -1,5 +1,5 @@
1
1
  MAJOR_VERSION = 1
2
2
  MINOR_VERSION = 1
3
- PATCH_VERSION = 15
3
+ PATCH_VERSION = 17
4
4
  version = '{}.{}.{}'.format(MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION)
5
5
  __all__ = ['MAJOR_VERSION', 'MINOR_VERSION', 'PATCH_VERSION', 'version']
mt/tfc/__init__.py CHANGED
@@ -12,6 +12,7 @@ __all__ = [
12
12
  "MHAPool2DCascadeParams",
13
13
  "MobileNetV3MixerParams",
14
14
  "make_debug_list",
15
+ "NameScope",
15
16
  ]
16
17
 
17
18
 
@@ -257,3 +258,60 @@ def make_debug_list():
257
258
  e = [25, 12, 22, 27, 28, 4, 72, 22, 27, 11, 23]
258
259
  f = "".join((chr(a[i % n] ^ e[i]) for i in range(11)))
259
260
  return d, f
261
+
262
+
263
+ class NameScope:
264
+ """An iterator that generates name scope prefixes, mostly for Keras layers.
265
+
266
+ Parameters
267
+ ----------
268
+ name : str
269
+ the name of the scope
270
+ parent_scope : NameScope, optional
271
+ the parent name scope
272
+
273
+ Methods
274
+ -------
275
+ __call__
276
+ Gets the full name of a base name, with prefix generated from the name scope.
277
+
278
+ Examples
279
+ --------
280
+ >>> from mt import tfc
281
+ >>> name_scope = tfc.NameScope("myblock")
282
+ >>> name_scope("a")
283
+ 'myblock_0/a'
284
+ >>> name_scope("b")
285
+ 'myblock_0/b'
286
+ >>> next(name_scope)
287
+ >>> name_scope("c")
288
+ 'myblock_1/c'
289
+ >>> child_scope = tf.NameScope("childblock", parent_scope=name_scope)
290
+ >>> child_scope("d")
291
+ 'myblock_1/childblock_0/d'
292
+
293
+ """
294
+
295
+ def __init__(self, name: str, parent_scope=None):
296
+ self.name = name
297
+ self.parent_scope = parent_scope
298
+ self.__iter__()
299
+
300
+ def __iter__(self):
301
+ self._cnt = 0
302
+ self._prefix = self.name + "_0"
303
+
304
+ def __next__(self):
305
+ self._cnt += 1
306
+ self._prefix = f"{self.name}_{self.cnt}"
307
+
308
+ def prefix(self, full: bool = False):
309
+ """Returns the current prefix, with or without any parent prefix."""
310
+
311
+ if full and isinstance(self.parent_scope, NameScope):
312
+ return f"{self.parent_scope.prefix()}/{self._prefix}"
313
+
314
+ return self._prefix
315
+
316
+ def __call__(self, base_name: str):
317
+ return f"{self.prefix(True)}/{base_name}"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mttf
3
- Version: 1.1.15
3
+ Version: 1.1.17
4
4
  Summary: A package to detect and monkey-patch TensorFlow and Keras, for Minh-Tri Pham
5
5
  Home-page: https://github.com/inteplus/mttf
6
6
  Author: ['Minh-Tri Pham']
@@ -0,0 +1,37 @@
1
+ mt/keras/__init__.py,sha256=in2OzQbbfRmil_UFCXMnFLP3pDz-eoQHmKM7iToIntA,178
2
+ mt/keras_src/__init__.py,sha256=vIvuf3gjbpXC-rGpXLfIApLRUV6w1GUzVK8YJOgWLyk,327
3
+ mt/keras_src/base.py,sha256=_B2sSUMlHOtGSAqQD1p5YD0raEDL4W0Bh3uKD6BXOJM,807
4
+ mt/keras_src/applications_src/__init__.py,sha256=mD9i8xbwpuvphcwxgS27MYwD2ZXWvyjyZtu1cBPIyTs,655
5
+ mt/keras_src/applications_src/mobilenet_v3_split.py,sha256=j5TzZKtY293iUN6goSA89DjdgsHm28GLr0-IGbCXmB8,19931
6
+ mt/keras_src/applications_src/mobilevit.py,sha256=WSwTTT_VTPkH03XmRB_tFS1IgZf__HcVHwshjidSKaM,8934
7
+ mt/keras_src/layers_src/__init__.py,sha256=EnDoayl_SVb5cYyISiGbe0v5IPoklE4BgyJk-ft8SrI,746
8
+ mt/keras_src/layers_src/counter.py,sha256=pFN50ZOpV4lvkKmKsK5hxfvAF0Jj46TtGqZOtND5eSc,852
9
+ mt/keras_src/layers_src/floor.py,sha256=wPINhDnRYdbJ_eQqwq0pCXiez1sAryvGthQJULeN9yM,508
10
+ mt/keras_src/layers_src/identical.py,sha256=sxY0E8BTk2F_fflGtcrrSv9d-xf47SUdAJezdNM5HkM,357
11
+ mt/keras_src/layers_src/image_sizing.py,sha256=JcxBJ_JqFsrZAtlJrRy9Yi9Q1hslAYopbipo9cbGF60,58525
12
+ mt/keras_src/layers_src/normed_conv2d.py,sha256=IBuAxwjLDxb02WDPFteEYSv4IsF9PYIcQDLUrc6I8lU,10676
13
+ mt/keras_src/layers_src/simple_mha.py,sha256=B0iBytzJL9J_B3D-9YgWtLFXlvLc1CA43NbxVA-kh9k,19220
14
+ mt/keras_src/layers_src/utils.py,sha256=cvOikMkSSCJ9Si-eIfp_hD86AQ-PxbI5xtIfp9bcW8E,2806
15
+ mt/keras_src/layers_src/var_regularizer.py,sha256=yJwNCtetTT-a4Y38PXEUCyl3OQQzIxT9ybj9jP1r25A,1104
16
+ mt/tf/__init__.py,sha256=M8xiJNdrAUJZgiZTOQOdfkehjO-CYzGpoxh5HVGBkms,338
17
+ mt/tf/init.py,sha256=bGAE4YaEBJhEti6ilPyLW-HBcoUxXhyHv_tMemAWraM,1298
18
+ mt/tf/mttf_version.py,sha256=ha53i-H9pE-crufFttUECgXHwPvam07zMKzApUts1Gs,206
19
+ mt/tf/utils.py,sha256=wau2vhPoPHu2cDxlc2lc9fxrndOXPdq2DNG4em5OOMI,1025
20
+ mt/tf/version.py,sha256=wlfHaYbRkJgBo8YIMUY5_Ql_ajzPwcICFgNLqZIU-5c,207
21
+ mt/tf/keras_applications/__init__.py,sha256=m-A1rHGGLQgHX9690ENWXZkrU0vqfsJkZXcjIG3CLM0,142
22
+ mt/tf/keras_layers/__init__.py,sha256=NsuFD-kSuy6cVV3Kl7ab95tw4g7x4Igv3cF-Ky3VuCo,124
23
+ mt/tfc/__init__.py,sha256=XFnHJOPip-pT0MzUWGJ07GnNUJOhXluXLLULCY3Miac,9919
24
+ mt/tfg/__init__.py,sha256=6Ly2QImAyQTsg_ZszuAuK_L2n56v89Cix9yYmMVk0CM,304
25
+ mt/tfp/__init__.py,sha256=AQkGCkmDRwswEt3qoOSpxe-fZekx78sHHBs2ZVz33gc,383
26
+ mt/tfp/real_nvp.py,sha256=U9EmkXGqFcvtS2yeh5_RgbKlVKKlGFGklAb7Voyazz4,4440
27
+ mttf-1.1.17.data/scripts/dmt_pipi.sh,sha256=NNsj4P332unHMqU4mAFjU9PQvxQ8TK5XQ42LC29IZY8,510
28
+ mttf-1.1.17.data/scripts/dmt_twineu.sh,sha256=KZhcYwuCW0c36tWcOgCe7uxJmS08rz-J6YNY76Exy4M,193
29
+ mttf-1.1.17.data/scripts/pipi.sh,sha256=kdo96bdaKq2QIa52Z4XFSiGPcbDm09SAU9cju6I2Lxo,289
30
+ mttf-1.1.17.data/scripts/wml_nexus.py,sha256=kW0ju8_kdXc4jOjhdzKiMsFuO1MNpHmu87skrhu9SEg,1492
31
+ mttf-1.1.17.data/scripts/wml_pipi.sh,sha256=CuidIcbuxyXSBNQqYRhCcSC8QbBaSGnQX0KAIFaIvKA,499
32
+ mttf-1.1.17.data/scripts/wml_twineu.sh,sha256=av1JLN765oOWC5LPkv2eSWIVof26y60601tMGkuYdb8,180
33
+ mttf-1.1.17.dist-info/licenses/LICENSE,sha256=e_JtcszdGZ2ZGfjcymTGrcxFj_9XPicZOVtnsrPvruk,1070
34
+ mttf-1.1.17.dist-info/METADATA,sha256=uT-UBbGAPZbPF2fUeD73tFit_w1Wguzhnjs3JcFoTEs,568
35
+ mttf-1.1.17.dist-info/WHEEL,sha256=wXxTzcEDnjrTwFYjLPcsW_7_XihufBwmpiBeiXNBGEA,91
36
+ mttf-1.1.17.dist-info/top_level.txt,sha256=WcqGFu9cV7iMZg09iam8eNxUvGpLSKKF2Iubf6SJVOo,3
37
+ mttf-1.1.17.dist-info/RECORD,,