models icon indicating copy to clipboard operation
models copied to clipboard

No variables to save error using tensorflow object detection API

Open ddurgaprasad opened this issue 8 years ago • 48 comments

System information

  • What is the top-level directory of the model you are using:/tensorflow/models/research

  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow):No

  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04):

    DISTRIB_ID=Ubuntu DISTRIB_RELEASE=16.04 DISTRIB_CODENAME=xenial DISTRIB_DESCRIPTION="Ubuntu 16.04.3 LTS"

  • TensorFlow installed from (source or binary): binary

  • TensorFlow version (use command below): ('v1.3.0-rc1-7384-gc9437c1', '1.6.0-dev20180119')

  • Bazel version (if compiling from source): Not Applicable

  • CUDA/cuDNN version: Not Applicable

  • GPU model and memory: Not Applicable

  • Exact command to reproduce:

    python object_detection/train.py --logtostderr
    --pipeline_config_path=train_mydata/models/model/ssd_mobilenet_v1_coco.config
    --train_dir=train_mydata/models/train

Describe the problem

Successfully created necessary files for training my custom data as described at https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/running_locally.md

Executing the above command complained about absence of tkinter, which is installed with apt-get install.Updated the tensorflow to latest nightly build.

Getting 'No Variables to save' after running above training

Source code / logs

---Config file

  SSD with Mobilenet v1 configuration for MSCOCO Dataset.


model {
  ssd {
    num_classes: 1
    box_coder {
      faster_rcnn_box_coder {
        y_scale: 10.0
        x_scale: 10.0
        height_scale: 5.0
        width_scale: 5.0
      }
    }
    matcher {
      argmax_matcher {
        matched_threshold: 0.5
        unmatched_threshold: 0.5
        ignore_thresholds: false
        negatives_lower_than_unmatched: true
        force_match_for_each_row: true
      }
    }
    similarity_calculator {
      iou_similarity {
      }
    }
    anchor_generator {
      ssd_anchor_generator {
        num_layers: 6
        min_scale: 0.2
        max_scale: 0.95
        aspect_ratios: 1.0
        aspect_ratios: 2.0
        aspect_ratios: 0.5
        aspect_ratios: 3.0
        aspect_ratios: 0.3333
      }
    }
    image_resizer {
      fixed_shape_resizer {
        height: 300
        width: 300
      }
    }
    box_predictor {
      convolutional_box_predictor {
        min_depth: 0
        max_depth: 0
        num_layers_before_predictor: 0
        use_dropout: false
        dropout_keep_probability: 0.8
        kernel_size: 1
        box_code_size: 4
        apply_sigmoid_to_scores: false
        conv_hyperparams {
          activation: RELU_6,
          regularizer {
            l2_regularizer {
              weight: 0.00004
            }
          }
          initializer {
            truncated_normal_initializer {
              stddev: 0.03
              mean: 0.0
            }
          }
          batch_norm {
            train: true,
            scale: true,
            center: true,
            decay: 0.9997,
            epsilon: 0.001,
          }
        }
      }
    }
    feature_extractor {
      type: 'ssd_mobilenet_v1'
      min_depth: 16
      depth_multiplier: 1.0
      conv_hyperparams {
        activation: RELU_6,
        regularizer {
          l2_regularizer {
            weight: 0.00004
          }
        }
        initializer {
          truncated_normal_initializer {
            stddev: 0.03
            mean: 0.0
          }
        }
        batch_norm {
          train: true,
          scale: true,
          center: true,
          decay: 0.9997,
          epsilon: 0.001,
        }
      }
    }
    loss {
      classification_loss {
        weighted_sigmoid {
          anchorwise_output: true
        }
      }
      localization_loss {
        weighted_smooth_l1 {
          anchorwise_output: true
        }
      }
      hard_example_miner {
        num_hard_examples: 3000
        iou_threshold: 0.99
        loss_type: CLASSIFICATION
        max_negatives_per_positive: 3
        min_negatives_per_image: 0
      }
      classification_weight: 1.0
      localization_weight: 1.0
    }
    normalize_loss_by_num_matches: true
    post_processing {
      batch_non_max_suppression {
        score_threshold: 1e-8
        iou_threshold: 0.6
        max_detections_per_class: 100
        max_total_detections: 100
      }
      score_converter: SIGMOID
    }
  }
}

