Open givitallugot opened 1 year ago
assign roles -s 0427 -c 13.3.3 13.4 13.5
0 | 1 | 2 | |
---|---|---|---|
member | 한단비 | 주선미 | 김유리 |
chapter | 13.3.3 | 13.4 | 13.5 |
tfds.load()
: 원하는 데이터를 다운로드하고 데이터셋의 딕셔너리로 데이터를 반환함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)
as_supervised=True
로 지정하여 load()
함수를 호출하는 것이 더 간단함in_memory=True
로 설정하면 데이터셋을 메모리로 적재하여 처리 속도를 높일 수 있음tf.keras
모델에 바로 이 데이터셋을 전달할 수 있음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)
import tensorflow_transform as tft
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 변환을 사용해 훈련을 위해 매우 확장성이 좋은 입력 파이프라인을 구축하고 상용 환경에서 빠르고 이식성이 좋은 데이터 전처리를 손쉽게 수행할 수 있음
keras.layers.Normalization
: 특성 표준화 수행TextVectorization
: 입력에 있는 각 단어를 어휘 사전에 있는 인덱스로 인코딩Discretization
: 연속적인 데이터를 몇 개의 구간으로 나누고 각 구간을 원-핫 벡터로 인코딩
ProcessingStage
클래스를 사용해 여러 전처리 층을 연결할 수 있음normalization = keras.layers.Normalization()
discretization = keras.layers.Discretization([..])
pipeline = keras.layers.PreprocessingStage([normalization, discretization])
pipeline.adapt(data_sample)
TextVectorization
층은 단어 카운트 벡터를 출력하는 옵션을 가지고 있음
--> 케라스 전처리 층을 사용하면 전처리 과정을 훨씬 간단히 처리할 수 있음. 자신만의 전처리 층이든, 케라스의 전처리 층을 사용하든 모든 전처리 과정이 동시에 수행될 수 있음
~05/08 월 10:10~ 05/11 목 9:30