Skip to content

Commit 07bde63

Browse files
WeichenXu123jkbradley
authored andcommitted
Deprecation of Spark ML APIs in sparkdl (#213)
Deprecation on graph/udf submodule of sparkdl, plus the various Spark ML Transformers and Estimators.
1 parent 73b8233 commit 07bde63

File tree

15 files changed

+59
-0
lines changed

15 files changed

+59
-0
lines changed

dev/dev-requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ argcomplete==1.9.4
33
pylint==1.8.4
44
prospector==0.12.7
55
yapf==0.21.0
6+
Deprecated==1.2.7

environment.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@ dependencies:
3232
- yapf==0.21.0
3333
# docs
3434
- sphinx
35+
- Deprecated==1.2.7

python/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ PyNaCl==1.2.1 # Note: This is a transitive dependency of paramiko v 1.3.0 fails
1414
cloudpickle>=0.5.2
1515
horovod>=0.16.0
1616
wrapt==1.10.11
17+
Deprecated==1.2.7

python/sparkdl/estimators/keras_image_file_estimator.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from __future__ import absolute_import, division, print_function
1919

2020
import threading
21+
from deprecated import deprecated
2122
import numpy as np
2223

2324
from pyspark.ml import Estimator
@@ -70,6 +71,9 @@ def __next__(self):
7071
return self.models[index]
7172

7273

74+
@deprecated(reason="KerasImageFileEstimator will be removed in the next release of sparkdl. "
75+
"To replace a KerasImageFileEstimator workflow, please use "
76+
"Distributed Hyperopt with SparkTrials to distribute model tuning.")
7377
class KerasImageFileEstimator(Estimator, HasInputCol, HasOutputCol, HasLabelCol, HasKerasModel,
7478
HasKerasOptimizer, HasKerasLoss, CanLoadImage, HasOutputMode):
7579
"""

python/sparkdl/graph/input.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#
1515
from __future__ import absolute_import, division, print_function
1616

17+
from deprecated import deprecated
1718
import tensorflow as tf
1819
from tensorflow.core.protobuf import meta_graph_pb2 # pylint: disable=no-name-in-module
1920

@@ -24,6 +25,8 @@
2425
# pylint: disable=invalid-name,wrong-spelling-in-comment,wrong-spelling-in-docstring
2526

2627

28+
@deprecated(reason="TFInputGraph will be removed in next release of sparkdl. "
29+
"Please use Pandas UDF for distributed model inference.")
2730
class TFInputGraph(object):
2831
"""
2932
An opaque object containing TensorFlow graph.

python/sparkdl/graph/utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import logging
1818

1919
import six
20+
from deprecated import deprecated
2021
import tensorflow as tf
2122

2223
logger = logging.getLogger('sparkdl')
@@ -33,6 +34,7 @@
3334

3435
__all__ = ['strip_and_freeze_until']
3536

37+
3638
def validated_graph(graph):
3739
"""
3840
Check if the input is a valid :py:class:`tf.Graph` and return it.
@@ -196,6 +198,8 @@ def validated_input(tfobj_or_name, graph):
196198
return name
197199

198200

201+
@deprecated(reason="strip_and_freeze_until() will be removed in next release of sparkdl. "
202+
"Please use Pandas UDF for distributed model inference.")
199203
def strip_and_freeze_until(fetches, graph, sess=None, return_graph=False):
200204
"""
201205
Create a static view of the graph by

python/sparkdl/image/imageIO.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
from io import BytesIO
1717
from collections import namedtuple
18+
import warnings
1819

1920
# 3rd party
2021
import numpy as np
@@ -173,6 +174,8 @@ def createResizeImageUDF(size):
173174
:param size: tuple, target size of new image in the form (height, width).
174175
:return: udf, a udf for resizing an image column to `size`.
175176
"""
177+
warnings.warn("createResizeImageUDF() will be removed in the next release of sparkdl. "
178+
"Please use Pandas UDF instead.", DeprecationWarning)
176179
if len(size) != 2:
177180
raise ValueError(
178181
"New image size should have format [height, width] but got {}".format(size))
@@ -212,6 +215,8 @@ def PIL_decode(raw_bytes):
212215
:param raw_bytes:
213216
:return: image data as an array in CV_8UC3 format
214217
"""
218+
warnings.warn("PIL_decode() will be removed in the next release of sparkdl. "
219+
"Please use pillow and Pandas UDF instead.", DeprecationWarning)
215220
return PIL_to_imageStruct(Image.open(BytesIO(raw_bytes)))
216221

217222

@@ -237,6 +242,8 @@ def readImagesWithCustomFn(path, decode_f, numPartition=None):
237242
:param numPartition: [optional] int, number or partitions to use for reading files.
238243
:return: DataFrame with schema == ImageSchema.imageSchema.
239244
"""
245+
warnings.warn("readImagesWithCustomFn() will be removed in the next release of sparkdl. "
246+
"Please use pillow and Pandas UDF instead.", DeprecationWarning)
240247
return _readImagesWithCustomFn(path, decode_f, numPartition, sc=SparkContext.getOrCreate())
241248

242249

python/sparkdl/transformers/keras_image.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414
#
1515

16+
from deprecated import deprecated
1617
from pyspark.ml import Transformer
1718
from sparkdl.param import CanLoadImage, HasInputCol, HasKerasModel, HasOutputCol, HasOutputMode, \
1819
keyword_only
@@ -22,6 +23,8 @@
2223
# pylint: disable=duplicate-code
2324

2425

26+
@deprecated(reason="KerasImageFileTransformer will be removed in the next release of sparkdl. "
27+
"Please use binary file data source and Pandas UDF instead.")
2528
class KerasImageFileTransformer(Transformer, HasInputCol, HasOutputCol,
2629
CanLoadImage, HasKerasModel, HasOutputMode):
2730
"""

python/sparkdl/transformers/keras_tensor.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414
#
15+
16+
from deprecated import deprecated
1517
from pyspark.ml import Transformer
1618
from sparkdl.graph.input import TFInputGraph
1719
from sparkdl.param import HasInputCol, HasKerasModel, HasOutputCol, keyword_only
@@ -21,6 +23,8 @@
2123
# pylint: disable=duplicate-code
2224

2325

26+
@deprecated(reason="KerasTransformer will be removed in the next release of sparkdl. "
27+
"Please use Pandas UDF instead.")
2428
class KerasTransformer(Transformer, HasInputCol, HasOutputCol, HasKerasModel):
2529
"""
2630
Applies a Tensorflow-backed Keras model (specified by a file name) to

python/sparkdl/transformers/named_image.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414
#
1515

16+
from deprecated import deprecated
1617
from keras.applications.imagenet_utils import decode_predictions
1718
import numpy as np
1819
import py4j
@@ -36,6 +37,8 @@
3637
SUPPORTED_MODELS = ["InceptionV3", "Xception", "ResNet50", "VGG16", "VGG19"]
3738

3839

40+
@deprecated(reason="DeepImagePredictor will be removed in the next release of sparkdl. "
41+
"Please use Pandas UDF instead.")
3942
class DeepImagePredictor(Transformer, HasInputCol, HasOutputCol):
4043
"""
4144
Applies the model specified by its popular name to the image column in DataFrame.
@@ -150,6 +153,8 @@ def __call__(self, value):
150153
return self._sizeHintConverter(value)
151154

152155

156+
@deprecated(reason="DeepImageFeaturizer will be removed in the next release of sparkdl. "
157+
"Please use Pandas UDF instead.")
153158
class DeepImageFeaturizer(JavaTransformer):
154159
"""
155160
Applies the model specified by its popular name, with its prediction layer(s) chopped off,

0 commit comments

Comments
 (0)