njs03332 / ml_study

3 stars 0 forks source link

2023/04/27 ~ 2023/05/11 #67

Open givitallugot opened 1 year ago

givitallugot commented 1 year ago

~05/08 월 10:10~ 05/11 목 9:30

givitallugot commented 1 year ago

assign roles -s 0427 -c 13.3.3 13.4 13.5

njs03332 commented 1 year ago
0 1 2
member 한단비 주선미 김유리
chapter 13.3.3 13.4 13.5
njs03332 commented 1 year ago

13.5 텐서플로 데이터셋 (TFDS) 프로젝트

import tensorflow_datasets as tfdx

dataset = tfds.load(name="mnist")
mnist_train, mnist_test = dataset["train"], dataset["test"]

# 원하는 변환을 적용하고 모델을 훈련하기 위한 준비를 마침
mnist_train = mnist_rain.shuffle(10000).batch(32).prefetch(1)
for item in mnist_train:
    images = item["image"]
    labels = item["label"]
    [...]

# 딕셔너리를 튜플 형태로 변환
mnist_train = mnist_train.shuffle(10000).batch(32)
mnist_train = mnist_train.map(lambda items: (items["image"], items["label"]))
mnist_train = mnist_train.prefetch(1)
dataset = tfds.load(name="mnist", batch_size=32, as_supervised=True)
mnist_train = dataset["train"].prefetch(1)
model = keras.models.Sequential([...])
model.compile(loss="sparse_categorical_crossentropy", optimizer="sgd")
model.fit(mnist_train, epoch=5)
givitallugot commented 1 year ago

13.4 TF 변환

TF 변환

def preprocess(inputs): # inputs is a batch of input features median_age = inputs["housing_median_age"] ocean_proximity = inputs["ocean_proximity"] standardized_age = tft.scale_to_z_score(median_age - tft.mean(median_age)) ocean_proximity_id = tft.compute_and_apply_vocabulary(ocean_proximity) return { "standardized_median_age": standardized_age, "ocean_proximity_id": ocean_proximity_id }


- 그 다음 아파치 빔을 사용해서 preprocess() 함수를 전체 훈련 세트에 적용할 수 있음
- 이 과정에서 전체 훈련 세트에 대해 필요한 모든 통계를 계산
###
=> 데이터 API, TFRecord, 케라스 전처리 층, TF 변환을 사용해 훈련을 위해 매우 확장성이 좋은 입력 파이프라인을 구축하고 상용 환경에서 빠르고 이식성이 좋은 데이터 전처리를 손쉽게 수행할 수 있음
danbi5228 commented 1 year ago

13.3.3 케라스 전처리 층

normalization = keras.layers.Normalization()
discretization = keras.layers.Discretization([..])
pipeline = keras.layers.PreprocessingStage([normalization, discretization])
pipeline.adapt(data_sample)

--> 케라스 전처리 층을 사용하면 전처리 과정을 훨씬 간단히 처리할 수 있음. 자신만의 전처리 층이든, 케라스의 전처리 층을 사용하든 모든 전처리 과정이 동시에 수행될 수 있음