train_config: {
  batch_size: 15
  optimizer {
    rms_prop_optimizer: {
      learning_rate: {
        exponential_decay_learning_rate {
          initial_learning_rate: 0.004
          decay_steps: 800720
          decay_factor: 0.95
        }
      }
      momentum_optimizer_value: 0.9
      decay: 0.9
      epsilon: 1.0
    }
  }
  fine_tune_checkpoint: "/tensorflow/models/research/train_mydata/data/mobilenet_v1_1.0_224.ckpt"
  from_detection_checkpoint: true
  # Note: The below line limits the training process to 200K steps, which we
  # empirically found to be sufficient enough to train the pets dataset. This
  # effectively bypasses the learning rate schedule (the learning rate will
  # never decay). Remove the below line to train indefinitely.
  num_steps: 300
  data_augmentation_options {
    random_horizontal_flip {
    }
  }
  data_augmentation_options {
    ssd_random_crop {
    }
  }
}

train_input_reader: {
  tf_record_input_reader {
    input_path: "/tensorflow/models/research/train_mydata/data/train.record"
  }
  label_map_path: "/tensorflow/models/research/train_mydata/data/object_label.pbtxt"
}

eval_config: {
  num_examples: 160
  # Note: The below line limits the evaluation process to 10 evaluations.
  # Remove the below line to evaluate indefinitely.
  max_evals: 10
}

eval_input_reader: {
  tf_record_input_reader {
    input_path: "/tensorflow/models/research/train_mydata/data/test.record"
  }
  label_map_path: "/tensorflow/models/research/train_mydata/data/object_label.pbtxt"
  shuffle: false
  num_readers: 1
  num_epochs: 1
}

Errors

Traceback (most recent call last): File "object_detection/train.py", line 163, in tf.app.run() File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/app.py", line 124, in run _sys.exit(main(argv)) File "object_detection/train.py", line 159, in main worker_job_name, is_chief, FLAGS.train_dir) File "build/bdist.linux-x86_64/egg/object_detection/trainer.py", line 255, in train init_saver = tf.train.Saver(available_var_map) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.py", line 1288, in init self.build() File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.py", line 1297, in build self._build(self._filename, build_save=True, build_restore=True) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.py", line 1322, in _build raise ValueError("No variables to save") ValueError: No variables to save

ddurgaprasad avatar Jan 20 '18 06:01 ddurgaprasad

Any ideas @jch1 @tombstone ?

tatatodd avatar Jan 26 '18 21:01 tatatodd

Getting the same issue. I was able to bypass the error by using other models (faster_rcnn_inception_v2_coco_2017_11_08).

hu-po avatar Feb 04 '18 02:02 hu-po

I'd love to bypass this error by using other models but other models give another error, for which there is already an issue:

Expected int32, got range(0, 3) of type 'range' instead.

So, I've so far been unsuccessful at using ANY model with TF object detection.

jazoom avatar Mar 15 '18 02:03 jazoom

Solution for issue #3443 might help you, @jazoom.

TheFlashover avatar Mar 15 '18 08:03 TheFlashover

resnet_v1_101,按照 #3443 解决了“Expected int32, got range(0, 3) of type 'range' instead”的错误,但是出现了“ValueError: No variables to save”的错误。resnet_v2_101也有这些错误。

yuanyuanxiang avatar Mar 24 '18 12:03 yuanyuanxiang

@yuanyuanxiang 所有你的问题解决了吗?求助

shuli163love avatar Apr 19 '18 11:04 shuli163love

@shuli163love 这可能是预训练模型的问题,换一个模型就行了。虽然模型名称一样,但是日期不同也应该换着试一下。

yuanyuanxiang avatar Apr 19 '18 12:04 yuanyuanxiang

I'm getting same errors on different models including one I trained yesterday. yesterday btw I didn't get any errors, I terminated the training script (I'm using the stock script train.py from models/research/object_detection which doesn't stop itself) and then I presumably did something wrong and started to get those variable errors I wrote no custom code, and was trying to train inception v2, mobilenet v1&2 models

before raise the variable exception, it gives up some warnings like this

