teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

4

質問変更

2018/08/03 12:10

投稿

trafalbad
trafalbad

スコア303

title CHANGED
@@ -1,1 +1,1 @@
1
- pandas で日時(data型)に変換する方法
1
+ の中のfor文の内容をすべて出力する方法
body CHANGED
@@ -1,27 +1,27 @@
1
- 質問変更申し訳ありません
1
+ 関数の中にfor文がありま
2
- 以下のようなpandasのDataFrame(df)があります
3
- ```python
4
2
 
5
- df
3
+ 以下のようにして関数からfor文の中身を取り出そうとしましたが、最後の一つしか出力されません
6
4
 
5
+ 関数の中のfor文をすべて出力するにはどうしたら良いでしょうか?
6
+ 出力するとき、for文は関数内で用いて、関数の外ではfor文を使わない方法を探しているのですが可能でしょうか?
7
+ ```python
8
+ def input_data(distort=False):
9
+ filenames = [os.path.join('ubuntu/d', 'train_%d.tfrecords' % i)
10
+ for i in range(1, 61)]
11
+
12
+ queues=[filenames[i*6:(i+1)*6] for i in range(10)]
13
+ for queue in queues:
14
+ a=queue
7
-   hours
15
+ return a
8
- 0 2017063014
9
- 1 2017063015
10
- 2 2017063015
11
- ```
12
16
 
13
- 例えばindexが0のhoursの内容は
14
- **2017063014 → 2017年6月30日14時**
15
- を表しています
16
17
 
18
+ a=input_data()
19
+ a
20
+ >>>['ubuntu/d/train_55.tfrecords',
21
+ 'ubuntu/d/train_56.tfrecords',
22
+ 'ubuntu/d/train_57.tfrecords',
23
+ 'ubuntu/d/train_58.tfrecords',
24
+ 'ubuntu/d/train_59.tfrecords',
17
- この文字列を 2016-12-31 14:00:00'
25
+ 'ubuntu/d/train_60.tfrecords']
18
- このようなdata型に変換できないでしょうか?(以下のコードで出しました)
19
- ご教授お願いします。
20
26
 
21
- ```python
22
-
23
- train_day= pd.date_range('2016-12-31 14:00:00',periods=1,freq='H')
24
- train_day
25
-
26
- >>>DatetimeIndex(['2016-12-31 14:00:00'], dtype='datetime64[ns]', freq='H')
27
27
  ```

3

質問変更

2018/08/03 12:10

投稿

trafalbad
trafalbad

スコア303

title CHANGED
@@ -1,1 +1,1 @@
1
- tf.train.shuffle_batch以外kerasでtfrecord使う方法について
1
+ pandas 数字日時(data型)に変換する方法
body CHANGED
@@ -1,152 +1,27 @@
1
- 2300000枚の画像を読み込ませていますが、エポック4000付近でエラーが出てしまいます
1
+ 質問変更申訳ありせん
2
-
3
- multi_gpu_modelメソッドを使っているので、メモリは確保できているのですが、なぜこのようなエラーが出てしまうのでしょうか?どう考えてもtf.train.shuffle_batchの設定値の問題としか思えないです。
4
-
5
- tfrecord60こ作成し、1つに35000万ほど入っています
2
+ 以下のようなpandasのDataFrame(df)あります
6
-
7
- tf.train.shuffle_batch以外でtfrecordをkerasで使う方法はないでしょうか?
8
-
9
- ご教授お願いします
10
-
11
- #エラー
12
-
13
3
  ```python
14
- Limit: 68719476736
15
- InUse: 68718195456
16
- MaxInUse: 68719414272
17
- NumAllocs: 2500357
18
- MaxAllocSize: 12779520
19
4
 
20
- 2018-07-27 08:36:00.941846: W tensorflow/core/common_runtime/bfc_allocator.cc:279] ****************************************************************************************************
21
- 4834/16407 [=======>......................] - ETA: 4:51:14 - loss: 1.6521 - acc: 0.4547Traceback (most recent call last):
22
- File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1322, in _do_call
23
- return fn(*args)
24
- File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1307, in _run_fn
25
- options, feed_dict, fetch_list, target_list, run_metadata)
26
- File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1409, in _call_tf_sessionrun
27
- run_metadata)
28
- tensorflow.python.framework.errors_impl.OutOfRangeError: RandomShuffleQueue '_0_shuffle_batch/random_shuffle_queue' is closed and has insufficient elements (requested 128, current size 122)
29
- [[Node: shuffle_batch = QueueDequeueManyV2[component_types=[DT_FLOAT, DT_INT32], timeout_ms=-1, _device="/job:localhost/replica:0/task:0/device:CPU:0"](shuffle_batch/random_shuffle_queue, shuffle_batch/n)]]
5
+ df
30
6
 
