models icon indicating copy to clipboard operation
models copied to clipboard

TFslim and TF-native implementaions (per the documentation) do not match up!

Open Steven-N-Hart opened this issue 9 years ago • 7 comments

Trying to get results between TFslim & native TF to match up when I ran across an issue with significant differences in accuracy on the flowers dataset when run using TFslim documentation and TF.

First, I run the initial download and train instructions from TFslim

PRETRAINED_CHECKPOINT_DIR=/tmp/checkpoints
TRAIN_DIR=/tmp/flowers-models/inception_v3
DATASET_DIR=/tmp/flowers

mkdir ${PRETRAINED_CHECKPOINT_DIR}
wget http://download.tensorflow.org/models/inception_v3_2016_08_28.tar.gz
tar -xvf inception_v3_2016_08_28.tar.gz
mv inception_v3.ckpt ${PRETRAINED_CHECKPOINT_DIR}/inception_v3.ckpt
rm inception_v3_2016_08_28.tar.gz

python download_and_convert_data.py \
  --dataset_name=flowers \
  --dataset_dir=${DATASET_DIR}
  
time python train_image_classifier.py \
  --train_dir=${TRAIN_DIR} \
  --dataset_name=flowers \
  --dataset_split_name=train \
  --dataset_dir=${DATASET_DIR} \
  --model_name=inception_v3 \
  --checkpoint_path=${PRETRAINED_CHECKPOINT_DIR}/inception_v3.ckpt \
  --checkpoint_exclude_scopes=InceptionV3/Logits,InceptionV3/AuxLogits \
  --trainable_scopes=InceptionV3/Logits,InceptionV3/AuxLogits \
  --max_number_of_steps=1000 \
  --batch_size=32 \
  --learning_rate=0.01 \
  --log_every_n_steps=100
STDERR log is here # I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcublas.so.8.0 locally # I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcudnn.so.5 locally # I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcufft.so.8.0 locally # I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcuda.so.1 locally # I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcurand.so.8.0 locally # 0:daisy # 1:dandelion # 2:roses # 3:sunflowers # 4:tulips # INFO:tensorflow:Summary name /clone_loss is illegal; using clone_loss instead. # INFO:tensorflow:Fine-tuning from /tmp/checkpoints/inception_v3.ckpt # W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE3 instructions, but these are available on your machine and could speed up CPU computations. # W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations. # W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations. # W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations. # W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations. # W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations. # I tensorflow/core/common_runtime/gpu/gpu_device.cc:885] Found device 0 with properties: # name: GeForce GTX 1080 # major: 6 minor: 1 memoryClockRate (GHz) 1.7335 # pciBusID 0000:0a:00.0 # Total memory: 7.92GiB # Free memory: 7.70GiB # W tensorflow/stream_executor/cuda/cuda_driver.cc:590] creating context when one is currently active; existing: 0x8c80370 # I tensorflow/core/common_runtime/gpu/gpu_device.cc:885] Found device 1 with properties: # name: GeForce GTX 1080 # major: 6 minor: 1 memoryClockRate (GHz) 1.7335 # pciBusID 0000:09:00.0 # Total memory: 7.92GiB # Free memory: 7.81GiB # W tensorflow/stream_executor/cuda/cuda_driver.cc:590] creating context when one is currently active; existing: 0x8dde3b0 # I tensorflow/core/common_runtime/gpu/gpu_device.cc:885] Found device 2 with properties: # name: GeForce GTX 1080 # major: 6 minor: 1 memoryClockRate (GHz) 1.7335 # pciBusID 0000:06:00.0 # Total memory: 7.92GiB # Free memory: 7.81GiB # W tensorflow/stream_executor/cuda/cuda_driver.cc:590] creating context when one is currently active; existing: 0x81abf00 # I tensorflow/core/common_runtime/gpu/gpu_device.cc:885] Found device 3 with properties: # name: GeForce GTX 1080 # major: 6 minor: 1 memoryClockRate (GHz) 1.7335 # pciBusID 0000:05:00.0 # Total memory: 7.92GiB # Free memory: 7.69GiB # I tensorflow/core/common_runtime/gpu/gpu_device.cc:906] DMA: 0 1 2 3 # I tensorflow/core/common_runtime/gpu/gpu_device.cc:916] 0: Y Y Y Y # I tensorflow/core/common_runtime/gpu/gpu_device.cc:916] 1: Y Y Y Y # I tensorflow/core/common_runtime/gpu/gpu_device.cc:916] 2: Y Y Y Y # I tensorflow/core/common_runtime/gpu/gpu_device.cc:916] 3: Y Y Y Y # I tensorflow/core/common_runtime/gpu/gpu_device.cc:975] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 1080, pci bus id: 0000:0a:00.0) # I tensorflow/core/common_runtime/gpu/gpu_device.cc:975] Creating TensorFlow device (/gpu:1) -> (device: 1, name: GeForce GTX 1080, pci bus id: 0000:09:00.0) # I tensorflow/core/common_runtime/gpu/gpu_device.cc:975] Creating TensorFlow device (/gpu:2) -> (device: 2, name: GeForce GTX 1080, pci bus id: 0000:06:00.0) # I tensorflow/core/common_runtime/gpu/gpu_device.cc:975] Creating TensorFlow device (/gpu:3) -> (device: 3, name: GeForce GTX 1080, pci bus id: 0000:05:00.0) # INFO:tensorflow:Starting Session. # INFO:tensorflow:Starting Queues. # INFO:tensorflow:global_step/sec: 0 # INFO:tensorflow:global step 100: loss = 1.1246 (0.21 sec/step) # INFO:tensorflow:global step 200: loss = 0.7643 (0.21 sec/step) # INFO:tensorflow:global step 300: loss = 0.6426 (0.21 sec/step) # INFO:tensorflow:global step 400: loss = 0.6626 (0.21 sec/step) # INFO:tensorflow:global step 500: loss = 0.7226 (0.22 sec/step) # INFO:tensorflow:global step 600: loss = 0.7136 (0.22 sec/step) # INFO:tensorflow:global step 700: loss = 0.9115 (0.22 sec/step) # INFO:tensorflow:global step 800: loss = 0.8113 (0.22 sec/step) # INFO:tensorflow:global step 900: loss = 0.9217 (0.22 sec/step) # INFO:tensorflow:global step 1000: loss = 0.8763 (0.22 sec/step) # INFO:tensorflow:Stopping Training. # INFO:tensorflow:Finished training! Saving model to disk. # real 3m55.049s # user 18m39.024s # sys 2m33.808s