WARNING:root:Variable [MobilenetV1/Conv2d_9_depthwise/depthwise_weights/RMSProp] is not available in checkpoint
WARNING:root:Variable [MobilenetV1/Conv2d_9_depthwise/depthwise_weights/RMSProp_1] is not available in checkpoint
WARNING:root:Variable [MobilenetV1/Conv2d_9_pointwise/BatchNorm/beta] is not available in checkpoint

which looks strange because I used different models but the mentioning of MobilenetV1 pops up every time

speaking of Stackoverflow, there's some custom code being discussed, it's hard to figure out how their solutions may be applied to the stock code.

Insertfunnylogin avatar Apr 20 '18 12:04 Insertfunnylogin

I don't know why but setting this variable to false solved the issue for me: from_detection_checkpoint: false

chriskraus0 avatar May 23 '18 13:05 chriskraus0

@yuanyuanxiang is right, I met the same problem, finally use ssd_mobilenet_v1_coco_2017_11_17 succed

hbbdwk avatar Jun 27 '18 11:06 hbbdwk

#2025 should help @ddurgaprasad from_detection_checkpoint: true should be changed to from_detection_checkpoint: false

stoneyang avatar Jun 28 '18 11:06 stoneyang

Did anyone find any other solutions to this problem? I am trying to run train.py using the ssd_mobilenet_v1_fpn model and I am running into the same error:

ValueError: No variables to save.

There is no line from_detection_checkpoint in the ssd_mobilenet_v1_fpn_shared_box_predictor_640x640_coco14_sync.config config file unfortunately. Tried adding it into the config file and run into the same error.

GeorgiaA avatar Aug 29 '18 14:08 GeorgiaA

those "from checkpoint=false" tricks never worked for me.... though, it's always useful to ensure whether your TF version matches the version that was used for exporting the model models from the zoo was from v. 1.5 (last time i've checked) when the last TF-GPU is 1.8 or so

just run export model before training, it should help

Insertfunnylogin avatar Aug 30 '18 04:08 Insertfunnylogin

I get the same error with ssd_mobilenet_v1_fpn_coco and ssd_resnet_50_fpn_coco as well. Also there is not any " from_detection_checkpoint " in those config files. im using ubuntu 16.4 ang tensorflow 1.9 gpu version. what can i do to bypass the error?

farshadopencv avatar Sep 02 '18 03:09 farshadopencv

The opposite happened for me. Setting from_detection_checkpoint: true helped me resolve the error. I had it to false previously. This is for ssd_resnet101_fpn_ct_coco.config

ravikantgupta9 avatar Sep 07 '18 18:09 ravikantgupta9

@GeorgiaA did you find a solution to the probelm? It's kind of what I'm facing too.

karansomaiah avatar Sep 18 '18 20:09 karansomaiah

@karansomaiah sadly I didn't. I couldn't find any solution to it. I was only testing out various models so I didn't spend much time fretting over the problem. If you find anything please let me know.

GeorgiaA avatar Sep 18 '18 21:09 GeorgiaA

I was getting same error from past few hours. I started again with clean tensorflow repository and custom scripts as mentioned in the following blog and it worked. https://becominghuman.ai/tensorflow-object-detection-api-tutorial-training-and-evaluating-custom-object-detector-ed2594afcf73

Earlier it was not detecting model.ckpt as there is no file in the folder with this name but somehow it's working now. Value of variable in config file is fine_tune_checkpoint="path_to_model_dir/model.ckpt"

goravkaul avatar Sep 20 '18 09:09 goravkaul

Hey @goravkaul thanks for your reply. I did get it working by changing the value of "from_detection_checkpoint" to "true". Thank you for your suggestions.

@GeorgiaA I did get it working by changing the above values in the config file. Let me know if anyone is still facing issues. Also, I was facing this specifically with the fpn models in ssd only. So I'm training them with the train.py files in the legacy folder rather than the model_main.py

If you're using multiple GPUs, make sure to change "sync_replicas" to "true" as well.

karansomaiah avatar Sep 20 '18 17:09 karansomaiah

@ravikantgupta9 Same here. I was using ssd_resnet50_v1_fpn and setting from_detection_checkpoint to true resolved it. I added it separately as it wasn't there in the config file.

shivaniNK8 avatar Sep 28 '18 05:09 shivaniNK8