for itr in range(100): print("\nFor the {0:03d}".format(itr)) awa_train_path = config.data_path + 'meta/path_label_list{0:03d}.txt'.format(itr) # num_file : int # count the number of input image files with open(awa_train_path) as f: for num_file, l in enumerate(f): pass """ example) queue_data('/home/siit/navi/data/sample/meta/path_label_list.txt', 50, 1, 'val',multi_label=False) """ trainX, trainY = data_loader.queue_data( awa_train_path, config.n_classes, config.batch_size, 'val', multi_label=False) feat = [] lab = [] path_feat = {} for i in range(num_file+1): batch_x, batch_y = sess.run([trainX, trainY]) _, idx = np.nonzero(batch_y) feature = sess.run(feat_layer, feed_dict={x: batch_x, y_: batch_y, keep_prob:1.0}) feat.append(feature[0][0][0]) lab.append(idx[0]) path_feat[] if i%1000 == 0:
total_cost += cost_val counter += 1 if np.mod(counter, config.print_freq) == 0: print('Step:', '%05dk' % (counter), '\tAvg. cost =', '{:.5f}'.format(cost_val), '\tAcc: {:.5f}'.format(acc_)) writer.add_summary(acc, counter) # Save the model if np.mod(counter, config.save_freq) == 0: if config.nsml: nsml.save(counter) if not os.path.exists(config.checkpoint_path): os.mkdir(config.checkpoint_path) saver.save(sess, os.path.join(config.checkpoint_path, 'vgg19_{0:03d}k'.format(int(counter/1000)))) print('Model ') # -------------------- Testing -------------------- # Xbatch, Ybatch, _ = data_loader.queue_data( test_data, label_list, im_size) accuracy_ = sess.run(accuracy, feed_dict = {X: Xbatch, Y: Ybatch}) print('Accuracy:', accuracy_)
train_data = [line for line in path_label_list if 'train' in line] test_data = [line for line in path_label_list if 'test' in line] num_file = len(train_data) # print('Number of input files: \t{}'.format(num_file)) total_batch = int(num_file / batch_size) total_cost = 0 final_acc = 0 for i in range(total_batch): # Get the batch as [batch_size, 28,28] and [batch_size, n_classes] ndarray Xbatch, Ybatch, _ = data_loader.queue_data( train_data[i*batch_size:(i+1)*batch_size], label_list, im_size) _, cost_val, acc = sess.run([optimizer, cost, merged], feed_dict={X: Xbatch, Y: Ybatch}) total_cost += cost_val print('Epoch:', '%04d' % (epoch + 1), '\tAvg. cost =', '{:.3f}'.format(total_cost / total_batch)) writer.add_summary(acc, epoch) # Save the model if epoch % 5 == 0: if not os.path.exists(config.checkpoint_path): os.mkdir(config.checkpoint_path) saver.save(sess, os.path.join(config.checkpoint_path,
test_data = all_data[:1000] num_file = len(train_data) if num_file == 0: break # print('Number of input files: \t{}'.format(num_file)) total_batch = int(num_file / batch_size) total_cost = 0 final_acc = 0 for i in range(total_batch): # Get the batch as [batch_size, 28,28] and [batch_size, n_classes] ndarray Xbatch, Ybatch, _ = data_loader.queue_data( train_data[i * batch_size:(i + 1) * batch_size], label_list, im_size, config.lable_processed) _, cost_val, acc = sess.run([optimizer, cost, merged], feed_dict={ X: Xbatch, Y: Ybatch }) total_cost += cost_val if np.mod(i, 10) == 0: print('Epoch:', '%02d' % (epoch + 1), '\tAvg. cost =', '{:.3f}'.format(total_cost / total_batch)) print('Epoch:', '%04d' % (epoch + 1), '\tAvg. cost =', '{:.3f}'.format(total_cost / total_batch))