models icon indicating copy to clipboard operation
models copied to clipboard

run train.py in the models of tensorflow/models/research/object_detection,has error

Open Distance789 opened this issue 8 years ago • 3 comments

win10(64) python3.6 CUDA8.0 CUDNN 7.0 tensorflow-cpu 1.6(special) pycharm

Copyright 2017 The TensorFlow Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");

you may not use this file except in compliance with the License.

You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software

distributed under the License is distributed on an "AS IS" BASIS,

WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and

limitations under the License.

==============================================================================

r"""Training executable for detection models.

This executable is used to train DetectionModels. There are two ways of configuring the training job:

  1. A single pipeline_pb2.TrainEvalPipelineConfig configuration file can be specified by --pipeline_config_path.

Example usage: ./train
--logtostderr
--train_dir=path/to/train_dir
--pipeline_config_path=pipeline_config.pbtxt

  1. Three configuration files can be provided: a model_pb2.DetectionModel configuration file to define what type of DetectionModel is being trained, an input_reader_pb2.InputReader file to specify what training data will be used and a train_pb2.TrainConfig file to configure training parameters.

Example usage: ./train
--logtostderr
--train_dir=path/to/train_dir
--model_config_path=model_config.pbtxt
--train_config_path=train_config.pbtxt
--input_config_path=train_input_config.pbtxt """

import functools import json import os import tensorflow as tf

from object_detection import trainer from object_detection.builders import dataset_builder from object_detection.builders import graph_rewriter_builder from object_detection.builders import model_builder from object_detection.utils import config_util from object_detection.utils import dataset_util

tf.logging.set_verbosity(tf.logging.INFO)

flags = tf.app.flags flags.DEFINE_string('master', '', 'Name of the TensorFlow master to use.') flags.DEFINE_integer('task', 0, 'task id') flags.DEFINE_integer('num_clones', 1, 'Number of clones to deploy per worker.') flags.DEFINE_boolean('clone_on_cpu', False, 'Force clones to be deployed on CPU. Note that even if ' 'set to False (allowing ops to run on gpu), some ops may ' 'still be run on the CPU if they have no GPU kernel.') flags.DEFINE_integer('worker_replicas', 1, 'Number of worker+trainer ' 'replicas.') flags.DEFINE_integer('ps_tasks', 0, 'Number of parameter server tasks. If None, does not use ' 'a parameter server.') flags.DEFINE_string('train_dir', '', 'Directory to save the checkpoints and training summaries.')

flags.DEFINE_string('pipeline_config_path', '', 'Path to a pipeline_pb2.TrainEvalPipelineConfig config ' 'file. If provided, other configs are ignored')

flags.DEFINE_string('train_config_path', '', 'Path to a train_pb2.TrainConfig config file.') flags.DEFINE_string('input_config_path', '', 'Path to an input_reader_pb2.InputReader config file.') flags.DEFINE_string('model_config_path', '', 'Path to a model_pb2.DetectionModel config file.')

FLAGS = flags.FLAGS

def main(_): assert FLAGS.train_dir, 'train_dir is missing.' if FLAGS.task == 0: tf.gfile.MakeDirs(FLAGS.train_dir) if FLAGS.pipeline_config_path: configs = config_util.get_configs_from_pipeline_file( FLAGS.pipeline_config_path) if FLAGS.task == 0: tf.gfile.Copy(FLAGS.pipeline_config_path, os.path.join(FLAGS.train_dir, 'pipeline.config'), overwrite=True) else: configs = config_util.get_configs_from_multiple_files( model_config_path=FLAGS.model_config_path, train_config_path=FLAGS.train_config_path, train_input_config_path=FLAGS.input_config_path) if FLAGS.task == 0: for name, config in [('model.config', FLAGS.model_config_path), ('train.config', FLAGS.train_config_path), ('input.config', FLAGS.input_config_path)]: tf.gfile.Copy(config, os.path.join(FLAGS.train_dir, name), overwrite=True)

model_config = configs['model'] train_config = configs['train_config'] input_config = configs['train_input_config']

model_fn = functools.partial( model_builder.build, model_config=model_config, is_training=True)

def get_next(config): return dataset_util.make_initializable_iterator( dataset_builder.build(config)).get_next()

create_input_dict_fn = functools.partial(get_next, input_config)

env = json.loads(os.environ.get('TF_CONFIG', '{}')) cluster_data = env.get('cluster', None) cluster = tf.train.ClusterSpec(cluster_data) if cluster_data else None task_data = env.get('task', None) or {'type': 'master', 'index': 0} task_info = type('TaskSpec', (object,), task_data)

Parameters for a single worker.

ps_tasks = 0 worker_replicas = 1 worker_job_name = 'lonely_worker' task = 0 is_chief = True master = ''

if cluster_data and 'worker' in cluster_data: # Number of total worker replicas include "worker"s and the "master". worker_replicas = len(cluster_data['worker']) + 1 if cluster_data and 'ps' in cluster_data: ps_tasks = len(cluster_data['ps'])

if worker_replicas > 1 and ps_tasks < 1: raise ValueError('At least 1 ps task is needed for distributed training.')

if worker_replicas >= 1 and ps_tasks > 0: # Set up distributed training. server = tf.train.Server(tf.train.ClusterSpec(cluster), protocol='grpc', job_name=task_info.type, task_index=task_info.index) if task_info.type == 'ps': server.join() return

worker_job_name = '%s/task:%d' % (task_info.type, task_info.index)
task = task_info.index
is_chief = (task_info.type == 'master')
master = server.target

graph_rewriter_fn = None if 'graph_rewriter_config' in configs: graph_rewriter_fn = graph_rewriter_builder.build( configs['graph_rewriter_config'], is_training=True)