Then I evaluate my model

python eval_image_classifier.py \
  --checkpoint_path=${TRAIN_DIR} \
  --eval_dir=${TRAIN_DIR} \
  --dataset_name=flowers \
  --dataset_split_name=validation \
  --dataset_dir=${DATASET_DIR} \
  --model_name=inception_v3
I get: eval/Accuracy[0.755] # I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcublas.so.8.0 locally # I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcudnn.so.5 locally # I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcufft.so.8.0 locally # I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcuda.so.1 locally # I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcurand.so.8.0 locally # 0:daisy # 1:dandelion # 2:roses # 3:sunflowers # 4:tulips # INFO:tensorflow:Scale of 0 disables regularizer. # INFO:tensorflow:Evaluating /tmp/flowers-models/inception_v3/model.ckpt-1000 # WARNING:tensorflow:From /home/m087494/anaconda3/lib/python3.6/site-packages/tensorflow/contrib/training/python/training/evaluation.py:298: SummaryWriter.__init__ (from tensorflow.python.training.summary_io) is deprecated and will be removed after 2016-11-30. # Instructions for updating: # Please switch to tf.summary.FileWriter. The interface and behavior is the same; this is just a rename. # INFO:tensorflow:Starting evaluation at 2017-04-07-18:53:57 # W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE3 instructions, but these are available on your machine and could speed up CPU computations. # W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations. # W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations. # W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations. # W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations. # W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations. # I tensorflow/core/common_runtime/gpu/gpu_device.cc:885] Found device 0 with properties: # name: GeForce GTX 1080 # major: 6 minor: 1 memoryClockRate (GHz) 1.7335 # pciBusID 0000:0a:00.0 # Total memory: 7.92GiB # Free memory: 7.70GiB # W tensorflow/stream_executor/cuda/cuda_driver.cc:590] creating context when one is currently active; existing: 0x4bd2840 # I tensorflow/core/common_runtime/gpu/gpu_device.cc:885] Found device 1 with properties: # name: GeForce GTX 1080 # major: 6 minor: 1 memoryClockRate (GHz) 1.7335 # pciBusID 0000:09:00.0 # Total memory: 7.92GiB # Free memory: 7.81GiB # W tensorflow/stream_executor/cuda/cuda_driver.cc:590] creating context when one is currently active; existing: 0x4bd61c0 # I tensorflow/core/common_runtime/gpu/gpu_device.cc:885] Found device 2 with properties: # name: GeForce GTX 1080 # major: 6 minor: 1 memoryClockRate (GHz) 1.7335 # pciBusID 0000:06:00.0 # Total memory: 7.92GiB # Free memory: 7.81GiB # W tensorflow/stream_executor/cuda/cuda_driver.cc:590] creating context when one is currently active; existing: 0x4bd9b40 # I tensorflow/core/common_runtime/gpu/gpu_device.cc:885] Found device 3 with properties: # name: GeForce GTX 1080 # major: 6 minor: 1 memoryClockRate (GHz) 1.7335 # pciBusID 0000:05:00.0 # Total memory: 7.92GiB # Free memory: 7.69GiB # I tensorflow/core/common_runtime/gpu/gpu_device.cc:906] DMA: 0 1 2 3 # I tensorflow/core/common_runtime/gpu/gpu_device.cc:916] 0: Y Y Y Y # I tensorflow/core/common_runtime/gpu/gpu_device.cc:916] 1: Y Y Y Y # I tensorflow/core/common_runtime/gpu/gpu_device.cc:916] 2: Y Y Y Y # I tensorflow/core/common_runtime/gpu/gpu_device.cc:916] 3: Y Y Y Y # I tensorflow/core/common_runtime/gpu/gpu_device.cc:975] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 1080, pci bus id: 0000:0a:00.0) # I tensorflow/core/common_runtime/gpu/gpu_device.cc:975] Creating TensorFlow device (/gpu:1) -> (device: 1, name: GeForce GTX 1080, pci bus id: 0000:09:00.0) # I tensorflow/core/common_runtime/gpu/gpu_device.cc:975] Creating TensorFlow device (/gpu:2) -> (device: 2, name: GeForce GTX 1080, pci bus id: 0000:06:00.0) # I tensorflow/core/common_runtime/gpu/gpu_device.cc:975] Creating TensorFlow device (/gpu:3) -> (device: 3, name: GeForce GTX 1080, pci bus id: 0000:05:00.0) # INFO:tensorflow:Evaluation [1/4] # INFO:tensorflow:Evaluation [2/4] # INFO:tensorflow:Evaluation [3/4] # INFO:tensorflow:Evaluation [4/4] # I tensorflow/core/kernels/logging_ops.cc:79] eval/Accuracy[0.755] # INFO:tensorflow:Finished evaluation at 2017-04-07-18:54:05

