2017-10-27 4 views
0

Ich erstelle ein Regressionsmodell mit Hilfe von Schätzer DNNRegressor. Es folgt der CodeFehler in DNNRegressor Training

import tensorflow as tf 

DATA_PATH = 'train_data/train_1.csv' 
BATCH_SIZE = 5 
N_FEATURES = 3963 

def batch_generator(filenames): 
    """ filenames is the list of files you want to read from. 
    In this case, it contains only heart.csv 
    """ 
    filename_queue = tf.train.string_input_producer(filenames) 
    reader = tf.TextLineReader(skip_header_lines=1) # skip the first line in the file 
    _, value = reader.read(filename_queue) 
    record_defaults = [[1.0] for _ in range(N_FEATURES)] 

    # read in the rows of data 
    content = tf.decode_csv(value, record_defaults=record_defaults) 

    # pack all features into a tensor 
    features = tf.stack(content[:N_FEATURES]) 

    # assign the last column to label 
    label = content[1] 

    # minimum number elements in the queue after a dequeue, used to ensure 
    # that the samples are sufficiently mixed 
    # I think 10 times the BATCH_SIZE is sufficient 
    min_after_dequeue = 10 * BATCH_SIZE 

    # the maximum number of elements in the queue 
    capacity = 20 * BATCH_SIZE 

    # shuffle the data to generate BATCH_SIZE sample pairs 
    data_batch, label_batch = tf.train.shuffle_batch([features, label], batch_size=BATCH_SIZE, 
             capacity=capacity, min_after_dequeue=min_after_dequeue) 

    return data_batch, label_batch 

def generate_batches(): 
    regressor = tf.estimator.DNNRegressor(feature_columns=feature_cols,hidden_units=[10,10,10],model_dir='alg_model4') 
    with tf.Session() as sess: 
     coord = tf.train.Coordinator() 
     threads = tf.train.start_queue_runners(coord=coord) 
     for _ in range(4): # generate 10 batches 
      regressor.train(input_fn=sess.run(input_fn()),steps=2) 
     coord.request_stop() 
     coord.join(threads) 

def main(): 
    generate_batches() 


if __name__ == '__main__': 
    main() 

Hier wird der Fluss: -

  • Zuerst lese ich Daten aus dem Verzeichnis, das mehrere Dateien mit Präfix als „train_“ enthält.
  • Muster wie Zug _ *. Csv
  • Es enthält 3963 Spalten insgesamt.
  • zweite Säule ist die abhängige Variable Alle ganzen Zahlen vom Typ sind
  • Ich brauche diesen Datensatz in Chargen von fester Größe zu lesen und in DNNRegressor füttern

Issue is that it is throwing the following output with error:- INFO:tensorflow:Using default config. INFO:tensorflow:Using config: {'_log_step_count_steps': 100, '_keep_checkpoint_max': 5, '_save_checkpoints_secs': 600, '_tf_random_seed': 1, '_save_summary_steps': 100, '_model_dir': 'alg_model4', '_save_checkpoints_steps': None, '_session_config': None, '_keep_checkpoint_every_n_hours': 10000} (TensorShape([Dimension(None), Dimension(3963)]), TensorShape([Dimension(None)])) INFO:tensorflow:Error reported to Coordinator: , Dequeue operation was cancelled [[Node: ReaderReadV2_7 = ReaderReadV2[_device="/job:localhost/replica:0/task:0/cpu:0"](TextLineReaderV2_7, input_producer_7)]] --------------------------------------------------------------------------- TypeError Traceback (most recent call last) /usr/lib/python3.5/inspect.py in getfullargspec(func) 1088
skip_bound_arg=False, -> 1089 sigcls=Signature) 1090 except Exception as ex:

/usr/lib/python3.5/inspect.py in _signature_from_callable(obj, follow_wrapper_chains, skip_bound_arg, sigcls) 2155 if not callable(obj): -> 2156 raise TypeError('{!r} is not a callable object'.format(obj)) 2157