trainer.train( create_input_dict_fn, model_fn, train_config, master, task, FLAGS.num_clones, worker_replicas, FLAGS.clone_on_cpu, ps_tasks, worker_job_name, is_chief, FLAGS.train_dir, graph_hook_fn=graph_rewriter_fn)

if name == 'main': tf.app.run()

run result:

E:\Python36\python.exe G:/raccoon_dataset-master/train.py --logtostderr --pipeline_config_path=G:\raccoon_dataset-master\ssd_mobilenet_v1_raccoon.config --train_dir=G:\raccoon_dataset-master\train WARNING:tensorflow:num_readers has been reduced to 0 to match input file shards. Traceback (most recent call last): File "G:/raccoon_dataset-master/train.py", line 184, in tf.app.run() File "E:\Python36\lib\site-packages\tensorflow\python\platform\app.py", line 126, in run _sys.exit(main(argv)) File "G:/raccoon_dataset-master/train.py", line 180, in main graph_hook_fn=graph_rewriter_fn) File "G:\raccoon_dataset-master\object_detection\trainer.py", line 275, in train train_config.prefetch_queue_capacity, data_augmentation_options) File "G:\raccoon_dataset-master\object_detection\trainer.py", line 59, in create_input_queue tensor_dict = create_tensor_dict_fn() File "G:/raccoon_dataset-master/train.py", line 121, in get_next dataset_builder.build(config)).get_next() File "G:\raccoon_dataset-master\object_detection\builders\dataset_builder.py", line 186, in build process_fn, config.input_path[:], input_reader_config) File "G:\raccoon_dataset-master\object_detection\utils\dataset_util.py", line 141, in read_dataset sloppy=config.shuffle)) File "E:\Python36\lib\site-packages\tensorflow\python\data\ops\dataset_ops.py", line 912, in apply dataset = transformation_func(self) File "E:\Python36\lib\site-packages\tensorflow\contrib\data\python\ops\interleave_ops.py", line 167, in _apply_fn buffer_output_elements, prefetch_input_elements) File "E:\Python36\lib\site-packages\tensorflow\contrib\data\python\ops\interleave_ops.py", line 70, in init self._map_func.add_to_graph(ops.get_default_graph()) File "E:\Python36\lib\site-packages\tensorflow\python\framework\function.py", line 486, in add_to_graph self._create_definition_if_needed() File "E:\Python36\lib\site-packages\tensorflow\python\framework\function.py", line 321, in _create_definition_if_needed self._create_definition_if_needed_impl() File "E:\Python36\lib\site-packages\tensorflow\python\framework\function.py", line 338, in _create_definition_if_needed_impl outputs = self._func(*inputs) File "E:\Python36\lib\site-packages\tensorflow\contrib\data\python\ops\interleave_ops.py", line 58, in tf_map_func dataset = map_func(nested_args) File "E:\Python36\lib\site-packages\tensorflow\python\data\ops\readers.py", line 93, in init filenames, dtypes.string, name="filenames") File "E:\Python36\lib\site-packages\tensorflow\python\framework\ops.py", line 946, in convert_to_tensor as_ref=False) File "E:\Python36\lib\site-packages\tensorflow\python\framework\ops.py", line 1036, in internal_convert_to_tensor ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref) File "E:\Python36\lib\site-packages\tensorflow\python\framework\ops.py", line 879, in _TensorTensorConversionFunction (dtype.name, t.dtype.name, str(t))) ValueError: Tensor conversion requested dtype string for Tensor with dtype float32: 'Tensor("arg0:0", shape=(), dtype=float32)'

Process finished with exit code 1

Distance789 avatar Jul 29 '18 13:07 Distance789

Thank you for your post. We noticed you have not filled out the following field in the issue template. Could you update them if they are relevant in your case, or leave them as N/A? Thanks. What is the top-level directory of the model you are using Have I written custom code OS Platform and Distribution TensorFlow installed from TensorFlow version Bazel version CUDA/cuDNN version GPU model and memory Exact command to reproduce

tensorflowbutler avatar Jul 30 '18 00:07 tensorflowbutler

@tensorflowbutler @Distance789

Hi, I am stuck in similar kind of issue , needed help and advise . System Config Name Version Build Channel

  • cudatoolkit 10.0.130 0
  • cudnn 7.3.1 cuda10.0_0
  • conda 4.6.2 py36_0
  • matplotlib 3.0.2 py36hc8f65d3_0
  • python 3.6.8 h9f7ef89_0
  • Windows 10 + 64bit

I am using anaconda with windows10. Current working Directory - C:\Users..\model\models-master\research then I run the the protobuf and pythonpath commands. C:\Users...\model\models-master\research>C:/Users/.../protoc-3.4.0-win32/bin/protoc object_detection/protos/*.proto --python_out=. (It runs successfully with out any error) then i run C:\Users...\model\models-master\research>set PYTHONPATH=$PYTHONPATH:'C:\Users\1010141\Desktop\model\models-master\research':'C:\Users\1010141\Desktop\model\models-master\research\slim' (It runs successfully without any error) C:\Users...\model\models-master\research>cd Object_detection C:\Users...\model\models-master\research\Object_detection>python train.py --logtostderr --train_dir=Training/ --pipeline_config_path=training/ssd_mobilenet_v1_pets.config

Now the error is coming :
Traceback (most recent call last): File "train.py", line 49, in from object_detection.builders import dataset_builder ModuleNotFoundError: No module named 'object_detection'

Please advise where I am going wrong

rahulramesh3321 avatar Feb 02 '19 13:02 rahulramesh3321

your can add object_detection dir to sys.path

northeastsquare avatar Mar 15 '20 14:03 northeastsquare