Hmm. That looks like crap!
However, the results are quite different if I start here.

wget 'http://download.tensorflow.org/example_images/flower_photos.tgz'
tar xvzf flower_photos.tgz
mv flower_photos /tmp/flower_photos

#build the bazel env
bazel build -c opt --copt=-mavx --copt=-mavx2 --copt=-mfma --copt=-mfpmath=both --copt=-msse4.2 --config=cuda tensorflow/examples/image_retraining:retrain
## several logging messages (INFO and WARNING)

time bazel-bin/tensorflow/examples/image_retraining/retrain \
  --image_dir /tmp/flower_photos \
  --train_batch_size 32 \
  --learning_rate=0.01 \
  --how_many_training_steps 4000 \
  --summaries_dir /tmp/flower_summaries

  # writes output_labels.txt and output_graph.pb to /tmp

# ... # 2017-04-07 14:56:40.753382: Step 3950: Validation accuracy = 95.0% (N=100) # 2017-04-07 14:56:41.195889: Step 3960: Train accuracy = 96.9% # 2017-04-07 14:56:41.196014: Step 3960: Cross entropy = 0.129627 # 2017-04-07 14:56:41.333375: Step 3960: Validation accuracy = 88.0% (N=100) # 2017-04-07 14:56:41.787402: Step 3970: Train accuracy = 100.0% # 2017-04-07 14:56:41.787512: Step 3970: Cross entropy = 0.100659 # 2017-04-07 14:56:41.897388: Step 3970: Validation accuracy = 93.0% (N=100) # 2017-04-07 14:56:42.143706: Step 3980: Train accuracy = 93.8% # 2017-04-07 14:56:42.143822: Step 3980: Cross entropy = 0.201175 # 2017-04-07 14:56:42.277915: Step 3980: Validation accuracy = 92.0% (N=100) # 2017-04-07 14:56:42.658290: Step 3990: Train accuracy = 93.8% # 2017-04-07 14:56:42.658371: Step 3990: Cross entropy = 0.162338 # 2017-04-07 14:56:42.739404: Step 3990: Validation accuracy = 93.0% (N=100) # 2017-04-07 14:56:43.036147: Step 3999: Train accuracy = 100.0% # 2017-04-07 14:56:43.036214: Step 3999: Cross entropy = 0.162201 # 2017-04-07 14:56:43.146753: Step 3999: Validation accuracy = 95.0% (N=100) # Final test accuracy = 93.1% (N=378) # Converted 2 variables to const ops.
Now see if the slim implementation will improve
PRETRAINED_CHECKPOINT_DIR=/tmp/checkpoints
TRAIN_DIR=/tmp
DATASET_DIR=/tmp/flowers