TypeError: (array([[ 0., 1., 0., ..., 0., 0., 0.], [ 0., 1., 0., ..., 0., 0., 0.], [ 0., 1., 0., ..., 0., 0., 0.], [ 0., 1., 0., ..., 0., 0., 0.], [ 0., 1., 0., ..., 1., 0., 0.]], dtype=float32), array([4261, 2203, 4120, 4049, 1414])) is not a callable object

The above exception was the direct cause of the following exception:

TypeError Traceback (most recent call last) in() 4 5 if name == 'main': ----> 6 main()

in main() 1 def main(): ----> 2 generate_batches() 3 4 5 if name == 'main':

in generate_batches() 5 threads = tf.train.start_queue_runners(coord=coord) 6 for _ in range(4): # generate 10 batches ----> 7 regressor.train(input_fn=sess.run(input_fn()),steps=2) 8 coord.request_stop() 9 coord.join(threads)

/usr/local/lib/python3.5/dist-packages/tensorflow/python/estimator/estimator.py in train(self, input_fn, hooks, steps, max_steps) 239 hooks.append(training.StopAtStepHook(steps, max_steps)) 240 --> 241 loss = self._train_model(input_fn=input_fn, hooks=hooks) 242 logging.info('Loss for final step: %s.', loss) 243 return self

/usr/local/lib/python3.5/dist-packages/tensorflow/python/estimator/estimator.py in _train_model(self, input_fn, hooks) 626 global_step_tensor = self._create_and_assert_global_step(g) 627 features, labels = self._get_features_and_labels_from_input_fn( --> 628 input_fn, model_fn_lib.ModeKeys.TRAIN) 629 estimator_spec = self._call_model_fn(features, labels, 630 model_fn_lib.ModeKeys.TRAIN)

/usr/local/lib/python3.5/dist-packages/tensorflow/python/estimator/estimator.py in _get_features_and_labels_from_input_fn(self, input_fn, mode) 497 498 def _get_features_and_labels_from_input_fn(self, input_fn, mode): --> 499 result = self._call_input_fn(input_fn, mode) 500 if isinstance(result, (list, tuple)): 501 if len(result) != 2:

/usr/local/lib/python3.5/dist-packages/tensorflow/python/estimator/estimator.py in _call_input_fn(failed resolving arguments) 576 """ 577 del mode # unused --> 578 input_fn_args = util.fn_args(input_fn) 579 kwargs = {} 580 if 'params' in input_fn_args:

/usr/local/lib/python3.5/dist-packages/tensorflow/python/estimator/util.py in fn_args(fn) 55 56 # Handle function. ---> 57 return tuple(tf_inspect.getargspec(fn).args)

/usr/local/lib/python3.5/dist-packages/tensorflow/python/util/tf_inspect.py in getargspec(object) 43 decorators, target = tf_decorator.unwrap(object) 44 return next((d.decorator_argspec for d in decorators ---> 45 if d.decorator_argspec is not None), _inspect.getargspec(target)) 46 47

/usr/lib/python3.5/inspect.py in getargspec(func) 1041
stacklevel=2) 1042 args, varargs, varkw, defaults, kwonlyargs, kwonlydefaults, ann = \ -> 1043 getfullargspec(func) 1044 if kwonlyargs or ann: 1045 raise ValueError("Function has keyword-only arguments or annotations"

/usr/lib/python3.5/inspect.py in getfullargspec(func) 1093

else. So to be fully backwards compatible, we catch all 1094 # possible exceptions here, and reraise a TypeError.

-> 1095 raise TypeError('unsupported callable') from ex 1096 1097 args = []

TypeError: unsupported callable

Antwort

0

Nicht für das Training sicher das Modell, in dem input_fn kommt aus, aber sess.run(input_fn()) sieht falsch aus. Der Estimator wertet die input_fn aus.

Verwandte Themen