7
+   hours
31
- During handling of the above exception, another exception occurred:
8
+ 0 2017063014
9
+ 1 2017063015
10
+ 2 2017063015
11
+ ```
32
12
 
33
- Traceback (most recent call last):
34
- File "Inception_resnet_v2_train.py", line 285, in <module>
35
- history = parallel_model.fit(epochs=10, steps_per_epoch=int(np.ceil(2100000 / 128)), callbacks=callback)
36
- File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/keras/engine/training.py", line 1705, in fit
37
- validation_steps=validation_steps)
38
- File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/keras/engine/training.py", line 1188, in _fit_loop
39
- outs = f(ins)
40
- File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py", line 2478, in __call__
41
- **self.session_kwargs)
42
- File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 900, in run
43
- run_metadata_ptr)
44
- File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1135, in _run
45
- feed_dict_tensor, options, run_metadata)
46
- File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1316, in _do_run
47
- run_metadata)
48
- File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1335, in _do_call
49
- raise type(e)(node_def, op, message)
50
- tensorflow.python.framework.errors_impl.OutOfRangeError: RandomShuffleQueue '_0_shuffle_batch/random_shuffle_queue' is closed and has insufficient elements (requested 128, current size 122)
51
- [[Node: shuffle_batch = QueueDequeueManyV2[component_types=[DT_FLOAT, DT_INT32], timeout_ms=-1, _device="/job:localhost/replica:0/task:0/device:CPU:0"](shuffle_batch/random_shuffle_queue, shuffle_batch/n)]]
13
+ 例えばindexが0のhoursの内容は
14
+ **2017063014 2017年6月30日14時**
15
+ を表しています
52
16
 
53
- Caused by op 'shuffle_batch', defined at:
17
+ この文字列を 2016-12-31 14:00:00'
54
- File "Inception_resnet_v2_train.py", line 264, in <module>
55
- train_image, train_labels = input_data('/home/ubuntu/train_tf',128, distort=True)
56
- File "Inception_resnet_v2_train.py", line 97, in input_data
57
- min_after_dequeue=min_queue_examples)
18
+ このようなdata型に変換できないでしょうか?(以下のコードで出しました)
58
- File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/training/input.py", line 1300, in shuffle_batch
59
- name=name)
19
+ ご教授お願いします。
60
- File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/training/input.py", line 846, in _shuffle_batch
61
- dequeued = queue.dequeue_many(batch_size, name=name)
62
- File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/data_flow_ops.py", line 483, in dequeue_many
63
- self._queue_ref, n=n, component_types=self._dtypes, name=name)
64
- File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/gen_data_flow_ops.py", line 3480, in queue_dequeue_many_v2
65
- component_types=component_types, timeout_ms=timeout_ms, name=name)
66
- File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper
67
- op_def=op_def)
68
- File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 3392, in create_op
69
- op_def=op_def)
70
- File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1718, in __init__
71
- self._traceback = self._graph._extract_stack() # pylint: disable=protected-access
72
20
 
73
- OutOfRangeError (see above for traceback): RandomShuffleQueue '_0_shuffle_batch/random_shuffle_queue' is closed and has insufficient elements (requested 128, current size 122)
74
- [[Node: shuffle_batch = QueueDequeueManyV2[component_types=[DT_FLOAT, DT_INT32], timeout_ms=-1, _device="/job:localhost/replica:0/task:0/device:CPU:0"](shuffle_batch/random_shuffle_queue, shuffle_batch/n)]]
75
- ```
76
-
77
-
78
21
  ```python
79
- def input_data(data_dir,batch_size, distort=False):
80
-
81
- num_class = 45
82
- filenames = [os.path.join(data_dir, 'train_%d.tfrecords' % i)
83
- for i in range(1, 61)]
84
- for f in filenames:
85
- if not tf.gfile.Exists(f):
86
- raise ValueError('Failed to find file: ' + f)
87
22
 
88
- # Create a queue that produces the filenames to read.
89
- filename_queue = tf.train.string_input_producer(filenames)
90
- reader = tf.TFRecordReader()
91
- _, serialized_example = reader.read(filename_queue)
92
-
93
- features = tf.parse_single_example(serialized_example,
94
- features={"label": tf.FixedLenFeature([], tf.int64),
95
- "image": tf.FixedLenFeature([], tf.string)})
96
-
97
- label = tf.cast(features["label"], tf.int32)
98
- imgin = tf.reshape(tf.decode_raw(features["image"], tf.uint8), tf.stack([150, 150, 3]))
99
- float_image = tf.cast(imgin, tf.float32)
100
- float_image = tf.image.resize_images(float_image, [96, 96])
101
-
102
-
103
- if distort is True:
104
-      num_preprocess_threads = 60
105
- min_queue_examples =1160000
106
- print ('Filling queue with %d CIFAR images before starting to train. '
23
+ train_day= pd.date_range('2016-12-31 14:00:00',periods=1,freq='H')
107
- 'This will take a few minutes.' % min_queue_examples)
108
- images, label_batch = tf.train.shuffle_batch([distorted_image, label], batch_size=batch_size,
109
- num_threads=num_preprocess_threads, capacity=min_queue_examples + 3 * batch_size,
110
- min_after_dequeue=min_queue_examples)
111
-
112
- else:
24
+ train_day
113
-
114
- images, label_batch = tf.train.batch([distorted_image, label], batch_size=batch_size,
115
- num_threads=num_preprocess_threads, capacity=min_queue_examples + 3 * batch_size,
116
- min_after_dequeue=min_queue_examples)
117
-
118
- return tf.subtract(tf.div(images,127.5), 1.0), tf.one_hot(tf.reshape(label_batch, [batch_size]),num_class)
119
25
 
120
-
121
-
122
- #訓練
123
-
124
- sess = K.get_session()
125
-
126
- train_image, train_labels = input_data('/home/ubuntu/train_tf',128, distort=True)
26
+ >>>DatetimeIndex(['2016-12-31 14:00:00'], dtype='datetime64[ns]', freq='H')
127
- input_ = Input(tensor=train_image)
128
- output_ = InceptionResNetV2(img_input=input_)
129
- train_model = Model(input_, output_, name='inception_resnet_v2')
130
- parallel_model = multi_gpu_model(train_model, gpus=8)
131
- parallel_model.compile(optimizer=SGD(decay=0.1, momentum=0.9, nesterov=True),
132
- loss='categorical_crossentropy',
133
- metrics=['accuracy'], target_tensors=[train_labels])
134
-
135
-
136
- history = History()
137
- callback = []
138
- # callbacks.append(ModelCheckpoint(filepath="model.best.h5", save_best_only=True))
139
- callback.append(history)
140
- callback.append(ModelCheckpoint(filepath="/home/ubuntu/check_dir/model.ep{epoch:02d}.h5"))
141
- callback.append(EarlyStopping("loss", patience=1))
142
-
143
-
144
- coord = tf.train.Coordinator()
145
- threads = tf.train.start_queue_runners(sess, coord)
146
-
147
- history = parallel_model.fit(epochs=10, steps_per_epoch=int(np.ceil(2100000 / 128)), callbacks=callback)
148
- print(history)
149
-
150
- coord.request_stop()
151
- coord.join(threads)
152
27
  ```

