@@ 162-186 (lines=25) @@ | ||
159 | return |
|
160 | injector = BatchInjector(data_x=train_x, data_y=train_y, batch_size=batch_size) |
|
161 | i = 0 |
|
162 | while _pretrain_criterion.continue_learning(): |
|
163 | batch_x, batch_y = injector.next_batch() |
|
164 | if summaries_dir is not None and (i % summary_interval == 0): |
|
165 | summary, loss = session.run( |
|
166 | [current_layer.merged, current_layer.encode_loss], |
|
167 | feed_dict={self.x: x, self.y_: y} |
|
168 | ) |
|
169 | train_writer.add_summary(summary, i) |
|
170 | logger.info('Pre-training Layer %d, Step %d, training loss %g' % (j, i, loss)) |
|
171 | if test_x is not None and test_y is not None: |
|
172 | summary, loss = session.run( |
|
173 | [current_layer.merged, current_layer.encode_loss], |
|
174 | feed_dict={self.x: test_x, self.y_: test_y} |
|
175 | ) |
|
176 | test_writer.add_summary(summary, i) |
|
177 | logger.info('Pre-training Layer %d, Step %d, test loss %g' % (j, i, loss)) |
|
178 | if pretrain_criterion == 'monitor_based': |
|
179 | summary, loss = session.run( |
|
180 | [current_layer.merged, current_layer.encode_loss], |
|
181 | feed_dict={self.x: valid_x, self.y_: valid_y} |
|
182 | ) |
|
183 | valid_writer.add_summary(summary, i) |
|
184 | logger.info('Pre-training Layer %d, Step %d, valid loss %g' % (j, i, loss)) |
|
185 | _ = session.run(self.encode_opts[j], feed_dict={self.x: batch_x, self.y_: batch_y}) |
|
186 | i += 1 |
|
187 | if pretrain_criterion == 'monitor_based': |
|
188 | tf.train.Saver().restore(session, layer_summaries_dir + '/best.ckpt') |
|
189 | if summaries_dir is not None: |
|
@@ 222-240 (lines=19) @@ | ||
219 | return |
|
220 | injector = BatchInjector(data_x=train_x, data_y=train_y, batch_size=batch_size) |
|
221 | i = 0 |
|
222 | while _tuning_criterion.continue_learning(): |
|
223 | batch_x, batch_y = injector.next_batch() |
|
224 | if summaries_dir is not None and (i % summary_interval == 0): |
|
225 | summary, loss, accuracy = session.run([self.merged, self.loss, self.accuracy], |
|
226 | feed_dict={self.x: train_x, self.y_: train_y}) |
|
227 | train_writer.add_summary(summary, i) |
|
228 | logger.info('Fine-Tuning: Step %d, training accuracy %g, loss %g' % (i, accuracy, loss)) |
|
229 | if (test_x is not None) and (test_y is not None): |
|
230 | merged, accuracy = session.run([self.merged, self.accuracy], |
|
231 | feed_dict={self.x: test_x, self.y_: test_y}) |
|
232 | test_writer.add_summary(merged, i) |
|
233 | logger.info('Fine-Tuning: Step %d, test accuracy %g' % (i, accuracy)) |
|
234 | if tuning_criterion == 'monitor_based': |
|
235 | merged, accuracy = session.run([self.merged, self.accuracy], |
|
236 | feed_dict={self.x: valid_x, self.y_: valid_y}) |
|
237 | valid_writer.add_summary(merged, i) |
|
238 | logger.info('Fine-Tuning: Step %d, valid accuracy %g' % (i, accuracy)) |
|
239 | _ = session.run(self.fine_tuning, feed_dict={self.x: batch_x, self.y_: batch_y}) |
|
240 | i += 1 |
|
241 | if tuning_criterion == 'monitor_based': |
|
242 | tf.train.Saver().restore(session, tuning_summaries_dir + '/best.ckpt') |
|
243 | if summaries_dir is not None: |
@@ 155-178 (lines=24) @@ | ||
152 | injector = BatchInjector(data_x=x, data_y=y, batch_size=batch_size) |
|
153 | i = 0 |
|
154 | train_accuracy = 0 |
|
155 | while _criterion.continue_learning(): |
|
156 | batch_x, batch_y = injector.next_batch() |
|
157 | if summaries_dir is not None and (i % summary_interval == 0): |
|
158 | summary, loss, accuracy = session.run([self.merged, self.loss, self.accuracy], |
|
159 | feed_dict={self.x: x, self.y_: y}) |
|
160 | train_writer.add_summary(summary, i) |
|
161 | train_accuracy = accuracy |
|
162 | logger.info('Step %d, train_set accuracy %g, loss %g' % (i, accuracy, loss)) |
|
163 | if (test_x is not None) and (test_y is not None): |
|
164 | merged, accuracy = session.run([self.merged, self.accuracy], |
|
165 | feed_dict={self.x: test_x, self.y_: test_y}) |
|
166 | test_writer.add_summary(merged, i) |
|
167 | logger.info('test_set accuracy %g' % accuracy) |
|
168 | if criterion == 'monitor_based': |
|
169 | merged, accuracy = session.run([self.merged, self.accuracy], |
|
170 | feed_dict={self.x: valid_x, self.y_: valid_y}) |
|
171 | valid_writer.add_summary(merged, i) |
|
172 | logger.info('valid_set accuracy %g' % accuracy) |
|
173 | loss, accuracy, _ = session.run([self.loss, self.accuracy, self.fit_step], |
|
174 | feed_dict={self.x: batch_x, self.y_: batch_y}) |
|
175 | #logger.info('Step %d, training accuracy %g, loss %g' % (i, accuracy, loss)) |
|
176 | #_ = session.run(self.fit_step, feed_dict={self.x: batch_x, self.y_: batch_y}) |
|
177 | #logger.info('Step %d, training accuracy %g, loss %g' % (i, accuracy, loss)) |
|
178 | i += 1 |
|
179 | if criterion == 'monitor_based': |
|
180 | tf.train.Saver().restore(session, os.path.join(summaries_dir, 'best.ckpt')) |
|
181 | logger.debug('Total Epoch: %d, current batch %d', injector.num_epochs, injector.cur_batch) |