python eval_image_classifier.py \
  --checkpoint_path=${TRAIN_DIR} \
  --eval_dir=${TRAIN_DIR} \
  --dataset_name=flowers \
  --dataset_split_name=validation \
  --dataset_dir=${DATASET_DIR} \
  --model_name=inception_v3
# I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcublas.so.8.0 locally # I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcudnn.so.5 locally # I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcufft.so.8.0 locally # I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcuda.so.1 locally # I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcurand.so.8.0 locally # 0:daisy # 1:dandelion # 2:roses # 3:sunflowers # 4:tulips # INFO:tensorflow:Scale of 0 disables regularizer. # INFO:tensorflow:Evaluating None # WARNING:tensorflow:From /home/m087494/anaconda3/lib/python3.6/site-packages/tensorflow/contrib/training/python/training/evaluation.py:298: SummaryWriter.__init__ (from tensorflow.python.training.summary_io) is deprecated and will be removed after 2016-11-30. # Instructions for updating: # Please switch to tf.summary.FileWriter. The interface and behavior is the same; this is just a rename. # INFO:tensorflow:Starting evaluation at 2017-04-07-20:12:00 # W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE3 instructions, but these are available on your machine and could speed up CPU computations. # W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations. # W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations. # W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations. # W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations. # W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations. # I tensorflow/core/common_runtime/gpu/gpu_device.cc:885] Found device 0 with properties: # name: GeForce GTX 1080 # major: 6 minor: 1 memoryClockRate (GHz) 1.7335 # pciBusID 0000:0a:00.0 # Total memory: 7.92GiB # Free memory: 7.70GiB # W tensorflow/stream_executor/cuda/cuda_driver.cc:590] creating context when one is currently active; existing: 0x55ecf70 # I tensorflow/core/common_runtime/gpu/gpu_device.cc:885] Found device 1 with properties: # name: GeForce GTX 1080 # major: 6 minor: 1 memoryClockRate (GHz) 1.7335 # pciBusID 0000:09:00.0 # Total memory: 7.92GiB # Free memory: 7.81GiB # W tensorflow/stream_executor/cuda/cuda_driver.cc:590] creating context when one is currently active; existing: 0x5612370 # I tensorflow/core/common_runtime/gpu/gpu_device.cc:885] Found device 2 with properties: # name: GeForce GTX 1080 # major: 6 minor: 1 memoryClockRate (GHz) 1.7335 # pciBusID 0000:06:00.0 # Total memory: 7.92GiB # Free memory: 7.81GiB # W tensorflow/stream_executor/cuda/cuda_driver.cc:590] creating context when one is currently active; existing: 0x5615cf0 # I tensorflow/core/common_runtime/gpu/gpu_device.cc:885] Found device 3 with properties: # name: GeForce GTX 1080 # major: 6 minor: 1 memoryClockRate (GHz) 1.7335 # pciBusID 0000:05:00.0 # Total memory: 7.92GiB # Free memory: 7.69GiB # I tensorflow/core/common_runtime/gpu/gpu_device.cc:906] DMA: 0 1 2 3 # I tensorflow/core/common_runtime/gpu/gpu_device.cc:916] 0: Y Y Y Y # I tensorflow/core/common_runtime/gpu/gpu_device.cc:916] 1: Y Y Y Y # I tensorflow/core/common_runtime/gpu/gpu_device.cc:916] 2: Y Y Y Y # I tensorflow/core/common_runtime/gpu/gpu_device.cc:916] 3: Y Y Y Y # I tensorflow/core/common_runtime/gpu/gpu_device.cc:975] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 1080, pci bus id: 0000:0a:00.0) # I tensorflow/core/common_runtime/gpu/gpu_device.cc:975] Creating TensorFlow device (/gpu:1) -> (device: 1, name: GeForce GTX 1080, pci bus id: 0000:09:00.0) # I tensorflow/core/common_runtime/gpu/gpu_device.cc:975] Creating TensorFlow device (/gpu:2) -> (device: 2, name: GeForce GTX 1080, pci bus id: 0000:06:00.0) # I tensorflow/core/common_runtime/gpu/gpu_device.cc:975] Creating TensorFlow device (/gpu:3) -> (device: 3, name: GeForce GTX 1080, pci bus id: 0000:05:00.0) # INFO:tensorflow:Evaluation [1/4] # INFO:tensorflow:Evaluation [2/4] # INFO:tensorflow:Evaluation [3/4] # INFO:tensorflow:Evaluation [4/4] # I tensorflow/core/kernels/logging_ops.cc:79] eval/Accuracy[0.2175] # INFO:tensorflow:Finished evaluation at 2017-04-07-20:12:07

