Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 고양이는 언제나 귀엽다
- 소호정본점
- 먹기좋은곳
- 발산
- 스테이크
- 파버스
- A. Steed 2: Cruise Control
- 스코티쉬 스트레이트
- 냥이
- 양재맛집
- 데이트
- 안동국시
- 카페
- 부모님과
- codejam
- 소호정
- coffee
- 고양이
- CodeJam 2017 Round 1B
- CDJ
- 발산맛집
- RED CAT COFFEE X LOUNGE
- 냥냥
- 레스토랑
- 커플
- 스파게티
- 발산역 근처 카페
- 치명적 귀여움
- 파머스테이블
- 냥스토리
Archives
- Today
- Total
hubring
TensorFlow로 파일에서 데이터 읽어오기 본문
[참고] 모두를 위한 딥러닝 - 기본적인 머신러닝과 딥러닝 강좌
Loading data from file
import numpy as np
xy = np.loadtxt('sample.csv', delimiter=',', dtype=np.float32)
x_data = xy[:, 0:-1]
y_data = xy[:, [-1]]
slicing
Queue Runners
- 파일 크기가 너무 커서 메모리에 모두 올리지 못할 경우 사용.
- 여러 파일을 받아서 파일 큐에 넣고 Reader를 통해 문서를 읽음
- decoder에서 데이터를 양식에 맞게 처리(, 분리 등)
- Example Queue 배치형태로 데이터를 넣어 사용하도록함.
bach 방식으로 가져오기
import tensorflow as tf
tf.set_random_seed(777) # for reproducibility
filename_queue = tf.train.string_input_producer(
['data-01-test-score.csv'], shuffle=False, name='filename_queue')
reader = tf.TextLineReader()
key, value = reader.read(filename_queue)
# Default values, in case of empty columns. Also specifies the type of the
# decoded result.
record_defaults = [[0.], [0.], [0.], [0.]]
xy = tf.decode_csv(value, record_defaults=record_defaults)
# collect batches of csv in
train_x_batch, train_y_batch = \
tf.train.batch([xy[0:-1], xy[-1:]], batch_size=10)
...
# Start populating the filename queue.
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(sess=sess, coord=coord)
for step in range(2001):
x_batch, y_batch = sess.run([train_x_batch, train_y_batch])
cost_val, hy_val, _ = sess.run(
[cost, hypothesis, train], feed_dict={X: x_batch, Y: y_batch})
if step % 10 == 0:
print(step, "Cost: ", cost_val, "\nPrediction:\n", hy_val)
shuffle_batch
- 배치를 순서대로가 아닌 섞어서 하고 싶을 경우
min_after_dequeue = 10000 capacity = min_after_dequeue + 3*batch_size example_batch, label_batch = tf.train.shuffle_batch([example. label], batch_size=batch_size, capacity=capacity, min_after_dequeue=min_after_dequeue)
'AI > Tensorflow' 카테고리의 다른 글
Multi-variable linear regression (0) | 2021.02.24 |
---|---|
Linear Regression의 cost 최소화 원리 (0) | 2021.02.23 |
Linear Regression (0) | 2021.02.23 |
머신 러닝 기본 (0) | 2021.02.23 |
k-인접이웃 분류모형 (0) | 2019.09.18 |