2

2018/08/02 03:44

投稿

trafalbad
trafalbad

スコア303

title CHANGED
File without changes
body CHANGED
@@ -1,4 +1,4 @@
1
- 23000000万枚の画像を読み込ませていますが、エポック4000付近でエラーが出てしまいます。
1
+ 2300000枚の画像を読み込ませていますが、エポック4000付近でエラーが出てしまいます。
2
2
 
3
3
  multi_gpu_modelメソッドを使っているので、メモリは確保できているのですが、なぜこのようなエラーが出てしまうのでしょうか?どう考えてもtf.train.shuffle_batchの設定値の問題としか思えないです。
4
4
 

1

2018/07/27 10:43

投稿

trafalbad
trafalbad

スコア303

title CHANGED
@@ -1,1 +1,1 @@
1
- tf.train.shuffle_batchのエラーについて
1
+ tf.train.shuffle_batch以外でkerasでtfrecordを使う方法について
body CHANGED
@@ -1,8 +1,11 @@
1
- 23000000万枚の画像を読み込ませていますが、4000付近でエラーが出てしまいます。
1
+ 23000000万枚の画像を読み込ませていますが、エポック4000付近でエラーが出てしまいます。
2
2
 
3
- multi_gpu_modelメソッドを使っているので、メモリは確保できているのですが、なぜこのようなエラーが出てしまうのでしょうか?どう考えてもtf.train.shuffle_batchの設定値の問題としか思えないですが、このエラーの原因はなぜなのでしょうか?
3
+ multi_gpu_modelメソッドを使っているので、メモリは確保できているのですが、なぜこのようなエラーが出てしまうのでしょうか?どう考えてもtf.train.shuffle_batchの設定値の問題としか思えないです
4
4
 
5
5
  tfrecordが60こ作成し、1つに35000万ほど入っています
6
+
7
+ tf.train.shuffle_batch以外でtfrecordをkerasで使う方法はないでしょうか?
8
+
6
9
  ご教授お願いします
7
10
 
8
11
  #エラー