Now I get an even WORSE eval/Accuracy[0.2175].

So there is something fishy going on here. Note, I had to comment out the Recall_5 portion of the eval_image_classifier.py so it would work

So my questions are:

  1. What gives with the TFSlim vs Native? Which Example is wrong?
  2. When running retrain.py under bazel, I was only using 1 of 4 possible GPUs, that I know TF is aware of (see STDERRs in Details).
Machine SPECS bazel build 0.4.5 Python 3.6.0 :: Anaconda 4.3.1 (64-bit) TFSlim commit 405bb623bfdc5a1bf97550727272f43970414560 Tensorflow 1.0 commit f8dce81aeaff40dc78d398741854ad8766806f91

Steven-N-Hart avatar Apr 07 '17 20:04 Steven-N-Hart

@Steven-N-Hart , i am also facing similar issue i think #1314 . In my case i used TF-slim checkpoints to create a protobuf file. Then this protobuf file is retrained using the retrain.py.

ghost avatar Apr 10 '17 04:04 ghost

After running the documented code to finetune the inceptionv3 model on the flowers dataset I too am getting very poor accuracy (0.2175)

blake-varden avatar Apr 17 '17 18:04 blake-varden

I think I know one reason for the discrepancy between the example on the tensforflow tutorial page and the TF-Slim page. The TensorFlow tutorial uses inception-2015-12-05.tgz, whereas the TF-Slim implementation uses inception_v3_2016_08_28.tar.gz.

Could it be that the one from 2016 is not trained as deep as the 2015 one?

Steven-N-Hart avatar Apr 18 '17 18:04 Steven-N-Hart

Here are the Graphs for both models. It looks like the new one is missing a layer? Why do they look so different? This is from the TFSlim page: slim This is from the TF website: retrain_py

Steven-N-Hart avatar Jul 10 '17 21:07 Steven-N-Hart

@Steven-N-Hart What layer is the new (top) one missing?

By the way, as I wrote in tensorflow#11181, the dimensions of the last FC layer in the two models do not match. The 2016 model maps from 2048 to 1001 (which looks normal), but the 2015 one maps from 2048 to 1008. Would this observation help at all?

korrawat avatar Jul 11 '17 02:07 korrawat

The top one is missing the one described as pool_3.

Steven-N-Hart avatar Jul 11 '17 13:07 Steven-N-Hart

This question is better asked on StackOverflow since it is not a bug or feature request. There is also a larger community that reads questions there. Please also see #1314 . Thanks!

karmel avatar Feb 24 '18 18:02 karmel