΢ Ͷ ^ ھ

cba广州赛程 :tensorflowʹrange_input_producerྀxȡ

cba㶫 www.axwwg.com  •rg2020-01-26 11:00:56   ߣ   ҪuՓ(0)

ȷPIa


i = tf.train.range_input_producer(NUM_EXPOCHES, num_epochs=1, shuffle=False).dequeue()
inputs = tf.slice(array, [i * BATCH_SIZE], [BATCH

ȷPIa

i = tf.train.range_input_producer(NUM_EXPOCHES, num_epochs=1, shuffle=False).dequeue()
inputs = tf.slice(array, [i * BATCH_SIZE], [BATCH_SIZE])

ԭ

һЕaһа0NUM_EXPOCHES-1Ԫnum_epochsָtÿԪֻanum_epochstѭhashuffleָǷy@shuffle=FalseʾеԪǰ0NUM_EXPOCHES-1惦Graph\еĕrÿ̏ȡԪOֵiȻյڶдaгarrayһСΔһbatchNUM_EXPOCHES=3num_epochs=2tеă@

0,1,2,0,1,2

ֻ6Ԫ@Ӗĕrֻܮa6batch6ԺӖͽY

num_epochsָtЃ@ӣ

0,1,2,0,1,2,0,1,2,0,1,2...

пһֱԪӖĕrԮao޵batchҪԼʲôrֹͣӖ

ʾa

ļtest.txtݣ

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
32
33
34
35

main.pyݣ

import tensorflow as tf
import codecs
 
BATCH_SIZE = 6
NUM_EXPOCHES = 5
 
 
def input_producer():
 array = codecs.open("test.txt").readlines()
	array = map(lambda line: line.strip(), array)
 i = tf.train.range_input_producer(NUM_EXPOCHES, num_epochs=1, shuffle=False).dequeue()
 inputs = tf.slice(array, [i * BATCH_SIZE], [BATCH_SIZE])
 return inputs
 
 
class Inputs(object):
 def __init__(self):
  self.inputs = input_producer()
 
 
def main(*args, **kwargs):
 inputs = Inputs()
 init = tf.group(tf.initialize_all_variables(),
     tf.initialize_local_variables())
 sess = tf.Session()
 coord = tf.train.Coordinator()
 threads = tf.train.start_queue_runners(sess=sess, coord=coord)
 sess.run(init)
 try:
  index = 0
  while not coord.should_stop() and index<10:
   datalines = sess.run(inputs.inputs)
   index += 1
   print("step: %d, batch data: %s" % (index, str(datalines)))
 except tf.errors.OutOfRangeError:
  print("Done traing:-------Epoch limit reached")
 except KeyboardInterrupt:
  print("keyboard interrput detected, stop training")
 finally:
  coord.request_stop()
 coord.join(threads)
 sess.close()
 del sess
	
if __name__ == "__main__":
 main()

ݔ

step: 1, batch data: ['1' '2' '3' '4' '5' '6']
step: 2, batch data: ['7' '8' '9' '10' '11' '12']
step: 3, batch data: ['13' '14' '15' '16' '17' '18']
step: 4, batch data: ['19' '20' '21' '22' '23' '24']
step: 5, batch data: ['25' '26' '27' '28' '29' '30']
Done traing:-------Epoch limit reached

range_input_producerȥ􅢔num_epochs=1tݔ

step: 1, batch data: ['1' '2' '3' '4' '5' '6']
step: 2, batch data: ['7' '8' '9' '10' '11' '12']
step: 3, batch data: ['13' '14' '15' '16' '17' '18']
step: 4, batch data: ['19' '20' '21' '22' '23' '24']
step: 5, batch data: ['25' '26' '27' '28' '29' '30']
step: 6, batch data: ['1' '2' '3' '4' '5' '6']
step: 7, batch data: ['7' '8' '9' '10' '11' '12']
step: 8, batch data: ['13' '14' '15' '16' '17' '18']
step: 9, batch data: ['19' '20' '21' '22' '23' '24']
step: 10, batch data: ['25' '26' '27' '28' '29' '30']

һcҪעļ35lBATCH_SIZE = 6ʾÿbatch6lNUM_EXPOCHES = 5ʾa5batchNUM_EXPOCHES =6tҪ36l͕e`

InvalidArgumentError (see above for traceback): Expected size[0] in [0, 5], but got 6
 [[Node: Slice = Slice[Index=DT_INT32, T=DT_STRING, _device="/job:localhost/replica:0/task:0/cpu:0"](Slice/input, Slice/begin/_5, Slice/size)]]

e`Ϣ˼35/BATCH_SIZE=5NUM_EXPOCHES ȡֵֻ05֮g

@ƪtensorflowʹrange_input_producerྀxȡСoҵȫϣܽoһҲϣҶ֧_֮

ܸdȤ:

  • ԔTensorflowxȡNʽnext_batch
  • Tensorflowʹtfrecordʽxȡķ
  • tensorflow tf.train.batch֮xȡʽ
  • ʹTensorflowԼĔָbatchӖ

P

  • tensorflowʹrange_input_producerྀxȡ

    tensorflowʹrange_input_producerྀxȡ

    ȷPIa i = tf.train.range_input_producer(NUM_EXPOCHES, num_epochs=1, shuffle=False).dequeue() inputs = tf.slice(array, [i * BATCH_SIZE], [BATCH
    2020-01-26
  • Ptf.reverse_sequence()

    Ptf.reverse_sequence()

    tf.reverse_sequence() ڿbidirectional_dynamic_rnn()Դaĕr˴a{ reverse_sequence()@һֻȥ@÷lF
    2020-01-26
  • pRNN:bidirectional_dynamic_rnn()ʹԔ

    pRNN:bidirectional_dynamic_rnn()ʹԔ

    pRNNbidirectional_dynamic_rnn()ʹԔ fžʲôҪʹõpRNNxһƪµĕrᵽϢʮֵҪ@ЩϢDzԲ׽
    2020-01-26
  • Ptf.nn.dynamic_rnnֵԔ

    Ptf.nn.dynamic_rnnֵԔ

    ԭ tf.nn.dynamic_rnn( cell, inputs, sequence_length=None, initial_state=None, dtype=None, parallel_iterations=None, swap_memory=Fal
    2020-01-26
  • pythonCWxgboostʹ

    pythonCWxgboostʹ

    1.xȡ ԭxgboostxȡlibsvm import xgboost as xgb data = xgb.DMatrix(libsvmļ) ʹsklearnxȡlibsvm from sklearn.
    2020-01-26
  • \ՄTensorflow ӑBpRNNݔ}

    \ՄTensorflow ӑBpRNNݔ}

    tf.nn.bidirectional_dynamic_rnn() def bidirectional_dynamic_rnn( cell_fw, # ǰRNN cell_bw, # RNN inputs, # ݔ sequence_length=No
    2020-01-26
  • pythonȡվӕϢČFa

    pythonȡվӕϢČFa

    TxֻץȡQϢdַ惦 칤DBUtil.py import pymysql class DBUtils(object): def connDB(self):
    2020-01-26
  • TFRecordʽ惦cxȡ

    TFRecordʽ惦cxȡ

    Tensor FlowٷWվṩNxȡķ 1. AdTensor FlowDжx׃Д,ֱǶDӖ^r
    2020-01-26
  • ʹ tf.nn.dynamic_rnn չ_rgSȷʽ

    ʹ tf.nn.dynamic_rnn չ_rgSȷʽ

    چ΂ RNNCell  ʹɫ call M\r ֻЕrgǰMһ  ʹ x1 ho õh1 ͨ^ x2  h1 õ h2  tf.nn.dynamic_r
    2020-01-26
  • tensorflow ckptģͺpbģͫ@ȡcQ,ckptDpbģ͌

    tensorflow ckptģͺpbģͫ@ȡcQ,ckptDpbģ͌

    ckpt from tensorflow.python import pywrap_tensorflow checkpoint_path = 'model.ckpt-8000' reader = pywrap_tensorflow.NewCheckpointReader(checkpoint_pa
    2020-01-26