#TFX 장점:
파이프라인을 실행하기 위해 코드 작성이 필요 없다(예외: feature engineering, modeling)
파이프라인을 위한 components가 모두 미리 구현 되어있다.
Components 설명
TFX 파이프라인의 10가지 components들의 기능을 설명하고자 한다.

ExampleGen: 데이터를 TFX 파이프라인의 component가 읽을 수 있도록 변환해준다.
StatisticsGen: 데이터셋의 통계 분석
SchemaGen: 데이터 셋의 통계를 통해 스키마 자동 생성 (추후에 사용자가 수정)
ExampleValidator: 새로운 데이터가 들어왔을 때 StatisticsGen의 결과를 이용하여 데이터 검증(이상치, skewness, 등 파악) How?: 아직은 잘모르겠다.
Transform: feature engineering 과정, tf.Example의 feature들을 사용자가 정의한 대로 변환한다.
Tuner: Hyperparameter tuning을 해준다. How?: 아직은 잘모르겠다.
Trainer: 모델을 학습시켜준다.
Evaluator: baseline 모델과 현재 모델을 비교해서 어떤 모델이 더 좋은지 판단한다.
InfraValidator: production 환경에 push 하기 전 early warning layer이다. 모델이 잘 동작 하는지와 bad model이 push 되는 것을 방지한다. How?: 아직은 잘모르겠다.
Pusher: 검증된 모델을 push.
#Wide and Deep model + movielens dataset
변경한 components 2가지 뿐.
1. Transform component
-> feature engineering 수정
2. Trainer component
-> model architecture 수정

**Template의 구조만 잘 이해한다면, 기존 모델에 맞게 코드 수정을 손쉽게 할 수 있다.
#Appendix
실제 Tutorial의 Input/Output 설명
Tutorial는 local_runner.py를 실행시키면 된다.
local_runner,py 실행하면 아래 그림과 같이 폴더 생성 및 결과 저장이 된다.

Tree 구조
CsvExampleGen:
data_tfrecord-00000-of-00001.gz 파일 열기.
import tensorflow as tf
raw_dataset = tf.data.TFRecordDataset('data_tfrecord-00000-of-00001')
for raw_record in raw_dataset.take(1):
example = tf.train.Example()
example.ParseFromString(raw_record.numpy())
print(example)
features {
feature {
key: "age"
value {
int64_list {
value: 49
}
}
}
feature {
key: "gender"
value {
int64_list {
value: 1
}
}
}
feature {
key: "genre"
value {
int64_list {
value: 119
}
}
}
feature {
key: "itemId"
value {
int64_list {
value: 242
}
}
}
feature {
key: "movieTitle"
value {
int64_list {
value: 823
}
}
}...
....
StatisticsGen
FeatureStats.pb 파일 열기
visualize.ipynb
import tensorflow_data_validation as tfdv
stats = tfdv.load_stats_binary('./FeatureStats.pb')
tfdv.visualize_statistics(stats)
#SchemaGen
schema.pbtxt
추후 사람이 수정해야 함.
feature {
name: "age"
type: INT
presence {
min_fraction: 1.0
min_count: 1
}
shape {
dim {
size: 1
}
}
}
feature {
name: "gender"
type: INT
bool_domain {
}
presence {
min_fraction: 1.0
min_count: 1
}
shape {
dim {
size: 1
}
}
}
feature {
name: "genre"
type: INT
presence {
min_fraction: 1.0
min_count: 1
}
shape {
dim {
size: 1
}
}
}
feature {
name: "itemId"
type: INT
presence {
min_fraction: 1.0
min_count: 1
}
shape {
dim {
size: 1
}
}
}
feature {
name: "movieTitle"
type: INT
presence {
min_fraction: 1.0
min_count: 1
}
shape {
dim {
size: 1
}
}
}
feature {
name: "occupation"
type: INT
presence {
min_fraction: 1.0
min_count: 1
}
shape {
dim {
size: 1
}
}
}
feature {
name: "rating"
type: INT
bool_domain {
}
presence {
min_fraction: 1.0
min_count: 1
}
shape {
dim {
size: 1
}
}
}
feature {
name: "releaseDay"
type: INT
presence {
min_fraction: 1.0
min_count: 1
}
shape {
dim {
size: 1
}
}
}
feature {
name: "releaseMonth"
type: INT
presence {
min_fraction: 1.0
min_count: 1
}
shape {
dim {
size: 1
}
}
}
feature {
name: "releaseYear"
type: INT
presence {
min_fraction: 1.0
min_count: 1
}
shape {
dim {
size: 1
}
}
}
feature {
name: "userId"
type: INT
presence {
min_fraction: 1.0
min_count: 1
}
shape {
dim {
size: 1
}
}
}
feature {
name: "zipCode"
type: INT
presence {
min_fraction: 1.0
min_count: 1
}
shape {
dim {
size: 1
}
}
}
#Trainer
출처:
'MLOps' 카테고리의 다른 글
TFX + airflow 연동 (0) | 2022.07.27 |
---|---|
tf.Example과 TFRecord (0) | 2022.07.27 |
TFX ML Metadata (0) | 2022.05.03 |
Protocol Buffers, Protobuf (0) | 2022.04.28 |
TFX Guide Local pipeline example (0) | 2022.04.25 |