ধারক-ভিত্তিক উপাদান নির্মাণ
সেভ করা পৃষ্ঠা গুছিয়ে রাখতে 'সংগ্রহ' ব্যবহার করুন
আপনার পছন্দ অনুযায়ী কন্টেন্ট সেভ করুন ও সঠিক বিভাগে রাখুন।
কন্টেইনার-ভিত্তিক উপাদানগুলি আপনার পাইপলাইনে যেকোন ভাষায় লিখিত কোড সংহত করার নমনীয়তা প্রদান করে, যতক্ষণ না আপনি একটি ডকার কন্টেইনারে সেই কোডটি কার্যকর করতে পারেন।
আপনি যদি TFX পাইপলাইনে নতুন হন, তাহলে TFX পাইপলাইনের মূল ধারণা সম্পর্কে আরও জানুন ।
একটি ধারক-ভিত্তিক উপাদান তৈরি করা
কন্টেইনার-ভিত্তিক উপাদানগুলি কন্টেইনারাইজড কমান্ড-লাইন প্রোগ্রাম দ্বারা সমর্থিত। আপনার যদি ইতিমধ্যে একটি কন্টেইনার ইমেজ থাকে, তাহলে আপনি ইনপুট এবং আউটপুট ঘোষণা করতে create_container_component
ফাংশন ব্যবহার করে এটি থেকে একটি উপাদান তৈরি করতে TFX ব্যবহার করতে পারেন। ফাংশন পরামিতি:
- নাম: উপাদানটির নাম।
- ইনপুটস: একটি অভিধান যা ইনপুট নামগুলিকে প্রকারের সাথে মানচিত্র করে। আউটপুট: একটি অভিধান যা আউটপুট নামগুলিকে প্রকারের প্যারামিটারে ম্যাপ করে: একটি অভিধান যা প্যারামিটারের নামগুলি প্রকারের সাথে মানচিত্র করে।
- ছবি: ধারক ছবির নাম, এবং ঐচ্ছিকভাবে ছবি ট্যাগ।
- কমান্ড: কন্টেইনার এন্ট্রিপয়েন্ট কমান্ড লাইন। একটি শেল মধ্যে মৃত্যুদন্ড কার্যকর করা হয় না. কমান্ড লাইন প্লেসহোল্ডার অবজেক্ট ব্যবহার করতে পারে যা সংকলনের সময় ইনপুট, আউটপুট বা প্যারামিটার দিয়ে প্রতিস্থাপিত হয়। স্থানধারক বস্তুগুলি
tfx.dsl.component.experimental.placeholders
থেকে আমদানি করা যেতে পারে। মনে রাখবেন যে জিনজা টেমপ্লেট সমর্থিত নয়।
রিটার্ন মান: একটি কম্পোনেন্ট ক্লাস বেস_কম্পোনেন্ট থেকে উত্তরাধিকারসূত্রে পাওয়া যায়।
স্থানধারক
ইনপুট বা আউটপুট আছে এমন একটি উপাদানের জন্য, command
প্রায়ই প্লেসহোল্ডার থাকা প্রয়োজন যা রানটাইমে প্রকৃত ডেটা দিয়ে প্রতিস্থাপিত হয়। এই উদ্দেশ্যে বেশ কয়েকটি স্থানধারক প্রদান করা হয়েছে:
InputValuePlaceholder
: ইনপুট আর্টিফ্যাক্টের মানের জন্য একটি স্থানধারক। রানটাইমে, এই স্থানধারকটি আর্টিফ্যাক্টের মানের স্ট্রিং উপস্থাপনা দিয়ে প্রতিস্থাপিত হয়।
InputUriPlaceholder
: ইনপুট আর্টিফ্যাক্ট আর্গুমেন্টের URI-এর জন্য একটি স্থানধারক। রানটাইমে, এই স্থানধারকটি ইনপুট আর্টিফ্যাক্টের ডেটার URI দিয়ে প্রতিস্থাপিত হয়।
OutputUriPlaceholder
: আউটপুট আর্টিফ্যাক্ট আর্গুমেন্টের URI-এর জন্য একটি স্থানধারক। রানটাইমে, এই স্থানধারকটিকে URI দিয়ে প্রতিস্থাপিত করা হয় যেখানে উপাদানটিকে আউটপুট আর্টিফ্যাক্টের ডেটা সংরক্ষণ করা উচিত।
TFX কম্পোনেন্ট কমান্ড-লাইন স্থানধারক সম্পর্কে আরও জানুন।
উদাহরণ ধারক-ভিত্তিক উপাদান
নিম্নলিখিত একটি নন-পাইথন উপাদানের একটি উদাহরণ যা ডেটা ডাউনলোড, রূপান্তর এবং আপলোড করে:
import tfx.v1 as tfx
grep_component = tfx.dsl.components.create_container_component(
name='FilterWithGrep',
inputs={
'text': tfx.standard_artifacts.ExternalArtifact,
},
outputs={
'filtered_text': tfx.standard_artifacts.ExternalArtifact,
},
parameters={
'pattern': str,
},
# The component code uses gsutil to upload the data to Google Cloud Storage, so the
# container image needs to have gsutil installed and configured.
image='google/cloud-sdk:278.0.0',
command=[
'sh', '-exc',
'''
pattern="$1"
text_uri="$3"/data # Adding suffix, because currently the URI are "directories". This will be fixed soon.
text_path=$(mktemp)
filtered_text_uri="$5"/data # Adding suffix, because currently the URI are "directories". This will be fixed soon.
filtered_text_path=$(mktemp)
# Getting data into the container
gsutil cp "$text_uri" "$text_path"
# Running the main code
grep "$pattern" "$text_path" >"$filtered_text_path"
# Getting data out of the container
gsutil cp "$filtered_text_path" "$filtered_text_uri"
''',
'--pattern', tfx.dsl.placeholders.InputValuePlaceholder('pattern'),
'--text', tfx.dsl.placeholders.InputUriPlaceholder('text'),
'--filtered-text', tfx.dsl.placeholders.OutputUriPlaceholder('filtered_text'),
],
)
অন্য কিছু উল্লেখ না করা থাকলে, এই পৃষ্ঠার কন্টেন্ট Creative Commons Attribution 4.0 License-এর অধীনে এবং কোডের নমুনাগুলি Apache 2.0 License-এর অধীনে লাইসেন্স প্রাপ্ত। আরও জানতে, Google Developers সাইট নীতি দেখুন। Java হল Oracle এবং/অথবা তার অ্যাফিলিয়েট সংস্থার রেজিস্টার্ড ট্রেডমার্ক।
2025-07-25 UTC-তে শেষবার আপডেট করা হয়েছে।
[null,null,["2025-07-25 UTC-তে শেষবার আপডেট করা হয়েছে।"],[],[],null,["# Building Container-based components\n\nContainer-based components provide the flexibility to integrate code written in\nany language into your pipeline, so long as you can execute that code in a\nDocker container.\n\nIf you are new to TFX pipelines,\n[learn more about the core concepts of TFX pipelines](/tfx/guide/understanding_tfx_pipelines).\n\nCreating a Container-based Component\n------------------------------------\n\nContainer-based components are backed by containerized command-line programs. If\nyou already have a container image, you can use TFX to create a component from\nit by using the\n[`create_container_component` function](https://github.com/tensorflow/tfx/blob/master/tfx/dsl/component/experimental/container_component.py)\nto declare inputs and outputs. Function parameters:\n\n- **name:** The name of the component.\n- **inputs:** A dictionary that maps input names to types. outputs: A dictionary that maps output names to types parameters: A dictionary that maps parameter names to types.\n- **image:** Container image name, and optionally image tag.\n- **command:** Container entrypoint command line. Not executed within a shell. The command line can use placeholder objects that are replaced at compilation time with the input, output, or parameter. The placeholder objects can be imported from [`tfx.dsl.component.experimental.placeholders`](https://github.com/tensorflow/tfx/blob/master/tfx/dsl/component/experimental/placeholders.py). Note that Jinja templates are not supported.\n\n**Return value:** a Component class inheriting from base_component.BaseComponent\nwhich can be instantiated and used inside the pipeline.\n\n### Placeholders\n\nFor a component that has inputs or outputs, the `command` often needs to have\nplaceholders that are replaced with actual data at runtime. Several placeholders\nare provided for this purpose:\n\n- `InputValuePlaceholder`: A placeholder for the value of the input artifact.\n At runtime, this placeholder is replaced with the string representation of\n the artifact's value.\n\n- `InputUriPlaceholder`: A placeholder for the URI of the input artifact\n argument. At runtime, this placeholder is replaced with the URI of the input\n artifact's data.\n\n- `OutputUriPlaceholder`: A placeholder for the URI of the output artifact\n argument. At runtime, this placeholder is replaced with the URI where the\n component should store the output artifact's data.\n\nLearn more about\n[TFX component command-line placeholders](https://github.com/tensorflow/tfx/blob/master/tfx/dsl/component/experimental/placeholders.py).\n\n### Example Container-based Component\n\nThe following is an example of a non-python component that downloads,\ntransforms, and uploads the data: \n\n import tfx.v1 as tfx\n\n grep_component = tfx.dsl.components.create_container_component(\n name='FilterWithGrep',\n inputs={\n 'text': tfx.standard_artifacts.ExternalArtifact,\n },\n outputs={\n 'filtered_text': tfx.standard_artifacts.ExternalArtifact,\n },\n parameters={\n 'pattern': str,\n },\n # The component code uses gsutil to upload the data to Google Cloud Storage, so the\n # container image needs to have gsutil installed and configured.\n image='google/cloud-sdk:278.0.0',\n command=[\n 'sh', '-exc',\n '''\n pattern=\"$1\"\n text_uri=\"$3\"/data # Adding suffix, because currently the URI are \"directories\". This will be fixed soon.\n text_path=$(mktemp)\n filtered_text_uri=\"$5\"/data # Adding suffix, because currently the URI are \"directories\". This will be fixed soon.\n filtered_text_path=$(mktemp)\n\n # Getting data into the container\n gsutil cp \"$text_uri\" \"$text_path\"\n\n # Running the main code\n grep \"$pattern\" \"$text_path\" \u003e\"$filtered_text_path\"\n\n # Getting data out of the container\n gsutil cp \"$filtered_text_path\" \"$filtered_text_uri\"\n ''',\n '--pattern', tfx.dsl.placeholders.InputValuePlaceholder('pattern'),\n '--text', tfx.dsl.placeholders.InputUriPlaceholder('text'),\n '--filtered-text', tfx.dsl.placeholders.OutputUriPlaceholder('filtered_text'),\n ],\n )"]]