টেনসরফ্লো এক্সটেন্ডেড (টিএফএক্স) এর একটি অংশ-দ্বারা-অংশীকরণের ভূমিকা
কোলাব-ভিত্তিক এই টিউটোরিয়ালটি আন্তস্ক্রিয়ভাবে টেনসরফ্লো এক্সটেন্ডেড (টিএফএক্স) এর প্রতিটি অন্তর্নির্মিত উপাদানটির মধ্য দিয়ে চলবে।
এটি ডেটা অন্তর্ভুক্তি থেকে শুরু করে পরিবেশনার দিকে কোনও মডেলকে ধাক্কা দেওয়া থেকে শুরু করে শেষের শেষ পর্যন্ত মেশিন লার্নিং পাইপলাইনের প্রতিটি পদক্ষেপকে কভার করে।
আপনার হয়ে গেলে, এই নোটবুকের সামগ্রীগুলি স্বয়ংক্রিয়ভাবে টিএফএক্স পাইপলাইন উত্স কোড হিসাবে রফতানি করা যায়, যা আপনি অ্যাপাচি এয়ারফ্লো এবং অ্যাপাচি বিমের সাহায্যে অর্কেস্টেট করতে পারেন।
পটভূমি
এই নোটবুকটি দেখায় যে কীভাবে একটি বৃহত্তর / কুলাব পরিবেশে টিএফএক্স ব্যবহার করতে হয়। এখানে, আমরা একটি ইন্টারেক্টিভ নোটবুকে শিকাগো ট্যাক্সি উদাহরণ দিয়ে চলি।
একটি ইন্টারেক্টিভ নোটবুকে কাজ করা একটি টিএফএক্স পাইপলাইনের কাঠামোর সাথে পরিচিত হওয়ার একটি কার্যকর উপায়। আপনার নিজস্ব পাইপলাইনগুলিকে হালকা ওজনের বিকাশের পরিবেশ হিসাবে বিকাশ করার সময়ও এটি দরকারী, তবে আপনার সচেতন হওয়া উচিত যে ইন্টারেক্টিভ নোটবুকগুলি অর্কিস্ট্রেটেড করার পদ্ধতি এবং কীভাবে তারা মেটাডাটা শিল্পকর্মগুলিতে অ্যাক্সেস করে তার মধ্যে পার্থক্য রয়েছে।
অর্কেস্ট্রেশন
টিএফএক্সের উত্পাদন স্থাপনায়, আপনি টিএফএক্স উপাদানগুলির প্রাক-সংজ্ঞায়িত পাইপলাইন গ্রাফকে অর্কেস্ট্রেট করার জন্য আপাচে এয়ারফ্লো, কুবেফ্লো পাইপলাইনস বা অ্যাপাচি বিমের মতো অর্কেস্ট্রেটার ব্যবহার করবেন। একটি ইন্টারেক্টিভ নোটবুকে, নোটবুকটি নিজেই অর্কেস্ট্রেটর হয়, আপনি নোটবুকের কোষগুলি কার্যকর করার সাথে সাথে প্রতিটি টিএফএক্স উপাদান চালাচ্ছেন।
মেটাডেটা
টিএফএক্সের উত্পাদন স্থাপনায়, আপনি এমএল মেটাডেটা (এমএলএমডি) এপিআইয়ের মাধ্যমে মেটাডেটা অ্যাক্সেস করতে পারবেন। এমএলএমডি মাইএসকিউএল বা এসকিউএলাইটের মতো একটি ডেটাবেজে মেটাডেটা বৈশিষ্ট্যগুলি সঞ্চয় করে এবং আপনার ফাইল সিস্টেমের মতো ধ্রুবক স্টোরে মেটাডেটা পেওল্ডগুলি সঞ্চয় করে। একটি ইন্টারেক্টিভ নোটবুকে, সম্পত্তি এবং পেড উভয়ই বৃহত্তর নোটবুক বা কোলাব সার্ভারে /tmp
টিএমপি ডিরেক্টরিতে একটি ইফেমেরাল এসকিউএলাইট ডাটাবেসে সংরক্ষণ করা হয়।
সেটআপ
প্রথমত, আমরা প্রয়োজনীয় প্যাকেজগুলি ইনস্টল এবং আমদানি করি, পাথ সেট আপ করি এবং ডেটা ডাউনলোড করি।
পাইপ আপগ্রেড করুন
স্থানীয়ভাবে চলাকালীন কোনও সিস্টেমে পিপ আপগ্রেড করা এড়াতে, নিশ্চিত হয়ে নিন যে আমরা কলাবে ছুটছি। স্থানীয় সিস্টেমগুলি অবশ্যই আলাদাভাবে আপগ্রেড করা যায়।
try:
import colab
!pip install --upgrade pip
except:
pass
টিএফএক্স ইনস্টল করুন
# TODO(ccy): Fix need to use deprecated pip resolver.
pip install -q -U --use-deprecated=legacy-resolver tfx
আপনি কি রানটাইম পুনরায় চালু করেছেন?
আপনি যদি গুগল কলাব ব্যবহার করেন, আপনি যখন প্রথমবারের উপরের সেলটি চালাচ্ছেন, আপনাকে অবশ্যই রানটাইম পুনরায় চালু করতে হবে (রানটাইম> রানটাইম পুনরায় চালু করুন ...)। এটি কলব প্যাকেজ লোড করার কারণে।
প্যাকেজ আমদানি করুন
আমরা স্ট্যান্ডার্ড টিএফএক্স উপাদান উপাদান সহ প্রয়োজনীয় প্যাকেজগুলি আমদানি করি।
import os
import pprint
import tempfile
import urllib
import absl
import tensorflow as tf
import tensorflow_model_analysis as tfma
tf.get_logger().propagate = False
pp = pprint.PrettyPrinter()
import tfx
from tfx.components import CsvExampleGen
from tfx.components import Evaluator
from tfx.components import ExampleValidator
from tfx.components import Pusher
from tfx.components import ResolverNode
from tfx.components import SchemaGen
from tfx.components import StatisticsGen
from tfx.components import Trainer
from tfx.components import Transform
from tfx.components.base import executor_spec
from tfx.components.trainer.executor import GenericExecutor
from tfx.dsl.experimental import latest_blessed_model_resolver
from tfx.orchestration import metadata
from tfx.orchestration import pipeline
from tfx.orchestration.experimental.interactive.interactive_context import InteractiveContext
from tfx.proto import pusher_pb2
from tfx.proto import trainer_pb2
from tfx.types import Channel
from tfx.types.standard_artifacts import Model
from tfx.types.standard_artifacts import ModelBlessing
from tfx.utils.dsl_utils import external_input
%load_ext tfx.orchestration.experimental.interactive.notebook_extensions.skip
WARNING:absl:RuntimeParameter is only supported on Cloud-based DAG runner currently.
আসুন গ্রন্থাগারের সংস্করণগুলি পরীক্ষা করে দেখুন।
print('TensorFlow version: {}'.format(tf.__version__))
# TODO(ccy): Revert to `tfx.__version__` after 0.27.0 release.
import tfx.version
print('TFX version: {}'.format(tfx.__version__))
TensorFlow version: 2.3.2 TFX version: 0.26.1
পাইপলাইন পাথ সেট আপ করুন
import tfx.examples.chicago_taxi_pipeline
# This is the directory containing the TFX Chicago Taxi Pipeline example.
_taxi_root = tfx.examples.chicago_taxi_pipeline.__path__[0]
# This is the path where your model will be pushed for serving.
_serving_model_dir = os.path.join(
tempfile.mkdtemp(), 'serving_model/taxi_simple')
# Set up logging.
absl.logging.set_verbosity(absl.logging.INFO)
উদাহরণস্বরূপ ডেটা ডাউনলোড করুন
আমরা আমাদের টিএফএক্স পাইপলাইনে ব্যবহারের জন্য ডেটাসেটটি ডাউনলোড করি।
আমরা যে ডেটাসেটটি ব্যবহার করছি তা হ'ল শিকাগো সিটি দ্বারা প্রকাশিত ট্যাক্সি ট্রিপস ডেটাসেট । এই ডেটাসেটের কলামগুলি হ'ল:
পিকআপ_কমিনিটি_আরিয়া | ভাড়া | ট্রিপ_স্টার্ট_ম্যাথ |
ট্রিপ_স্টার্ট_আর | ট্রিপ_স্টার্ট_দিন | ট্রিপ_স্টার্ট_টাইমস্ট্যাম্প |
পিকআপ_লিটটিউড | বাছাই_ দীর্ঘতা | ড্রপ অফ_লিটটিউড |
ড্রপ অফ | ট্রিপ_মিলস | পিকআপ_সেনসাস_ট্র্যাক্ট |
ড্রপ অফ_সেনসাস_ট্র্যাক্ট | শোধের ধরণ | প্রতিষ্ঠান |
ট্রিপ_সেকেন্ডস | ড্রপ অফ কম্যুনিটি_আড়িয়া | পরামর্শ |
এই ডেটাসেটের সাহায্যে আমরা এমন একটি মডেল তৈরি করব যা ভ্রমণের tips
পূর্বাভাস দেয়।
_data_root = tempfile.mkdtemp(prefix='tfx-data')
DATA_PATH = 'https://raw.githubusercontent.com/tensorflow/tfx/master/tfx/examples/chicago_taxi_pipeline/data/simple/data.csv'
_data_filepath = os.path.join(_data_root, "data.csv")
urllib.request.urlretrieve(DATA_PATH, _data_filepath)
('/tmp/tfx-datajpj58jo7/data.csv', <http.client.HTTPMessage at 0x7f5ae8d23cf8>)
সিএসভি ফাইলটি একবার দেখুন।
head {_data_filepath}
pickup_community_area,fare,trip_start_month,trip_start_hour,trip_start_day,trip_start_timestamp,pickup_latitude,pickup_longitude,dropoff_latitude,dropoff_longitude,trip_miles,pickup_census_tract,dropoff_census_tract,payment_type,company,trip_seconds,dropoff_community_area,tips ,12.45,5,19,6,1400269500,,,,,0.0,,,Credit Card,Chicago Elite Cab Corp. (Chicago Carriag,0,,0.0 ,0,3,19,5,1362683700,,,,,0,,,Unknown,Chicago Elite Cab Corp.,300,,0 60,27.05,10,2,3,1380593700,41.836150155,-87.648787952,,,12.6,,,Cash,Taxi Affiliation Services,1380,,0.0 10,5.85,10,1,2,1382319000,41.985015101,-87.804532006,,,0.0,,,Cash,Taxi Affiliation Services,180,,0.0 14,16.65,5,7,5,1369897200,41.968069,-87.721559063,,,0.0,,,Cash,Dispatch Taxi Affiliation,1080,,0.0 13,16.45,11,12,3,1446554700,41.983636307,-87.723583185,,,6.9,,,Cash,,780,,0.0 16,32.05,12,1,1,1417916700,41.953582125,-87.72345239,,,15.4,,,Cash,,1200,,0.0 30,38.45,10,10,5,1444301100,41.839086906,-87.714003807,,,14.6,,,Cash,,2580,,0.0 11,14.65,1,1,3,1358213400,41.978829526,-87.771166703,,,5.81,,,Cash,,1080,,0.0
দাবি অস্বীকার: এই সাইটটি ডেটা ব্যবহার করে অ্যাপ্লিকেশন সরবরাহ করে যা এর মূল উত্স, www.cityofchicago.org, শিকাগো শহরের অফিসিয়াল ওয়েবসাইট থেকে ব্যবহারের জন্য পরিবর্তন করা হয়েছে। শিকাগো শহরটি এই সাইটে সরবরাহ করা কোনও ডেটা বিষয়বস্তু, নির্ভুলতা, সময়োপযোগীতা বা সম্পূর্ণতার বিষয়ে কোনও দাবি করে না। এই সাইটে সরবরাহ করা ডেটা যে কোনও সময় পরিবর্তন সাপেক্ষে। বোঝা যাচ্ছে যে এই সাইটে সরবরাহ করা ডেটা নিজের ঝুঁকিতে ব্যবহার করা হচ্ছে।
ইন্টারেক্টিভ কনটেক্সট তৈরি করুন
সর্বশেষে, আমরা একটি ইন্টারেক্টিভ কনটেক্সট তৈরি করি, যা আমাদের এই নোটবুকটিতে ইন্টারেক্টিভভাবে টিএফএক্স উপাদান চালানোর অনুমতি দেবে।
# Here, we create an InteractiveContext using default parameters. This will
# use a temporary directory with an ephemeral ML Metadata database instance.
# To use your own pipeline root or database, the optional properties
# `pipeline_root` and `metadata_connection_config` may be passed to
# InteractiveContext. Calls to InteractiveContext are no-ops outside of the
# notebook.
context = InteractiveContext()
WARNING:absl:InteractiveContext pipeline_root argument not provided: using temporary directory /tmp/tfx-interactive-2021-02-01T10_16_29.340076-cd248luc as root for pipeline outputs. WARNING:absl:InteractiveContext metadata_connection_config not provided: using SQLite ML Metadata database at /tmp/tfx-interactive-2021-02-01T10_16_29.340076-cd248luc/metadata.sqlite.
টিএফএক্স উপাদানগুলি ইন্টারেক্টিভভাবে চালান
অনুসরণকারী কক্ষগুলিতে আমরা টিএফএক্স উপাদানগুলি একে একে তৈরি করি, সেগুলির প্রতিটি চালাই এবং তাদের আউটপুট শিল্পকর্মগুলিকে কল্পনা করি।
উদাহরণস্বরূপ
ExampleGen
উপাদানটি সাধারণত একটি টিএফএক্স পাইপলাইনের শুরুতে থাকে। এটি হবে:
- প্রশিক্ষণ এবং মূল্যায়ন সেটে ডেটা বিভক্ত করুন (ডিফল্টরূপে, 2/3 প্রশিক্ষণ + 1/3 ইভাল)
-
tf.Example
বিন্যাসে রূপান্তর করুন - অন্যান্য উপাদান অ্যাক্সেসের জন্য
_tfx_root
ডিরেক্টরিতে ডেটা অনুলিপি করুন
ExampleGen
আপনার ডেটা উত্সের পথে ইনপুট হিসাবে নেয়। আমাদের ক্ষেত্রে, এটি _data_root
পাথ যা ডাউনলোড করা সিএসভি রয়েছে।
example_gen = CsvExampleGen(input=external_input(_data_root))
context.run(example_gen)
WARNING:absl:From <ipython-input-1-2e0190c2dd16>:1: external_input (from tfx.utils.dsl_utils) is deprecated and will be removed in a future version. Instructions for updating: external_input is deprecated, directly pass the uri to ExampleGen. WARNING:absl:The "input" argument to the CsvExampleGen component has been deprecated by "input_base". Please update your usage as support for this argument will be removed soon. INFO:absl:Running driver for CsvExampleGen INFO:absl:MetadataStore with DB connection initialized INFO:absl:select span and version = (0, None) INFO:absl:latest span and version = (0, None) INFO:absl:Running executor for CsvExampleGen INFO:absl:Generating examples. WARNING:apache_beam.runners.interactive.interactive_environment:Dependencies required for Interactive Beam PCollection visualization are not available, please use: `pip install apache-beam[interactive]` to install necessary dependencies to enable all data visualization features. INFO:absl:Processing input csv data /tmp/tfx-datajpj58jo7/* to TFExample. WARNING:apache_beam.io.tfrecordio:Couldn't find python-snappy so the implementation of _TFRecordUtil._masked_crc32c is not as fast as it could be. INFO:absl:Examples generated. INFO:absl:Running publisher for CsvExampleGen INFO:absl:MetadataStore with DB connection initialized
আসুন ExampleGen
আউটপুট শিল্পকর্মগুলি পরীক্ষা করি। এই উপাদানটি দুটি শিল্পকলা উত্পাদন করে, প্রশিক্ষণের উদাহরণ এবং মূল্যায়ন উদাহরণ:
artifact = example_gen.outputs['examples'].get()[0]
print(artifact.split_names, artifact.uri)
["train", "eval"] /tmp/tfx-interactive-2021-02-01T10_16_29.340076-cd248luc/CsvExampleGen/examples/1
আমরা প্রথম তিনটি প্রশিক্ষণের উদাহরণগুলিও দেখতে পারি:
# Get the URI of the output artifact representing the training examples, which is a directory
train_uri = os.path.join(example_gen.outputs['examples'].get()[0].uri, 'train')
# Get the list of files in this directory (all compressed TFRecord files)
tfrecord_filenames = [os.path.join(train_uri, name)
for name in os.listdir(train_uri)]
# Create a `TFRecordDataset` to read these files
dataset = tf.data.TFRecordDataset(tfrecord_filenames, compression_type="GZIP")
# Iterate over the first 3 records and decode them.
for tfrecord in dataset.take(3):
serialized_example = tfrecord.numpy()
example = tf.train.Example()
example.ParseFromString(serialized_example)
pp.pprint(example)
features { feature { key: "company" value { bytes_list { value: "Chicago Elite Cab Corp. (Chicago Carriag" } } } feature { key: "dropoff_census_tract" value { int64_list { } } } feature { key: "dropoff_community_area" value { int64_list { } } } feature { key: "dropoff_latitude" value { float_list { } } } feature { key: "dropoff_longitude" value { float_list { } } } feature { key: "fare" value { float_list { value: 12.449999809265137 } } } feature { key: "payment_type" value { bytes_list { value: "Credit Card" } } } feature { key: "pickup_census_tract" value { int64_list { } } } feature { key: "pickup_community_area" value { int64_list { } } } feature { key: "pickup_latitude" value { float_list { } } } feature { key: "pickup_longitude" value { float_list { } } } feature { key: "tips" value { float_list { value: 0.0 } } } feature { key: "trip_miles" value { float_list { value: 0.0 } } } feature { key: "trip_seconds" value { int64_list { value: 0 } } } feature { key: "trip_start_day" value { int64_list { value: 6 } } } feature { key: "trip_start_hour" value { int64_list { value: 19 } } } feature { key: "trip_start_month" value { int64_list { value: 5 } } } feature { key: "trip_start_timestamp" value { int64_list { value: 1400269500 } } } } features { feature { key: "company" value { bytes_list { value: "Taxi Affiliation Services" } } } feature { key: "dropoff_census_tract" value { int64_list { } } } feature { key: "dropoff_community_area" value { int64_list { } } } feature { key: "dropoff_latitude" value { float_list { } } } feature { key: "dropoff_longitude" value { float_list { } } } feature { key: "fare" value { float_list { value: 27.049999237060547 } } } feature { key: "payment_type" value { bytes_list { value: "Cash" } } } feature { key: "pickup_census_tract" value { int64_list { } } } feature { key: "pickup_community_area" value { int64_list { value: 60 } } } feature { key: "pickup_latitude" value { float_list { value: 41.836151123046875 } } } feature { key: "pickup_longitude" value { float_list { value: -87.64878845214844 } } } feature { key: "tips" value { float_list { value: 0.0 } } } feature { key: "trip_miles" value { float_list { value: 12.600000381469727 } } } feature { key: "trip_seconds" value { int64_list { value: 1380 } } } feature { key: "trip_start_day" value { int64_list { value: 3 } } } feature { key: "trip_start_hour" value { int64_list { value: 2 } } } feature { key: "trip_start_month" value { int64_list { value: 10 } } } feature { key: "trip_start_timestamp" value { int64_list { value: 1380593700 } } } } features { feature { key: "company" value { bytes_list { } } } feature { key: "dropoff_census_tract" value { int64_list { } } } feature { key: "dropoff_community_area" value { int64_list { } } } feature { key: "dropoff_latitude" value { float_list { } } } feature { key: "dropoff_longitude" value { float_list { } } } feature { key: "fare" value { float_list { value: 16.450000762939453 } } } feature { key: "payment_type" value { bytes_list { value: "Cash" } } } feature { key: "pickup_census_tract" value { int64_list { } } } feature { key: "pickup_community_area" value { int64_list { value: 13 } } } feature { key: "pickup_latitude" value { float_list { value: 41.98363494873047 } } } feature { key: "pickup_longitude" value { float_list { value: -87.72357940673828 } } } feature { key: "tips" value { float_list { value: 0.0 } } } feature { key: "trip_miles" value { float_list { value: 6.900000095367432 } } } feature { key: "trip_seconds" value { int64_list { value: 780 } } } feature { key: "trip_start_day" value { int64_list { value: 3 } } } feature { key: "trip_start_hour" value { int64_list { value: 12 } } } feature { key: "trip_start_month" value { int64_list { value: 11 } } } feature { key: "trip_start_timestamp" value { int64_list { value: 1446554700 } } } }
এখন যে ExampleGen
ডেটা ExampleGen
করা শেষ করেছে, পরবর্তী পদক্ষেপটি ডেটা বিশ্লেষণ।
পরিসংখ্যান
StatisticsGen
উপাদান আপনার ডেটাসেটের উপরে ডেটা বিশ্লেষণের জন্য, পাশাপাশি ডাউন স্ট্রিম উপাদানগুলিতে ব্যবহারের জন্য পরিসংখ্যানগুলি গণনা করে। এটি টেনসরফ্লো ডেটা বৈধকরণ লাইব্রেরি ব্যবহার করে।
StatisticsGen
ইনপুট হিসাবে ডেটাসেটটি গ্রহণ করে ExampleGen
আমরা স্রেফ ExampleGen
ব্যবহার করে ExampleGen
।
statistics_gen = StatisticsGen(
examples=example_gen.outputs['examples'])
context.run(statistics_gen)
INFO:absl:Excluding no splits because exclude_splits is not set. INFO:absl:Running driver for StatisticsGen INFO:absl:MetadataStore with DB connection initialized INFO:absl:Running executor for StatisticsGen INFO:absl:Generating statistics for split train. INFO:absl:Statistics for split train written to /tmp/tfx-interactive-2021-02-01T10_16_29.340076-cd248luc/StatisticsGen/statistics/2/train. INFO:absl:Generating statistics for split eval. INFO:absl:Statistics for split eval written to /tmp/tfx-interactive-2021-02-01T10_16_29.340076-cd248luc/StatisticsGen/statistics/2/eval. INFO:absl:Running publisher for StatisticsGen INFO:absl:MetadataStore with DB connection initialized
StatisticsGen
চলমান শেষ হওয়ার পরে, আমরা আউটপুটযুক্ত পরিসংখ্যানগুলিকে কল্পনা করতে পারি। বিভিন্ন প্লট দিয়ে খেলা চেষ্টা করুন!
context.show(statistics_gen.outputs['statistics'])
স্কিমাগেন
SchemaGen
উপাদান আপনার ডেটা পরিসংখ্যানের ভিত্তিতে একটি স্কিমা উত্পন্ন করে। (একটি স্কিমা আপনার ডেটাসেটের বৈশিষ্ট্যগুলির প্রত্যাশিত সীমা, প্রকার এবং বৈশিষ্ট্যগুলি সংজ্ঞায়িত করে)) এটি টেনসরফ্লো ডেটা বৈধকরণ লাইব্রেরিও ব্যবহার করে।
SchemaGen
পরিসংখ্যানগুলিকে ইনপুট হিসাবে গ্রহণ করব যা আমরা StatisticsGen
দিয়ে তৈরি করেছি, ডিফল্টরূপে প্রশিক্ষণকে বিভক্ত করে দেখছি।
schema_gen = SchemaGen(
statistics=statistics_gen.outputs['statistics'],
infer_feature_shape=False)
context.run(schema_gen)
INFO:absl:Excluding no splits because exclude_splits is not set. INFO:absl:Running driver for SchemaGen INFO:absl:MetadataStore with DB connection initialized INFO:absl:Running executor for SchemaGen INFO:absl:Processing schema from statistics for split train. INFO:absl:Processing schema from statistics for split eval. INFO:absl:Schema written to /tmp/tfx-interactive-2021-02-01T10_16_29.340076-cd248luc/SchemaGen/schema/3/schema.pbtxt. INFO:absl:Running publisher for SchemaGen INFO:absl:MetadataStore with DB connection initialized
SchemaGen
চলমান শেষ হওয়ার পরে, আমরা উত্পন্ন স্কিমাটি একটি টেবিল হিসাবে কল্পনা করতে পারি।
context.show(schema_gen.outputs['schema'])
/tmpfs/src/tf_docs_env/lib/python3.6/site-packages/tensorflow_data_validation/utils/display_util.py:151: FutureWarning: Passing a negative integer is deprecated in version 1.0 and will not be supported in future version. Instead, use None to not limit the column width. pd.set_option('max_colwidth', -1)
আপনার ডেটাসেটের প্রতিটি বৈশিষ্ট্য এর বৈশিষ্ট্যগুলির পাশাপাশি স্কিমা টেবিলের সারি হিসাবে দেখায়। স্কিমাটি একটি শ্রেণিবদ্ধ বৈশিষ্ট্যটি গ্রহণ করে এমন সমস্ত মানকে ক্যাপচার করে যা এর ডোমেন হিসাবে চিহ্নিত করা হয়।
স্কিমা সম্পর্কে আরও জানতে, স্কিমাজেন ডকুমেন্টেশন দেখুন ।
উদাহরণভালিডেটর
ExampleValidator
উপাদানটি স্কিমা দ্বারা সংজ্ঞায়িত প্রত্যাশার উপর ভিত্তি করে আপনার ডেটাতে ExampleValidator
সনাক্ত করে। এটি টেনসরফ্লো ডেটা বৈধকরণ গ্রন্থাগারও ব্যবহার করে।
ExampleValidator
পরিসংখ্যানজেন থেকে প্রাপ্ত StatisticsGen
এবং SchemaGen
স্কিমা হিসাবে ইনপুট হিসাবে গ্রহণ করবে।
example_validator = ExampleValidator(
statistics=statistics_gen.outputs['statistics'],
schema=schema_gen.outputs['schema'])
context.run(example_validator)
INFO:absl:Excluding no splits because exclude_splits is not set. INFO:absl:Running driver for ExampleValidator INFO:absl:MetadataStore with DB connection initialized INFO:absl:Running executor for ExampleValidator INFO:absl:Validating schema against the computed statistics for split train. INFO:absl:Validation complete for split train. Anomalies written to /tmp/tfx-interactive-2021-02-01T10_16_29.340076-cd248luc/ExampleValidator/anomalies/4/train. INFO:absl:Validating schema against the computed statistics for split eval. INFO:absl:Validation complete for split eval. Anomalies written to /tmp/tfx-interactive-2021-02-01T10_16_29.340076-cd248luc/ExampleValidator/anomalies/4/eval. INFO:absl:Running publisher for ExampleValidator INFO:absl:MetadataStore with DB connection initialized
ExampleValidator
চলমান শেষ হওয়ার পরে, আমরা ExampleValidator
একটি টেবিল হিসাবে কল্পনা করতে পারি।
context.show(example_validator.outputs['anomalies'])
অসঙ্গতি সারণীতে, আমরা দেখতে পাচ্ছি যে কোনও অসুবিধা নেই। এটি আমরা প্রত্যাশা করব, যেহেতু আমরা বিশ্লেষণ করেছি এবং স্কিমাটি এটি অনুসারে তৈরি করা হয়েছে dat আপনার এই স্কিমাটি পর্যালোচনা করা উচিত - অপ্রত্যাশিত কোনও কিছুর অর্থ ডেটাতে অসাধারণতা। একবার পর্যালোচনা করা হলে, স্কিমাটি ভবিষ্যতের ডেটা রক্ষার জন্য ব্যবহার করা যেতে পারে, এবং এখানে উত্পাদিত ব্যতিক্রমগুলি মডেল পারফরম্যান্স ডিবাগ করতে, সময়ের সাথে সাথে কীভাবে আপনার ডেটা বিকশিত হয় তা বুঝতে এবং ডেটা ত্রুটি সনাক্ত করতে ব্যবহার করা যেতে পারে।
রূপান্তর
Transform
উপাদান প্রশিক্ষণ এবং পরিবেশনের জন্য উভয়ই ফিচার ইঞ্জিনিয়ারিং সম্পাদন করে। এটি টেনসরফ্লো ট্রান্সফর্ম লাইব্রেরি ব্যবহার করে।
Transform
ইনপুট হিসাবে ExampleGen
, ExampleGen
স্কিমা এবং সেইসাথে ব্যবহারকারী-সংজ্ঞায়িত ট্রান্সফর্ম SchemaGen
একটি মডিউল হিসাবে SchemaGen
।
আসুন নীচে ব্যবহারকারী-সংজ্ঞায়িত ট্রান্সফর্ম কোডের একটি উদাহরণ দেখুন (টেনসরফ্লো ট্রান্সফর্ম এপিআইয়ের একটি পরিচিতির জন্য, টিউটোরিয়াল দেখুন )। প্রথমত, আমরা বৈশিষ্ট্য ইঞ্জিনিয়ারিংয়ের জন্য কয়েকটি ধ্রুবককে সংজ্ঞায়িত করি:
_taxi_constants_module_file = 'taxi_constants.py'
%%writefile {_taxi_constants_module_file}
# Categorical features are assumed to each have a maximum value in the dataset.
MAX_CATEGORICAL_FEATURE_VALUES = [24, 31, 12]
CATEGORICAL_FEATURE_KEYS = [
'trip_start_hour', 'trip_start_day', 'trip_start_month',
'pickup_census_tract', 'dropoff_census_tract', 'pickup_community_area',
'dropoff_community_area'
]
DENSE_FLOAT_FEATURE_KEYS = ['trip_miles', 'fare', 'trip_seconds']
# Number of buckets used by tf.transform for encoding each feature.
FEATURE_BUCKET_COUNT = 10
BUCKET_FEATURE_KEYS = [
'pickup_latitude', 'pickup_longitude', 'dropoff_latitude',
'dropoff_longitude'
]
# Number of vocabulary terms used for encoding VOCAB_FEATURES by tf.transform
VOCAB_SIZE = 1000
# Count of out-of-vocab buckets in which unrecognized VOCAB_FEATURES are hashed.
OOV_SIZE = 10
VOCAB_FEATURE_KEYS = [
'payment_type',
'company',
]
# Keys
LABEL_KEY = 'tips'
FARE_KEY = 'fare'
def transformed_name(key):
return key + '_xf'
Writing taxi_constants.py
এরপরে, আমরা একটি preprocessing_fn
লিখি যা কাঁচা ডেটা ইনপুট হিসাবে গ্রহণ করে এবং আমাদের মডেল প্রশিক্ষণ দিতে পারে এমন রূপান্তরিত বৈশিষ্ট্যগুলি ফেরত দেয়:
_taxi_transform_module_file = 'taxi_transform.py'
%%writefile {_taxi_transform_module_file}
import tensorflow as tf
import tensorflow_transform as tft
import taxi_constants
_DENSE_FLOAT_FEATURE_KEYS = taxi_constants.DENSE_FLOAT_FEATURE_KEYS
_VOCAB_FEATURE_KEYS = taxi_constants.VOCAB_FEATURE_KEYS
_VOCAB_SIZE = taxi_constants.VOCAB_SIZE
_OOV_SIZE = taxi_constants.OOV_SIZE
_FEATURE_BUCKET_COUNT = taxi_constants.FEATURE_BUCKET_COUNT
_BUCKET_FEATURE_KEYS = taxi_constants.BUCKET_FEATURE_KEYS
_CATEGORICAL_FEATURE_KEYS = taxi_constants.CATEGORICAL_FEATURE_KEYS
_FARE_KEY = taxi_constants.FARE_KEY
_LABEL_KEY = taxi_constants.LABEL_KEY
_transformed_name = taxi_constants.transformed_name
def preprocessing_fn(inputs):
"""tf.transform's callback function for preprocessing inputs.
Args:
inputs: map from feature keys to raw not-yet-transformed features.
Returns:
Map from string feature key to transformed feature operations.
"""
outputs = {}
for key in _DENSE_FLOAT_FEATURE_KEYS:
# Preserve this feature as a dense float, setting nan's to the mean.
outputs[_transformed_name(key)] = tft.scale_to_z_score(
_fill_in_missing(inputs[key]))
for key in _VOCAB_FEATURE_KEYS:
# Build a vocabulary for this feature.
outputs[_transformed_name(key)] = tft.compute_and_apply_vocabulary(
_fill_in_missing(inputs[key]),
top_k=_VOCAB_SIZE,
num_oov_buckets=_OOV_SIZE)
for key in _BUCKET_FEATURE_KEYS:
outputs[_transformed_name(key)] = tft.bucketize(
_fill_in_missing(inputs[key]), _FEATURE_BUCKET_COUNT)
for key in _CATEGORICAL_FEATURE_KEYS:
outputs[_transformed_name(key)] = _fill_in_missing(inputs[key])
# Was this passenger a big tipper?
taxi_fare = _fill_in_missing(inputs[_FARE_KEY])
tips = _fill_in_missing(inputs[_LABEL_KEY])
outputs[_transformed_name(_LABEL_KEY)] = tf.where(
tf.math.is_nan(taxi_fare),
tf.cast(tf.zeros_like(taxi_fare), tf.int64),
# Test if the tip was > 20% of the fare.
tf.cast(
tf.greater(tips, tf.multiply(taxi_fare, tf.constant(0.2))), tf.int64))
return outputs
def _fill_in_missing(x):
"""Replace missing values in a SparseTensor.
Fills in missing values of `x` with '' or 0, and converts to a dense tensor.
Args:
x: A `SparseTensor` of rank 2. Its dense shape should have size at most 1
in the second dimension.
Returns:
A rank 1 tensor where missing values of `x` have been filled in.
"""
if not isinstance(x, tf.sparse.SparseTensor):
return x
default_value = '' if x.dtype == tf.string else 0
return tf.squeeze(
tf.sparse.to_dense(
tf.SparseTensor(x.indices, x.values, [x.dense_shape[0], 1]),
default_value),
axis=1)
Writing taxi_transform.py
এখন, আমরা এই বৈশিষ্ট্যটি ইঞ্জিনিয়ারিং Transform
উপাদানটিতে প্রবেশ করি এবং এটি আপনার ডেটা রূপান্তর করতে চালিত করি।
transform = Transform(
examples=example_gen.outputs['examples'],
schema=schema_gen.outputs['schema'],
module_file=os.path.abspath(_taxi_transform_module_file))
context.run(transform)
INFO:absl:Running driver for Transform INFO:absl:MetadataStore with DB connection initialized INFO:absl:Running executor for Transform INFO:absl:Analyze the 'train' split and transform all splits when splits_config is not set. WARNING:absl:The default value of `force_tf_compat_v1` will change in a future release from `True` to `False`. Since this pipeline has TF 2 behaviors enabled, Transform will use native TF 2 at that point. You can test this behavior now by passing `force_tf_compat_v1=False` or disable it by explicitly setting `force_tf_compat_v1=True` in the Transform component. WARNING:tensorflow:From /tmpfs/src/tf_docs_env/lib/python3.6/site-packages/tfx/components/transform/executor.py:541: Schema (from tensorflow_transform.tf_metadata.dataset_schema) is deprecated and will be removed in a future version. Instructions for updating: Schema is a deprecated, use schema_utils.schema_from_feature_spec to create a `Schema` INFO:absl:Loading /tmpfs/src/temp/docs/tutorials/tfx/taxi_transform.py because it has not been loaded before. INFO:absl:/tmpfs/src/temp/docs/tutorials/tfx/taxi_transform.py is already loaded. INFO:absl:Feature company has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature payment_type has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature dropoff_census_tract has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature dropoff_community_area has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature dropoff_latitude has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature dropoff_longitude has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature fare has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature pickup_census_tract has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature pickup_community_area has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature pickup_latitude has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature pickup_longitude has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature tips has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature trip_miles has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature trip_seconds has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature trip_start_day has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature trip_start_hour has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature trip_start_month has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature trip_start_timestamp has no shape. Setting to VarLenSparseTensor. WARNING:tensorflow:From /tmpfs/src/tf_docs_env/lib/python3.6/site-packages/tensorflow_transform/tf_utils.py:261: Tensor.experimental_ref (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version. Instructions for updating: Use ref() instead. INFO:absl:Feature company has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature payment_type has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature dropoff_census_tract has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature dropoff_community_area has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature dropoff_latitude has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature dropoff_longitude has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature fare has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature pickup_census_tract has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature pickup_community_area has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature pickup_latitude has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature pickup_longitude has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature tips has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature trip_miles has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature trip_seconds has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature trip_start_day has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature trip_start_hour has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature trip_start_month has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature trip_start_timestamp has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature company has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature payment_type has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature dropoff_census_tract has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature dropoff_community_area has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature dropoff_latitude has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature dropoff_longitude has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature fare has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature pickup_census_tract has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature pickup_community_area has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature pickup_latitude has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature pickup_longitude has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature tips has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature trip_miles has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature trip_seconds has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature trip_start_day has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature trip_start_hour has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature trip_start_month has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature trip_start_timestamp has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature company has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature payment_type has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature dropoff_census_tract has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature dropoff_community_area has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature dropoff_latitude has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature dropoff_longitude has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature fare has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature pickup_census_tract has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature pickup_community_area has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature pickup_latitude has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature pickup_longitude has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature tips has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature trip_miles has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature trip_seconds has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature trip_start_day has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature trip_start_hour has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature trip_start_month has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature trip_start_timestamp has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature company has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature payment_type has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature dropoff_census_tract has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature dropoff_community_area has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature dropoff_latitude has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature dropoff_longitude has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature fare has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature pickup_census_tract has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature pickup_community_area has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature pickup_latitude has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature pickup_longitude has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature tips has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature trip_miles has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature trip_seconds has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature trip_start_day has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature trip_start_hour has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature trip_start_month has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature trip_start_timestamp has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature company has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature payment_type has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature dropoff_census_tract has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature dropoff_community_area has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature dropoff_latitude has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature dropoff_longitude has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature fare has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature pickup_census_tract has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature pickup_community_area has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature pickup_latitude has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature pickup_longitude has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature tips has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature trip_miles has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature trip_seconds has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature trip_start_day has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature trip_start_hour has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature trip_start_month has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature trip_start_timestamp has no shape. Setting to VarLenSparseTensor. WARNING:tensorflow:TFT beam APIs accept both the TFXIO format and the instance dict format now. There is no need to set use_tfxio any more and it will be removed soon. WARNING:root:This output type hint will be ignored and not used for type-checking purposes. Typically, output type hints for a PTransform are single (or nested) types wrapped by a PCollection, PDone, or None. Got: Tuple[Dict[str, Union[NoneType, _Dataset]], Union[Dict[str, Dict[str, PCollection]], NoneType]] instead. WARNING:root:This output type hint will be ignored and not used for type-checking purposes. Typically, output type hints for a PTransform are single (or nested) types wrapped by a PCollection, PDone, or None. Got: Tuple[Dict[str, Union[NoneType, _Dataset]], Union[Dict[str, Dict[str, PCollection]], NoneType]] instead. WARNING:tensorflow:Tensorflow version (2.3.2) found. Note that Tensorflow Transform support for TF 2.0 is currently in beta, and features such as tf.function may not work as intended. WARNING:tensorflow:From /tmpfs/src/tf_docs_env/lib/python3.6/site-packages/tensorflow/python/saved_model/signature_def_utils_impl.py:201: build_tensor_info (from tensorflow.python.saved_model.utils_impl) is deprecated and will be removed in a future version. Instructions for updating: This function will only be available through the v1 compatibility library as tf.compat.v1.saved_model.utils.build_tensor_info or tf.compat.v1.saved_model.build_tensor_info. INFO:tensorflow:Assets added to graph. INFO:tensorflow:No assets to write. WARNING:tensorflow:Issue encountered when serializing tft_mapper_use. Type is unsupported, or the types of the items don't match field type in CollectionDef. Note this is a warning and probably safe to ignore. 'Counter' object has no attribute 'name' INFO:tensorflow:SavedModel written to: /tmp/tfx-interactive-2021-02-01T10_16_29.340076-cd248luc/Transform/transform_graph/5/.temp_path/tftransform_tmp/d753c1ea35fc4e349c75af85b9e9db5d/saved_model.pb INFO:tensorflow:Assets added to graph. INFO:tensorflow:No assets to write. WARNING:tensorflow:Issue encountered when serializing tft_mapper_use. Type is unsupported, or the types of the items don't match field type in CollectionDef. Note this is a warning and probably safe to ignore. 'Counter' object has no attribute 'name' INFO:tensorflow:SavedModel written to: /tmp/tfx-interactive-2021-02-01T10_16_29.340076-cd248luc/Transform/transform_graph/5/.temp_path/tftransform_tmp/d854ff09cccf4c25a2b84437181d2810/saved_model.pb INFO:absl:Feature company has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature payment_type has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature dropoff_census_tract has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature dropoff_community_area has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature dropoff_latitude has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature dropoff_longitude has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature fare has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature pickup_census_tract has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature pickup_community_area has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature pickup_latitude has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature pickup_longitude has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature tips has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature trip_miles has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature trip_seconds has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature trip_start_day has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature trip_start_hour has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature trip_start_month has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature trip_start_timestamp has no shape. Setting to VarLenSparseTensor. WARNING:tensorflow:Tensorflow version (2.3.2) found. Note that Tensorflow Transform support for TF 2.0 is currently in beta, and features such as tf.function may not work as intended. WARNING:apache_beam.typehints.typehints:Ignoring send_type hint: <class 'NoneType'> WARNING:apache_beam.typehints.typehints:Ignoring return_type hint: <class 'NoneType'> WARNING:apache_beam.typehints.typehints:Ignoring send_type hint: <class 'NoneType'> WARNING:apache_beam.typehints.typehints:Ignoring return_type hint: <class 'NoneType'> WARNING:apache_beam.typehints.typehints:Ignoring send_type hint: <class 'NoneType'> WARNING:apache_beam.typehints.typehints:Ignoring return_type hint: <class 'NoneType'> INFO:absl:Feature company has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature payment_type has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature dropoff_census_tract has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature dropoff_community_area has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature dropoff_latitude has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature dropoff_longitude has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature fare has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature pickup_census_tract has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature pickup_community_area has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature pickup_latitude has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature pickup_longitude has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature tips has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature trip_miles has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature trip_seconds has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature trip_start_day has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature trip_start_hour has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature trip_start_month has no shape. Setting to VarLenSparseTensor. INFO:absl:Feature trip_start_timestamp has no shape. Setting to VarLenSparseTensor. WARNING:tensorflow:Tensorflow version (2.3.2) found. Note that Tensorflow Transform support for TF 2.0 is currently in beta, and features such as tf.function may not work as intended. WARNING:apache_beam.typehints.typehints:Ignoring send_type hint: <class 'NoneType'> WARNING:apache_beam.typehints.typehints:Ignoring return_type hint: <class 'NoneType'> WARNING:apache_beam.typehints.typehints:Ignoring send_type hint: <class 'NoneType'> WARNING:apache_beam.typehints.typehints:Ignoring return_type hint: <class 'NoneType'> WARNING:apache_beam.typehints.typehints:Ignoring send_type hint: <class 'NoneType'> WARNING:apache_beam.typehints.typehints:Ignoring return_type hint: <class 'NoneType'> INFO:tensorflow:Saver not created because there are no variables in the graph to restore INFO:tensorflow:Saver not created because there are no variables in the graph to restore INFO:tensorflow:Assets added to graph. INFO:tensorflow:Assets written to: /tmp/tfx-interactive-2021-02-01T10_16_29.340076-cd248luc/Transform/transform_graph/5/.temp_path/tftransform_tmp/8de2b014086c4615a0aa01d1dc62ed2f/assets INFO:tensorflow:SavedModel written to: /tmp/tfx-interactive-2021-02-01T10_16_29.340076-cd248luc/Transform/transform_graph/5/.temp_path/tftransform_tmp/8de2b014086c4615a0aa01d1dc62ed2f/saved_model.pb WARNING:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef" value: "\n\013\n\tConst_2:0\022-vocab_compute_and_apply_vocabulary_vocabulary" WARNING:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef" value: "\n\013\n\tConst_4:0\022/vocab_compute_and_apply_vocabulary_1_vocabulary" INFO:tensorflow:Saver not created because there are no variables in the graph to restore WARNING:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef" value: "\n\013\n\tConst_2:0\022-vocab_compute_and_apply_vocabulary_vocabulary" WARNING:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef" value: "\n\013\n\tConst_4:0\022/vocab_compute_and_apply_vocabulary_1_vocabulary" INFO:tensorflow:Saver not created because there are no variables in the graph to restore WARNING:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef" value: "\n\013\n\tConst_2:0\022-vocab_compute_and_apply_vocabulary_vocabulary" WARNING:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef" value: "\n\013\n\tConst_4:0\022/vocab_compute_and_apply_vocabulary_1_vocabulary" INFO:tensorflow:Saver not created because there are no variables in the graph to restore INFO:absl:Running publisher for Transform INFO:absl:MetadataStore with DB connection initialized
আসুন Transform
আউটপুট শিল্পকর্মগুলি পরীক্ষা করি। এই উপাদানটি দুটি ধরণের আউটপুট উত্পাদন করে:
-
transform_graph
হ'ল গ্রাফ যা প্রিপ্রসেসিং ক্রিয়াকলাপ সম্পাদন করতে পারে (এই গ্রাফটি পরিবেশন এবং মূল্যায়ন মডেলগুলিতে অন্তর্ভুক্ত করা হবে)। -
transformed_examples
প্রিপ্রোসেসড ট্রেনিং এবং মূল্যায়ন ডেটার প্রতিনিধিত্ব করে।
transform.outputs
{'transform_graph': Channel( type_name: TransformGraph artifacts: [Artifact(artifact: id: 5 type_id: 13 uri: "/tmp/tfx-interactive-2021-02-01T10_16_29.340076-cd248luc/Transform/transform_graph/5" custom_properties { key: "name" value { string_value: "transform_graph" } } custom_properties { key: "producer_component" value { string_value: "Transform" } } custom_properties { key: "state" value { string_value: "published" } } state: LIVE , artifact_type: id: 13 name: "TransformGraph" )] ), 'transformed_examples': Channel( type_name: Examples artifacts: [Artifact(artifact: id: 6 type_id: 5 uri: "/tmp/tfx-interactive-2021-02-01T10_16_29.340076-cd248luc/Transform/transformed_examples/5" properties { key: "split_names" value { string_value: "[\"train\", \"eval\"]" } } custom_properties { key: "name" value { string_value: "transformed_examples" } } custom_properties { key: "producer_component" value { string_value: "Transform" } } custom_properties { key: "state" value { string_value: "published" } } state: LIVE , artifact_type: id: 5 name: "Examples" properties { key: "span" value: INT } properties { key: "split_names" value: STRING } properties { key: "version" value: INT } )] ), 'updated_analyzer_cache': Channel( type_name: TransformCache artifacts: [Artifact(artifact: id: 7 type_id: 14 uri: "/tmp/tfx-interactive-2021-02-01T10_16_29.340076-cd248luc/Transform/updated_analyzer_cache/5" custom_properties { key: "name" value { string_value: "updated_analyzer_cache" } } custom_properties { key: "producer_component" value { string_value: "Transform" } } custom_properties { key: "state" value { string_value: "published" } } state: LIVE , artifact_type: id: 14 name: "TransformCache" )] )}
transform_graph
আর্টিফ্যাক্টটি দেখুন। এটি তিনটি উপ-ডিরেক্টরি সহ একটি ডিরেক্টরিতে নির্দেশ করে।
train_uri = transform.outputs['transform_graph'].get()[0].uri
os.listdir(train_uri)
['transform_fn', 'transformed_metadata', 'metadata']
transformed_metadata
সাব-ডিরেক্টরীতে প্রাক-প্রসেসড ডেটার স্কিমা রয়েছে। transform_fn
সাব-ডিরেক্টরীতে প্রকৃত প্রাকপ্রসেসিং গ্রাফ থাকে graph metadata
সাব-ডিরেক্টরিতে মূল ডেটার স্কিমা থাকে।
আমরা প্রথম তিনটি রূপান্তরিত উদাহরণও একবার দেখে নিতে পারি:
# Get the URI of the output artifact representing the transformed examples, which is a directory
train_uri = os.path.join(transform.outputs['transformed_examples'].get()[0].uri, 'train')
# Get the list of files in this directory (all compressed TFRecord files)
tfrecord_filenames = [os.path.join(train_uri, name)
for name in os.listdir(train_uri)]
# Create a `TFRecordDataset` to read these files
dataset = tf.data.TFRecordDataset(tfrecord_filenames, compression_type="GZIP")
# Iterate over the first 3 records and decode them.
for tfrecord in dataset.take(3):
serialized_example = tfrecord.numpy()
example = tf.train.Example()
example.ParseFromString(serialized_example)
pp.pprint(example)
features { feature { key: "company_xf" value { int64_list { value: 8 } } } feature { key: "dropoff_census_tract_xf" value { int64_list { value: 0 } } } feature { key: "dropoff_community_area_xf" value { int64_list { value: 0 } } } feature { key: "dropoff_latitude_xf" value { int64_list { value: 0 } } } feature { key: "dropoff_longitude_xf" value { int64_list { value: 9 } } } feature { key: "fare_xf" value { float_list { value: 0.06106060370802879 } } } feature { key: "payment_type_xf" value { int64_list { value: 1 } } } feature { key: "pickup_census_tract_xf" value { int64_list { value: 0 } } } feature { key: "pickup_community_area_xf" value { int64_list { value: 0 } } } feature { key: "pickup_latitude_xf" value { int64_list { value: 0 } } } feature { key: "pickup_longitude_xf" value { int64_list { value: 9 } } } feature { key: "tips_xf" value { int64_list { value: 0 } } } feature { key: "trip_miles_xf" value { float_list { value: -0.15886740386486053 } } } feature { key: "trip_seconds_xf" value { float_list { value: -0.7118487358093262 } } } feature { key: "trip_start_day_xf" value { int64_list { value: 6 } } } feature { key: "trip_start_hour_xf" value { int64_list { value: 19 } } } feature { key: "trip_start_month_xf" value { int64_list { value: 5 } } } } features { feature { key: "company_xf" value { int64_list { value: 0 } } } feature { key: "dropoff_census_tract_xf" value { int64_list { value: 0 } } } feature { key: "dropoff_community_area_xf" value { int64_list { value: 0 } } } feature { key: "dropoff_latitude_xf" value { int64_list { value: 0 } } } feature { key: "dropoff_longitude_xf" value { int64_list { value: 9 } } } feature { key: "fare_xf" value { float_list { value: 1.2521241903305054 } } } feature { key: "payment_type_xf" value { int64_list { value: 0 } } } feature { key: "pickup_census_tract_xf" value { int64_list { value: 0 } } } feature { key: "pickup_community_area_xf" value { int64_list { value: 60 } } } feature { key: "pickup_latitude_xf" value { int64_list { value: 0 } } } feature { key: "pickup_longitude_xf" value { int64_list { value: 3 } } } feature { key: "tips_xf" value { int64_list { value: 0 } } } feature { key: "trip_miles_xf" value { float_list { value: 0.532160758972168 } } } feature { key: "trip_seconds_xf" value { float_list { value: 0.5509493350982666 } } } feature { key: "trip_start_day_xf" value { int64_list { value: 3 } } } feature { key: "trip_start_hour_xf" value { int64_list { value: 2 } } } feature { key: "trip_start_month_xf" value { int64_list { value: 10 } } } } features { feature { key: "company_xf" value { int64_list { value: 48 } } } feature { key: "dropoff_census_tract_xf" value { int64_list { value: 0 } } } feature { key: "dropoff_community_area_xf" value { int64_list { value: 0 } } } feature { key: "dropoff_latitude_xf" value { int64_list { value: 0 } } } feature { key: "dropoff_longitude_xf" value { int64_list { value: 9 } } } feature { key: "fare_xf" value { float_list { value: 0.3873794972896576 } } } feature { key: "payment_type_xf" value { int64_list { value: 0 } } } feature { key: "pickup_census_tract_xf" value { int64_list { value: 0 } } } feature { key: "pickup_community_area_xf" value { int64_list { value: 13 } } } feature { key: "pickup_latitude_xf" value { int64_list { value: 9 } } } feature { key: "pickup_longitude_xf" value { int64_list { value: 0 } } } feature { key: "tips_xf" value { int64_list { value: 0 } } } feature { key: "trip_miles_xf" value { float_list { value: 0.21955278515815735 } } } feature { key: "trip_seconds_xf" value { float_list { value: 0.0019067145185545087 } } } feature { key: "trip_start_day_xf" value { int64_list { value: 3 } } } feature { key: "trip_start_hour_xf" value { int64_list { value: 12 } } } feature { key: "trip_start_month_xf" value { int64_list { value: 11 } } } }
Transform
উপাদানটি আপনার ডেটাগুলিকে বৈশিষ্ট্যগুলিতে রূপান্তরিত করার পরে এবং পরবর্তী পদক্ষেপটি একটি মডেলকে প্রশিক্ষণ দেওয়া।
প্রশিক্ষক
Trainer
উপাদান এমন একটি মডেলকে Trainer
দেবে যা আপনি টেনসরফ্লোতে সংজ্ঞায়িত করেন। ডিফল্ট ট্রেনার Estimator এপিআই সমর্থন করে, কেরাস এপিআই ব্যবহার করতে, আপনার custom_executor_spec=executor_spec.ExecutorClassSpec(GenericExecutor)
দ্বারা জেনেরিক ট্রেনার নির্দিষ্ট করতে হবে।
Trainer
SchemaGen
থেকে স্কিমা, Transform
থেকে Transform
ডেটা এবং গ্রাফ, প্রশিক্ষণ পরামিতি এবং সেই সাথে একটি মডিউল যা ব্যবহারকারী-সংজ্ঞায়িত মডেল কোড ধারণ করে।
আসুন নীচে ব্যবহারকারী-সংজ্ঞায়িত মডেল কোডের একটি উদাহরণ দেখুন (টেনসরফ্লো কেরাস এপিআইয়ের পরিচিতির জন্য, টিউটোরিয়ালটি দেখুন ):
_taxi_trainer_module_file = 'taxi_trainer.py'
%%writefile {_taxi_trainer_module_file}
from typing import List, Text
import os
import absl
import datetime
import tensorflow as tf
import tensorflow_transform as tft
from tfx.components.trainer.executor import TrainerFnArgs
from tfx.components.trainer.fn_args_utils import DataAccessor
from tfx_bsl.tfxio import dataset_options
import taxi_constants
_DENSE_FLOAT_FEATURE_KEYS = taxi_constants.DENSE_FLOAT_FEATURE_KEYS
_VOCAB_FEATURE_KEYS = taxi_constants.VOCAB_FEATURE_KEYS
_VOCAB_SIZE = taxi_constants.VOCAB_SIZE
_OOV_SIZE = taxi_constants.OOV_SIZE
_FEATURE_BUCKET_COUNT = taxi_constants.FEATURE_BUCKET_COUNT
_BUCKET_FEATURE_KEYS = taxi_constants.BUCKET_FEATURE_KEYS
_CATEGORICAL_FEATURE_KEYS = taxi_constants.CATEGORICAL_FEATURE_KEYS
_MAX_CATEGORICAL_FEATURE_VALUES = taxi_constants.MAX_CATEGORICAL_FEATURE_VALUES
_LABEL_KEY = taxi_constants.LABEL_KEY
_transformed_name = taxi_constants.transformed_name
def _transformed_names(keys):
return [_transformed_name(key) for key in keys]
def _get_serve_tf_examples_fn(model, tf_transform_output):
"""Returns a function that parses a serialized tf.Example and applies TFT."""
model.tft_layer = tf_transform_output.transform_features_layer()
@tf.function
def serve_tf_examples_fn(serialized_tf_examples):
"""Returns the output to be used in the serving signature."""
feature_spec = tf_transform_output.raw_feature_spec()
feature_spec.pop(_LABEL_KEY)
parsed_features = tf.io.parse_example(serialized_tf_examples, feature_spec)
transformed_features = model.tft_layer(parsed_features)
return model(transformed_features)
return serve_tf_examples_fn
def _input_fn(file_pattern: List[Text],
data_accessor: DataAccessor,
tf_transform_output: tft.TFTransformOutput,
batch_size: int = 200) -> tf.data.Dataset:
"""Generates features and label for tuning/training.
Args:
file_pattern: List of paths or patterns of input tfrecord files.
data_accessor: DataAccessor for converting input to RecordBatch.
tf_transform_output: A TFTransformOutput.
batch_size: representing the number of consecutive elements of returned
dataset to combine in a single batch
Returns:
A dataset that contains (features, indices) tuple where features is a
dictionary of Tensors, and indices is a single Tensor of label indices.
"""
return data_accessor.tf_dataset_factory(
file_pattern,
dataset_options.TensorFlowDatasetOptions(
batch_size=batch_size, label_key=_transformed_name(_LABEL_KEY)),
tf_transform_output.transformed_metadata.schema)
def _build_keras_model(hidden_units: List[int] = None) -> tf.keras.Model:
"""Creates a DNN Keras model for classifying taxi data.
Args:
hidden_units: [int], the layer sizes of the DNN (input layer first).
Returns:
A keras Model.
"""
real_valued_columns = [
tf.feature_column.numeric_column(key, shape=())
for key in _transformed_names(_DENSE_FLOAT_FEATURE_KEYS)
]
categorical_columns = [
tf.feature_column.categorical_column_with_identity(
key, num_buckets=_VOCAB_SIZE + _OOV_SIZE, default_value=0)
for key in _transformed_names(_VOCAB_FEATURE_KEYS)
]
categorical_columns += [
tf.feature_column.categorical_column_with_identity(
key, num_buckets=_FEATURE_BUCKET_COUNT, default_value=0)
for key in _transformed_names(_BUCKET_FEATURE_KEYS)
]
categorical_columns += [
tf.feature_column.categorical_column_with_identity( # pylint: disable=g-complex-comprehension
key,
num_buckets=num_buckets,
default_value=0) for key, num_buckets in zip(
_transformed_names(_CATEGORICAL_FEATURE_KEYS),
_MAX_CATEGORICAL_FEATURE_VALUES)
]
indicator_column = [
tf.feature_column.indicator_column(categorical_column)
for categorical_column in categorical_columns
]
model = _wide_and_deep_classifier(
# TODO(b/139668410) replace with premade wide_and_deep keras model
wide_columns=indicator_column,
deep_columns=real_valued_columns,
dnn_hidden_units=hidden_units or [100, 70, 50, 25])
return model
def _wide_and_deep_classifier(wide_columns, deep_columns, dnn_hidden_units):
"""Build a simple keras wide and deep model.
Args:
wide_columns: Feature columns wrapped in indicator_column for wide (linear)
part of the model.
deep_columns: Feature columns for deep part of the model.
dnn_hidden_units: [int], the layer sizes of the hidden DNN.
Returns:
A Wide and Deep Keras model
"""
# Following values are hard coded for simplicity in this example,
# However prefarably they should be passsed in as hparams.
# Keras needs the feature definitions at compile time.
# TODO(b/139081439): Automate generation of input layers from FeatureColumn.
input_layers = {
colname: tf.keras.layers.Input(name=colname, shape=(), dtype=tf.float32)
for colname in _transformed_names(_DENSE_FLOAT_FEATURE_KEYS)
}
input_layers.update({
colname: tf.keras.layers.Input(name=colname, shape=(), dtype='int32')
for colname in _transformed_names(_VOCAB_FEATURE_KEYS)
})
input_layers.update({
colname: tf.keras.layers.Input(name=colname, shape=(), dtype='int32')
for colname in _transformed_names(_BUCKET_FEATURE_KEYS)
})
input_layers.update({
colname: tf.keras.layers.Input(name=colname, shape=(), dtype='int32')
for colname in _transformed_names(_CATEGORICAL_FEATURE_KEYS)
})
# TODO(b/161952382): Replace with Keras preprocessing layers.
deep = tf.keras.layers.DenseFeatures(deep_columns)(input_layers)
for numnodes in dnn_hidden_units:
deep = tf.keras.layers.Dense(numnodes)(deep)
wide = tf.keras.layers.DenseFeatures(wide_columns)(input_layers)
output = tf.keras.layers.Dense(
1, activation='sigmoid')(
tf.keras.layers.concatenate([deep, wide]))
model = tf.keras.Model(input_layers, output)
model.compile(
loss='binary_crossentropy',
optimizer=tf.keras.optimizers.Adam(lr=0.001),
metrics=[tf.keras.metrics.BinaryAccuracy()])
model.summary(print_fn=absl.logging.info)
return model
# TFX Trainer will call this function.
def run_fn(fn_args: TrainerFnArgs):
"""Train the model based on given args.
Args:
fn_args: Holds args used to train the model as name/value pairs.
"""
# Number of nodes in the first layer of the DNN
first_dnn_layer_size = 100
num_dnn_layers = 4
dnn_decay_factor = 0.7
tf_transform_output = tft.TFTransformOutput(fn_args.transform_output)
train_dataset = _input_fn(fn_args.train_files, fn_args.data_accessor,
tf_transform_output, 40)
eval_dataset = _input_fn(fn_args.eval_files, fn_args.data_accessor,
tf_transform_output, 40)
model = _build_keras_model(
# Construct layers sizes with exponetial decay
hidden_units=[
max(2, int(first_dnn_layer_size * dnn_decay_factor**i))
for i in range(num_dnn_layers)
])
tensorboard_callback = tf.keras.callbacks.TensorBoard(
log_dir=fn_args.model_run_dir, update_freq='batch')
model.fit(
train_dataset,
steps_per_epoch=fn_args.train_steps,
validation_data=eval_dataset,
validation_steps=fn_args.eval_steps,
callbacks=[tensorboard_callback])
signatures = {
'serving_default':
_get_serve_tf_examples_fn(model,
tf_transform_output).get_concrete_function(
tf.TensorSpec(
shape=[None],
dtype=tf.string,
name='examples')),
}
model.save(fn_args.serving_model_dir, save_format='tf', signatures=signatures)
Writing taxi_trainer.py
এখন, আমরা এই মডেল Trainer
উপাদানটিতে প্রবেশ করি এবং এটি মডেলটিকে প্রশিক্ষণ দিতে চালিত করি।
trainer = Trainer(
module_file=os.path.abspath(_taxi_trainer_module_file),
custom_executor_spec=executor_spec.ExecutorClassSpec(GenericExecutor),
examples=transform.outputs['transformed_examples'],
transform_graph=transform.outputs['transform_graph'],
schema=schema_gen.outputs['schema'],
train_args=trainer_pb2.TrainArgs(num_steps=10000),
eval_args=trainer_pb2.EvalArgs(num_steps=5000))
context.run(trainer)
WARNING:absl:From <ipython-input-1-47ec22ebd3e4>:3: The name tfx.components.base.executor_spec.ExecutorClassSpec is deprecated. Please use tfx.dsl.components.base.executor_spec.ExecutorClassSpec instead. INFO:absl:Running driver for Trainer INFO:absl:MetadataStore with DB connection initialized INFO:absl:Running executor for Trainer INFO:absl:Train on the 'train' split when train_args.splits is not set. INFO:absl:Evaluate on the 'eval' split when eval_args.splits is not set. WARNING:absl:Examples artifact does not have payload_format custom property. Falling back to FORMAT_TF_EXAMPLE WARNING:absl:Examples artifact does not have payload_format custom property. Falling back to FORMAT_TF_EXAMPLE INFO:absl:Loading /tmpfs/src/temp/docs/tutorials/tfx/taxi_trainer.py because it has not been loaded before. INFO:absl:Training model. INFO:absl:Feature company_xf has a shape . Setting to DenseTensor. INFO:absl:Feature dropoff_census_tract_xf has a shape . Setting to DenseTensor. INFO:absl:Feature dropoff_community_area_xf has a shape . Setting to DenseTensor. INFO:absl:Feature dropoff_latitude_xf has a shape . Setting to DenseTensor. INFO:absl:Feature dropoff_longitude_xf has a shape . Setting to DenseTensor. INFO:absl:Feature fare_xf has a shape . Setting to DenseTensor. INFO:absl:Feature payment_type_xf has a shape . Setting to DenseTensor. INFO:absl:Feature pickup_census_tract_xf has a shape . Setting to DenseTensor. INFO:absl:Feature pickup_community_area_xf has a shape . Setting to DenseTensor. INFO:absl:Feature pickup_latitude_xf has a shape . Setting to DenseTensor. INFO:absl:Feature pickup_longitude_xf has a shape . Setting to DenseTensor. INFO:absl:Feature tips_xf has a shape . Setting to DenseTensor. INFO:absl:Feature trip_miles_xf has a shape . Setting to DenseTensor. INFO:absl:Feature trip_seconds_xf has a shape . Setting to DenseTensor. INFO:absl:Feature trip_start_day_xf has a shape . Setting to DenseTensor. INFO:absl:Feature trip_start_hour_xf has a shape . Setting to DenseTensor. INFO:absl:Feature trip_start_month_xf has a shape . Setting to DenseTensor. INFO:absl:Feature company_xf has a shape . Setting to DenseTensor. INFO:absl:Feature dropoff_census_tract_xf has a shape . Setting to DenseTensor. INFO:absl:Feature dropoff_community_area_xf has a shape . Setting to DenseTensor. INFO:absl:Feature dropoff_latitude_xf has a shape . Setting to DenseTensor. INFO:absl:Feature dropoff_longitude_xf has a shape . Setting to DenseTensor. INFO:absl:Feature fare_xf has a shape . Setting to DenseTensor. INFO:absl:Feature payment_type_xf has a shape . Setting to DenseTensor. INFO:absl:Feature pickup_census_tract_xf has a shape . Setting to DenseTensor. INFO:absl:Feature pickup_community_area_xf has a shape . Setting to DenseTensor. INFO:absl:Feature pickup_latitude_xf has a shape . Setting to DenseTensor. INFO:absl:Feature pickup_longitude_xf has a shape . Setting to DenseTensor. INFO:absl:Feature tips_xf has a shape . Setting to DenseTensor. INFO:absl:Feature trip_miles_xf has a shape . Setting to DenseTensor. INFO:absl:Feature trip_seconds_xf has a shape . Setting to DenseTensor. INFO:absl:Feature trip_start_day_xf has a shape . Setting to DenseTensor. INFO:absl:Feature trip_start_hour_xf has a shape . Setting to DenseTensor. INFO:absl:Feature trip_start_month_xf has a shape . Setting to DenseTensor. INFO:absl:Feature company_xf has a shape . Setting to DenseTensor. INFO:absl:Feature dropoff_census_tract_xf has a shape . Setting to DenseTensor. INFO:absl:Feature dropoff_community_area_xf has a shape . Setting to DenseTensor. INFO:absl:Feature dropoff_latitude_xf has a shape . Setting to DenseTensor. INFO:absl:Feature dropoff_longitude_xf has a shape . Setting to DenseTensor. INFO:absl:Feature fare_xf has a shape . Setting to DenseTensor. INFO:absl:Feature payment_type_xf has a shape . Setting to DenseTensor. INFO:absl:Feature pickup_census_tract_xf has a shape . Setting to DenseTensor. INFO:absl:Feature pickup_community_area_xf has a shape . Setting to DenseTensor. INFO:absl:Feature pickup_latitude_xf has a shape . Setting to DenseTensor. INFO:absl:Feature pickup_longitude_xf has a shape . Setting to DenseTensor. INFO:absl:Feature tips_xf has a shape . Setting to DenseTensor. INFO:absl:Feature trip_miles_xf has a shape . Setting to DenseTensor. INFO:absl:Feature trip_seconds_xf has a shape . Setting to DenseTensor. INFO:absl:Feature trip_start_day_xf has a shape . Setting to DenseTensor. INFO:absl:Feature trip_start_hour_xf has a shape . Setting to DenseTensor. INFO:absl:Feature trip_start_month_xf has a shape . Setting to DenseTensor. INFO:absl:Feature company_xf has a shape . Setting to DenseTensor. INFO:absl:Feature dropoff_census_tract_xf has a shape . Setting to DenseTensor. INFO:absl:Feature dropoff_community_area_xf has a shape . Setting to DenseTensor. INFO:absl:Feature dropoff_latitude_xf has a shape . Setting to DenseTensor. INFO:absl:Feature dropoff_longitude_xf has a shape . Setting to DenseTensor. INFO:absl:Feature fare_xf has a shape . Setting to DenseTensor. INFO:absl:Feature payment_type_xf has a shape . Setting to DenseTensor. INFO:absl:Feature pickup_census_tract_xf has a shape . Setting to DenseTensor. INFO:absl:Feature pickup_community_area_xf has a shape . Setting to DenseTensor. INFO:absl:Feature pickup_latitude_xf has a shape . Setting to DenseTensor. INFO:absl:Feature pickup_longitude_xf has a shape . Setting to DenseTensor. INFO:absl:Feature tips_xf has a shape . Setting to DenseTensor. INFO:absl:Feature trip_miles_xf has a shape . Setting to DenseTensor. INFO:absl:Feature trip_seconds_xf has a shape . Setting to DenseTensor. INFO:absl:Feature trip_start_day_xf has a shape . Setting to DenseTensor. INFO:absl:Feature trip_start_hour_xf has a shape . Setting to DenseTensor. INFO:absl:Feature trip_start_month_xf has a shape . Setting to DenseTensor. INFO:absl:Model: "functional_1" INFO:absl:__________________________________________________________________________________________________ INFO:absl:Layer (type) Output Shape Param # Connected to INFO:absl:================================================================================================== INFO:absl:company_xf (InputLayer) [(None,)] 0 INFO:absl:__________________________________________________________________________________________________ INFO:absl:dropoff_census_tract_xf (InputL [(None,)] 0 INFO:absl:__________________________________________________________________________________________________ INFO:absl:dropoff_community_area_xf (Inpu [(None,)] 0 INFO:absl:__________________________________________________________________________________________________ INFO:absl:dropoff_latitude_xf (InputLayer [(None,)] 0 INFO:absl:__________________________________________________________________________________________________ INFO:absl:dropoff_longitude_xf (InputLaye [(None,)] 0 INFO:absl:__________________________________________________________________________________________________ INFO:absl:fare_xf (InputLayer) [(None,)] 0 INFO:absl:__________________________________________________________________________________________________ INFO:absl:payment_type_xf (InputLayer) [(None,)] 0 INFO:absl:__________________________________________________________________________________________________ INFO:absl:pickup_census_tract_xf (InputLa [(None,)] 0 INFO:absl:__________________________________________________________________________________________________ INFO:absl:pickup_community_area_xf (Input [(None,)] 0 INFO:absl:__________________________________________________________________________________________________ INFO:absl:pickup_latitude_xf (InputLayer) [(None,)] 0 INFO:absl:__________________________________________________________________________________________________ INFO:absl:pickup_longitude_xf (InputLayer [(None,)] 0 INFO:absl:__________________________________________________________________________________________________ INFO:absl:trip_miles_xf (InputLayer) [(None,)] 0 INFO:absl:__________________________________________________________________________________________________ INFO:absl:trip_seconds_xf (InputLayer) [(None,)] 0 INFO:absl:__________________________________________________________________________________________________ INFO:absl:trip_start_day_xf (InputLayer) [(None,)] 0 INFO:absl:__________________________________________________________________________________________________ INFO:absl:trip_start_hour_xf (InputLayer) [(None,)] 0 INFO:absl:__________________________________________________________________________________________________ INFO:absl:trip_start_month_xf (InputLayer [(None,)] 0 INFO:absl:__________________________________________________________________________________________________ INFO:absl:dense_features (DenseFeatures) (None, 3) 0 company_xf[0][0] INFO:absl: dropoff_census_tract_xf[0][0] INFO:absl: dropoff_community_area_xf[0][0] INFO:absl: dropoff_latitude_xf[0][0] INFO:absl: dropoff_longitude_xf[0][0] INFO:absl: fare_xf[0][0] INFO:absl: payment_type_xf[0][0] INFO:absl: pickup_census_tract_xf[0][0] INFO:absl: pickup_community_area_xf[0][0] INFO:absl: pickup_latitude_xf[0][0] INFO:absl: pickup_longitude_xf[0][0] INFO:absl: trip_miles_xf[0][0] INFO:absl: trip_seconds_xf[0][0] INFO:absl: trip_start_day_xf[0][0] INFO:absl: trip_start_hour_xf[0][0] INFO:absl: trip_start_month_xf[0][0] INFO:absl:__________________________________________________________________________________________________ INFO:absl:dense (Dense) (None, 100) 400 dense_features[0][0] INFO:absl:__________________________________________________________________________________________________ INFO:absl:dense_1 (Dense) (None, 70) 7070 dense[0][0] INFO:absl:__________________________________________________________________________________________________ INFO:absl:dense_2 (Dense) (None, 48) 3408 dense_1[0][0] INFO:absl:__________________________________________________________________________________________________ INFO:absl:dense_3 (Dense) (None, 34) 1666 dense_2[0][0] INFO:absl:__________________________________________________________________________________________________ INFO:absl:dense_features_1 (DenseFeatures (None, 2127) 0 company_xf[0][0] INFO:absl: dropoff_census_tract_xf[0][0] INFO:absl: dropoff_community_area_xf[0][0] INFO:absl: dropoff_latitude_xf[0][0] INFO:absl: dropoff_longitude_xf[0][0] INFO:absl: fare_xf[0][0] INFO:absl: payment_type_xf[0][0] INFO:absl: pickup_census_tract_xf[0][0] INFO:absl: pickup_community_area_xf[0][0] INFO:absl: pickup_latitude_xf[0][0] INFO:absl: pickup_longitude_xf[0][0] INFO:absl: trip_miles_xf[0][0] INFO:absl: trip_seconds_xf[0][0] INFO:absl: trip_start_day_xf[0][0] INFO:absl: trip_start_hour_xf[0][0] INFO:absl: trip_start_month_xf[0][0] INFO:absl:__________________________________________________________________________________________________ INFO:absl:concatenate (Concatenate) (None, 2161) 0 dense_3[0][0] INFO:absl: dense_features_1[0][0] INFO:absl:__________________________________________________________________________________________________ INFO:absl:dense_4 (Dense) (None, 1) 2162 concatenate[0][0] INFO:absl:================================================================================================== INFO:absl:Total params: 14,706 INFO:absl:Trainable params: 14,706 INFO:absl:Non-trainable params: 0 INFO:absl:__________________________________________________________________________________________________ 1/10000 [..............................] - ETA: 1s - loss: 0.7103 - binary_accuracy: 0.3500WARNING:tensorflow:From /tmpfs/src/tf_docs_env/lib/python3.6/site-packages/tensorflow/python/ops/summary_ops_v2.py:1277: stop (from tensorflow.python.eager.profiler) is deprecated and will be removed after 2020-07-01. Instructions for updating: use `tf.profiler.experimental.stop` instead. WARNING:tensorflow:Callbacks method `on_train_batch_end` is slow compared to the batch time (batch time: 0.0033s vs `on_train_batch_end` time: 0.0146s). Check your callbacks. 10000/10000 [==============================] - 34s 3ms/step - loss: 0.2396 - binary_accuracy: 0.8808 - val_loss: 0.2216 - val_binary_accuracy: 0.8824 INFO:tensorflow:Saver not created because there are no variables in the graph to restore WARNING:tensorflow:From /tmpfs/src/tf_docs_env/lib/python3.6/site-packages/tensorflow/python/training/tracking/tracking.py:111: Model.state_updates (from tensorflow.python.keras.engine.training) is deprecated and will be removed in a future version. Instructions for updating: This property should not be used in TensorFlow 2.0, as updates are applied automatically. WARNING:tensorflow:From /tmpfs/src/tf_docs_env/lib/python3.6/site-packages/tensorflow/python/training/tracking/tracking.py:111: Layer.updates (from tensorflow.python.keras.engine.base_layer) is deprecated and will be removed in a future version. Instructions for updating: This property should not be used in TensorFlow 2.0, as updates are applied automatically. INFO:tensorflow:Assets written to: /tmp/tfx-interactive-2021-02-01T10_16_29.340076-cd248luc/Trainer/model/6/serving_model_dir/assets INFO:absl:Training complete. Model written to /tmp/tfx-interactive-2021-02-01T10_16_29.340076-cd248luc/Trainer/model/6/serving_model_dir. ModelRun written to /tmp/tfx-interactive-2021-02-01T10_16_29.340076-cd248luc/Trainer/model_run/6 INFO:absl:Running publisher for Trainer INFO:absl:MetadataStore with DB connection initialized
টেনসরবোর্ড দিয়ে প্রশিক্ষণ বিশ্লেষণ করুন
প্রশিক্ষক নিদর্শন তাকান। এটি মডেল সাব-ডিরেক্টরি অন্তর্ভুক্ত একটি ডিরেক্টরিতে নির্দেশ করে।
model_artifact_dir = trainer.outputs['model'].get()[0].uri
pp.pprint(os.listdir(model_artifact_dir))
model_dir = os.path.join(model_artifact_dir, 'serving_model_dir')
pp.pprint(os.listdir(model_dir))
['serving_model_dir'] ['variables', 'assets', 'saved_model.pb']
Allyচ্ছিকভাবে, আমরা আমাদের মডেলটির প্রশিক্ষণ কার্ভগুলি বিশ্লেষণ করতে ট্রেনারের সাথে টেনসরবোর্ড সংযোগ করতে পারি।
model_run_artifact_dir = trainer.outputs['model_run'].get()[0].uri
%load_ext tensorboard
%tensorboard --logdir {model_run_artifact_dir}
মূল্যায়নকারী
Evaluator
উপাদান মূল্যায়ন সেট উপর মডেল কর্মক্ষমতা বৈশিষ্ট্যের মান নির্ণয় করে। এটি টেনসরফ্লো মডেল বিশ্লেষণ গ্রন্থাগার ব্যবহার করে। Evaluator
বৈকল্পিকভাবে যাচাই করতে পারে যে একটি নতুন প্রশিক্ষিত মডেল আগের মডেলের চেয়ে ভাল। এটি এমন একটি উত্পাদন পাইপলাইন সেটিংয়ে দরকারী যেখানে আপনি প্রতিদিন কোনও মডেলকে স্বয়ংক্রিয়ভাবে প্রশিক্ষণ ও বৈধতা দিতে পারেন। এই নোটবুকে, আমরা কেবল একটি মডেলকে প্রশিক্ষণ দিই, সুতরাং Evaluator
স্বয়ংক্রিয়ভাবে মডেলটিকে "ভাল" হিসাবে লেবেল করবে।
Evaluator
থেকে ডেটা ইনপুট হিসাবে নিতে হবে ExampleGen
থেকে প্রশিক্ষিত মডেল Trainer
, এবং slicing কনফিগারেশন। স্লাইসিং কনফিগারেশন আপনাকে বৈশিষ্ট্যগুলির মানগুলিতে আপনার ম্যাট্রিকগুলি টুকরো টুকরো করতে দেয় (উদাহরণস্বরূপ, আপনার মডেলটি ট্যাক্সি ভ্রমণের সময় কীভাবে সকাল ৮ টা থেকে রাত ৮ টার দিকে শুরু হয়?)। নীচে এই কনফিগারেশনের একটি উদাহরণ দেখুন:
eval_config = tfma.EvalConfig(
model_specs=[
# This assumes a serving model with signature 'serving_default'. If
# using estimator based EvalSavedModel, add signature_name: 'eval' and
# remove the label_key.
tfma.ModelSpec(label_key='tips')
],
metrics_specs=[
tfma.MetricsSpec(
# The metrics added here are in addition to those saved with the
# model (assuming either a keras model or EvalSavedModel is used).
# Any metrics added into the saved model (for example using
# model.compile(..., metrics=[...]), etc) will be computed
# automatically.
# To add validation thresholds for metrics saved with the model,
# add them keyed by metric name to the thresholds map.
metrics=[
tfma.MetricConfig(class_name='ExampleCount'),
tfma.MetricConfig(class_name='BinaryAccuracy',
threshold=tfma.MetricThreshold(
value_threshold=tfma.GenericValueThreshold(
lower_bound={'value': 0.5}),
change_threshold=tfma.GenericChangeThreshold(
direction=tfma.MetricDirection.HIGHER_IS_BETTER,
absolute={'value': -1e-10})))
]
)
],
slicing_specs=[
# An empty slice spec means the overall slice, i.e. the whole dataset.
tfma.SlicingSpec(),
# Data can be sliced along a feature column. In this case, data is
# sliced along feature column trip_start_hour.
tfma.SlicingSpec(feature_keys=['trip_start_hour'])
])
এরপরে, আমরা এই কনফিগারেশনটি Evaluator
দেব এবং এটি চালাব।
# Use TFMA to compute a evaluation statistics over features of a model and
# validate them against a baseline.
# The model resolver is only required if performing model validation in addition
# to evaluation. In this case we validate against the latest blessed model. If
# no model has been blessed before (as in this case) the evaluator will make our
# candidate the first blessed model.
model_resolver = ResolverNode(
instance_name='latest_blessed_model_resolver',
resolver_class=latest_blessed_model_resolver.LatestBlessedModelResolver,
model=Channel(type=Model),
model_blessing=Channel(type=ModelBlessing))
context.run(model_resolver)
evaluator = Evaluator(
examples=example_gen.outputs['examples'],
model=trainer.outputs['model'],
baseline_model=model_resolver.outputs['model'],
# Change threshold will be ignored if there is no baseline (first run).
eval_config=eval_config)
context.run(evaluator)
WARNING:absl:`instance_name` is deprecated, please set the node id directly using `with_id()` or the `.id` setter. INFO:absl:Running driver for ResolverNode.latest_blessed_model_resolver INFO:absl:MetadataStore with DB connection initialized INFO:absl:Running publisher for ResolverNode.latest_blessed_model_resolver INFO:absl:MetadataStore with DB connection initialized INFO:absl:Running driver for Evaluator INFO:absl:MetadataStore with DB connection initialized INFO:absl:Running executor for Evaluator ERROR:absl:There are change thresholds, but the baseline is missing. This is allowed only when rubber stamping (first run). WARNING:absl:"maybe_add_baseline" and "maybe_remove_baseline" are deprecated, please use "has_baseline" instead. INFO:absl:Request was made to ignore the baseline ModelSpec and any change thresholds. This is likely because a baseline model was not provided: updated_config= model_specs { label_key: "tips" } slicing_specs { } slicing_specs { feature_keys: "trip_start_hour" } metrics_specs { metrics { class_name: "ExampleCount" } metrics { class_name: "BinaryAccuracy" threshold { value_threshold { lower_bound { value: 0.5 } } } } } INFO:absl:Using /tmp/tfx-interactive-2021-02-01T10_16_29.340076-cd248luc/Trainer/model/6/serving_model_dir as model. INFO:absl:The 'example_splits' parameter is not set, using 'eval' split. INFO:absl:Evaluating model. INFO:absl:Request was made to ignore the baseline ModelSpec and any change thresholds. This is likely because a baseline model was not provided: updated_config= model_specs { label_key: "tips" } slicing_specs { } slicing_specs { feature_keys: "trip_start_hour" } metrics_specs { metrics { class_name: "ExampleCount" } metrics { class_name: "BinaryAccuracy" threshold { value_threshold { lower_bound { value: 0.5 } } } } model_names: "" } INFO:absl:Request was made to ignore the baseline ModelSpec and any change thresholds. This is likely because a baseline model was not provided: updated_config= model_specs { label_key: "tips" } slicing_specs { } slicing_specs { feature_keys: "trip_start_hour" } metrics_specs { metrics { class_name: "ExampleCount" } metrics { class_name: "BinaryAccuracy" threshold { value_threshold { lower_bound { value: 0.5 } } } } model_names: "" } INFO:absl:Request was made to ignore the baseline ModelSpec and any change thresholds. This is likely because a baseline model was not provided: updated_config= model_specs { label_key: "tips" } slicing_specs { } slicing_specs { feature_keys: "trip_start_hour" } metrics_specs { metrics { class_name: "ExampleCount" } metrics { class_name: "BinaryAccuracy" threshold { value_threshold { lower_bound { value: 0.5 } } } } model_names: "" } WARNING:tensorflow:5 out of the last 5 calls to <function recreate_function.<locals>.restored_function_body at 0x7f59f879c1e0> triggered tf.function retracing. Tracing is expensive and the excessive number of tracings could be due to (1) creating @tf.function repeatedly in a loop, (2) passing tensors with different shapes, (3) passing Python objects instead of tensors. For (1), please define your @tf.function outside of the loop. For (2), @tf.function has experimental_relax_shapes=True option that relaxes argument shapes that can avoid unnecessary retracing. For (3), please refer to https://www.tensorflow.org/tutorials/customization/performance#python_or_tensor_args and https://www.tensorflow.org/api_docs/python/tf/function for more details. INFO:absl:Evaluation complete. Results written to /tmp/tfx-interactive-2021-02-01T10_16_29.340076-cd248luc/Evaluator/evaluation/8. INFO:absl:Checking validation results. INFO:absl:Blessing result True written to /tmp/tfx-interactive-2021-02-01T10_16_29.340076-cd248luc/Evaluator/blessing/8. INFO:absl:Running publisher for Evaluator INFO:absl:MetadataStore with DB connection initialized
এখন আসুন Evaluator
আউটপুট শিল্পকর্মগুলি পরীক্ষা করি।
evaluator.outputs
{'evaluation': Channel( type_name: ModelEvaluation artifacts: [Artifact(artifact: id: 10 type_id: 20 uri: "/tmp/tfx-interactive-2021-02-01T10_16_29.340076-cd248luc/Evaluator/evaluation/8" custom_properties { key: "name" value { string_value: "evaluation" } } custom_properties { key: "producer_component" value { string_value: "Evaluator" } } custom_properties { key: "state" value { string_value: "published" } } state: LIVE , artifact_type: id: 20 name: "ModelEvaluation" )] ), 'blessing': Channel( type_name: ModelBlessing artifacts: [Artifact(artifact: id: 11 type_id: 21 uri: "/tmp/tfx-interactive-2021-02-01T10_16_29.340076-cd248luc/Evaluator/blessing/8" custom_properties { key: "blessed" value { int_value: 1 } } custom_properties { key: "current_model" value { string_value: "/tmp/tfx-interactive-2021-02-01T10_16_29.340076-cd248luc/Trainer/model/6" } } custom_properties { key: "current_model_id" value { int_value: 8 } } custom_properties { key: "name" value { string_value: "blessing" } } custom_properties { key: "producer_component" value { string_value: "Evaluator" } } custom_properties { key: "state" value { string_value: "published" } } state: LIVE , artifact_type: id: 21 name: "ModelBlessing" )] )}
evaluation
আউটপুট ব্যবহার করে আমরা পুরো মূল্যায়ন সেটটিতে গ্লোবাল মেট্রিকগুলির ডিফল্ট ভিজ্যুয়ালাইজেশন প্রদর্শন করতে পারি।
context.show(evaluator.outputs['evaluation'])
কাটা মূল্যায়ন মেট্রিকগুলির জন্য দৃশ্য দেখতে, আমরা সরাসরি টেনসরফ্লো মডেল বিশ্লেষণ লাইব্রেরি কল করতে পারি।
import tensorflow_model_analysis as tfma
# Get the TFMA output result path and load the result.
PATH_TO_RESULT = evaluator.outputs['evaluation'].get()[0].uri
tfma_result = tfma.load_eval_result(PATH_TO_RESULT)
# Show data sliced along feature column trip_start_hour.
tfma.view.render_slicing_metrics(
tfma_result, slicing_column='trip_start_hour')
SlicingMetricsViewer(config={'weightedExamplesColumn': 'example_count'}, data=[{'slice': 'trip_start_hour:19',…
এই ভিজ্যুয়ালাইজেশন একই ম্যাট্রিকগুলি দেখায়, তবে সম্পূর্ণ মূল্যায়ন সেটের পরিবর্তে trip_start_hour
প্রতিটি বৈশিষ্ট্যের trip_start_hour
গণনা করা হয়।
টেনসরফ্লো মডেল অ্যানালাইসিস আরও অনেকগুলি ভিজ্যুয়ালাইজেশনকে সমর্থন করে, যেমন ফেয়ারনেস ইন্ডিকেটর এবং মডেল পারফরম্যান্সের একটি সময়ের সিরিজ প্লট করা। আরও জানতে, টিউটোরিয়াল দেখুন ।
যেহেতু আমরা আমাদের কনফিগারেশনে থ্রেশহোল্ডগুলি যুক্ত করেছি, বৈধতা আউটপুটও উপলব্ধ। blessing
শিল্পের নজির ইঙ্গিত দেয় যে আমাদের মডেলটি বৈধতা দিয়েছিল। যেহেতু এটি প্রথম বৈধতা সম্পাদন করা হচ্ছে প্রার্থী স্বয়ংক্রিয়ভাবে আশীর্বাদপ্রাপ্ত।
blessing_uri = evaluator.outputs.blessing.get()[0].uri
!ls -l {blessing_uri}
total 0 -rw-rw-r-- 1 kbuilder kbuilder 0 Feb 1 10:17 BLESSED
বৈধতা রেকর্ড রেকর্ড লোড করে এখন সাফল্য যাচাই করতে পারে:
PATH_TO_RESULT = evaluator.outputs['evaluation'].get()[0].uri
print(tfma.load_validation_result(PATH_TO_RESULT))
validation_ok: true validation_details { slicing_details { slicing_spec { } num_matching_slices: 25 } }
পুশার
Pusher
উপাদানটি সাধারণত একটি টিএফএক্স পাইপলাইন শেষে থাকে। এটি কোনও মডেল বৈধতা পাস করেছে কিনা তা পরীক্ষা করে এবং যদি তাই হয়, তবে এই মডেলটিকে _serving_model_dir
রফতানি করে।
pusher = Pusher(
model=trainer.outputs['model'],
model_blessing=evaluator.outputs['blessing'],
push_destination=pusher_pb2.PushDestination(
filesystem=pusher_pb2.PushDestination.Filesystem(
base_directory=_serving_model_dir)))
context.run(pusher)
INFO:absl:Running driver for Pusher INFO:absl:MetadataStore with DB connection initialized INFO:absl:Running executor for Pusher INFO:absl:Model version: 1612174674 INFO:absl:Model written to serving path /tmp/tmpmg3nskc7/serving_model/taxi_simple/1612174674. INFO:absl:Model pushed to /tmp/tfx-interactive-2021-02-01T10_16_29.340076-cd248luc/Pusher/pushed_model/9. INFO:absl:Running publisher for Pusher INFO:absl:MetadataStore with DB connection initialized
আসুন Pusher
আউটপুট শিল্পকর্মগুলি পরীক্ষা করি।
pusher.outputs
{'pushed_model': Channel( type_name: PushedModel artifacts: [Artifact(artifact: id: 12 type_id: 23 uri: "/tmp/tfx-interactive-2021-02-01T10_16_29.340076-cd248luc/Pusher/pushed_model/9" custom_properties { key: "name" value { string_value: "pushed_model" } } custom_properties { key: "producer_component" value { string_value: "Pusher" } } custom_properties { key: "pushed" value { int_value: 1 } } custom_properties { key: "pushed_destination" value { string_value: "/tmp/tmpmg3nskc7/serving_model/taxi_simple/1612174674" } } custom_properties { key: "pushed_version" value { string_value: "1612174674" } } custom_properties { key: "state" value { string_value: "published" } } state: LIVE , artifact_type: id: 23 name: "PushedModel" )] )}
বিশেষত, পুশার আপনার মডেলকে সেভডমডেল ফর্ম্যাটে রফতানি করবে, যা দেখতে এটির মতো দেখাচ্ছে:
push_uri = pusher.outputs.model_push.get()[0].uri
model = tf.saved_model.load(push_uri)
for item in model.signatures.items():
pp.pprint(item)
WARNING:tensorflow:6 out of the last 6 calls to <function recreate_function.<locals>.restored_function_body at 0x7f5989b94ea0> triggered tf.function retracing. Tracing is expensive and the excessive number of tracings could be due to (1) creating @tf.function repeatedly in a loop, (2) passing tensors with different shapes, (3) passing Python objects instead of tensors. For (1), please define your @tf.function outside of the loop. For (2), @tf.function has experimental_relax_shapes=True option that relaxes argument shapes that can avoid unnecessary retracing. For (3), please refer to https://www.tensorflow.org/tutorials/customization/performance#python_or_tensor_args and https://www.tensorflow.org/api_docs/python/tf/function for more details. ('serving_default', <ConcreteFunction signature_wrapper(examples) at 0x7F59A0197D68>)
আমরা আমাদের অন্তর্নির্মিত টিএফএক্স উপাদানগুলির ট্যুরটি শেষ করেছি!