ns2250225 / python3_tf_slim_image_classify Goto Github PK
View Code? Open in Web Editor NEWPython3使用TF-Slim进行图像分类
Python3使用TF-Slim进行图像分类
在终端敲入 python train_image_classifier.py
--checkpoint_exclude_scopes=InceptionV3/Logits,InceptionV3/AuxLogits
--trainable_scopes=InceptionV3/Logits,InceptionV3/AuxLogits
这个是训练最后一层的fine tune, !!我想训练的可能是 最后三层!!,该如何fine tune呢,看了很久的源码,也没找到。
请帮忙解答一下.谢谢
我想训练全部层,而不只是最后一层。
所以我删去了trainable_scopes,
echo "1 epoch"
python slim/train_image_classifier.py \
--train_dir=train_log \
--dataset_name=gesture \
--train_image_size=256 \
--dataset_split_name=train \
--dataset_dir=/data/workspace/MobilenetV2_image_classify-master/data_prepare/pic \
--model_name="mobilenet_v2_140" \
--checkpoint_path=pretrained/mobilenet_v2_1.4_224.ckpt \
--checkpoint_exclude_scope=MobilenetV2/Logits, MobilenetV2/AuxLogits \
--max_number_of_steps=10000 \
--batch_size=16 \
--learning_rate=0.001 \
--learning_rate_decay_type=fixed \
--save_interval_secs=300 \
--save_summaries_secs=2 \
--log_every_n_steps=10 \
--optimizer=rmsprop \
--weight_decay=0.00004 \
--label_smoothing=0.1 \
--num_clones=1 \
--num_epochs_per_decay=2.5 \
--moving_average_decay=0.9999 \
--learning_rate_decay_factor=0.98 \
--preprocessing_name="inception_v2"
运行时会报错:
INFO:tensorflow:Restoring parameters from pretrained/mobilenet_v2_1.4_224.ckpt
INFO:tensorflow:Error reported to Coordinator: <class 'tensorflow.python.framework.errors_impl.InvalidArgumentError'>, Restoring from checkpoint failed. This is most likely due to a mismatch between the current graph and the graph from the checkpoint. Please ensure that you have not altered the graph expected based on the checkpoint. Original error:
Assign requires shapes of both tensors to match. lhs shape= [6] rhs shape= [1001]
[[Node: save/Assign_10 = Assign[T=DT_FLOAT, _class=["loc:@MobilenetV2/Logits/Conv2d_1c_1x1/biases"], use_locking=true, validate_shape=true, _device="/job:localhost/replica:0/task:0/device:CPU:0"](MobilenetV2/Logits/Conv2d_1c_1x1/biases, save/RestoreV2:10)]]
Caused by op 'save/Assign_10', defined at:
File "slim/train_image_classifier.py", line 587, in
tf.app.run()
File "/data/zhaowenlin/anaconda3/envs/tf10_mobilenet/lib/python3.6/site-packages/tensorflow/python/platform/app.py", line 125, in run
_sys.exit(main(argv))
File "slim/train_image_classifier.py", line 574, in main
init_fn=_get_init_fn(),
File "slim/train_image_classifier.py", line 372, in _get_init_fn
ignore_missing_vars=FLAGS.ignore_missing_vars)
File "/data/zhaowenlin/anaconda3/envs/tf10_mobilenet/lib/python3.6/site-packages/tensorflow/contrib/framework/python/ops/variables.py", line 695, in assign_from_checkpoint_fn
write_version=saver_pb2.SaverDef.V1)
File "/data/zhaowenlin/anaconda3/envs/tf10_mobilenet/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 1281, in init
self.build()
File "/data/zhaowenlin/anaconda3/envs/tf10_mobilenet/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 1293, in build
self._build(self._filename, build_save=True, build_restore=True)
File "/data/zhaowenlin/anaconda3/envs/tf10_mobilenet/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 1330, in _build
build_save=build_save, build_restore=build_restore)
File "/data/zhaowenlin/anaconda3/envs/tf10_mobilenet/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 778, in _build_internal
restore_sequentially, reshape)
File "/data/zhaowenlin/anaconda3/envs/tf10_mobilenet/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 419, in _AddRestoreOps
assign_ops.append(saveable.restore(saveable_tensors, shapes))
File "/data/zhaowenlin/anaconda3/envs/tf10_mobilenet/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 112, in restore
self.op.get_shape().is_fully_defined())
File "/data/zhaowenlin/anaconda3/envs/tf10_mobilenet/lib/python3.6/site-packages/tensorflow/python/ops/state_ops.py", line 216, in assign
validate_shape=validate_shape)
File "/data/zhaowenlin/anaconda3/envs/tf10_mobilenet/lib/python3.6/site-packages/tensorflow/python/ops/gen_state_ops.py", line 60, in assign
use_locking=use_locking, name=name)
File "/data/zhaowenlin/anaconda3/envs/tf10_mobilenet/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper
op_def=op_def)
File "/data/zhaowenlin/anaconda3/envs/tf10_mobilenet/lib/python3.6/site-packages/tensorflow/python/util/deprecation.py", line 454, in new_func
return func(*args, **kwargs)
File "/data/zhaowenlin/anaconda3/envs/tf10_mobilenet/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 3155, in create_op
op_def=op_def)
File "/data/zhaowenlin/anaconda3/envs/tf10_mobilenet/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1717, in init
self._traceback = tf_stack.extract_stack()
InvalidArgumentError (see above for traceback): Restoring from checkpoint failed. This is most likely due to a mismatch between the current graph and the graph from the checkpoint. Please ensure that you have not altered the graph expected based on the checkpoint. Original error:
Assign requires shapes of both tensors to match. lhs shape= [6] rhs shape= [1001]
[[Node: save/Assign_10 = Assign[T=DT_FLOAT, _class=["loc:@MobilenetV2/Logits/Conv2d_1c_1x1/biases"], use_locking=true, validate_shape=true, _device="/job:localhost/replica:0/task:0/device:CPU:0"](MobilenetV2/Logits/Conv2d_1c_1x1/biases, save/RestoreV2:10)]]
Traceback (most recent call last):
File "/data/zhaowenlin/anaconda3/envs/tf10_mobilenet/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1278, in _do_call
return fn(*args)
File "/data/zhaowenlin/anaconda3/envs/tf10_mobilenet/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1263, in _run_fn
options, feed_dict, fetch_list, target_list, run_metadata)
File "/data/zhaowenlin/anaconda3/envs/tf10_mobilenet/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1350, in _call_tf_sessionrun
run_metadata)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Assign requires shapes of both tensors to match. lhs shape= [6] rhs shape= [1001]
[[Node: save/Assign_10 = Assign[T=DT_FLOAT, _class=["loc:@MobilenetV2/Logits/Conv2d_1c_1x1/biases"], use_locking=true, validate_shape=true, _device="/job:localhost/replica:0/task:0/device:CPU:0"](MobilenetV2/Logits/Conv2d_1c_1x1/biases, save/RestoreV2:10)]]
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/data/zhaowenlin/anaconda3/envs/tf10_mobilenet/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 1725, in restore
{self.saver_def.filename_tensor_name: save_path})
File "/data/zhaowenlin/anaconda3/envs/tf10_mobilenet/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 877, in run
run_metadata_ptr)
File "/data/zhaowenlin/anaconda3/envs/tf10_mobilenet/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1100, in _run
feed_dict_tensor, options, run_metadata)
File "/data/zhaowenlin/anaconda3/envs/tf10_mobilenet/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1272, in _do_run
run_metadata)
File "/data/zhaowenlin/anaconda3/envs/tf10_mobilenet/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1291, in _do_call
raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Assign requires shapes of both tensors to match. lhs shape= [6] rhs shape= [1001]
[[Node: save/Assign_10 = Assign[T=DT_FLOAT, _class=["loc:@MobilenetV2/Logits/Conv2d_1c_1x1/biases"], use_locking=true, validate_shape=true, _device="/job:localhost/replica:0/task:0/device:CPU:0"](MobilenetV2/Logits/Conv2d_1c_1x1/biases, save/RestoreV2:10)]]
Caused by op 'save/Assign_10', defined at:
File "slim/train_image_classifier.py", line 587, in
tf.app.run()
File "/data/zhaowenlin/anaconda3/envs/tf10_mobilenet/lib/python3.6/site-packages/tensorflow/python/platform/app.py", line 125, in run
_sys.exit(main(argv))
File "slim/train_image_classifier.py", line 574, in main
init_fn=_get_init_fn(),
File "slim/train_image_classifier.py", line 372, in _get_init_fn
ignore_missing_vars=FLAGS.ignore_missing_vars)
File "/data/zhaowenlin/anaconda3/envs/tf10_mobilenet/lib/python3.6/site-packages/tensorflow/contrib/framework/python/ops/variables.py", line 695, in assign_from_checkpoint_fn
write_version=saver_pb2.SaverDef.V1)
File "/data/zhaowenlin/anaconda3/envs/tf10_mobilenet/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 1281, in init
self.build()
File "/data/zhaowenlin/anaconda3/envs/tf10_mobilenet/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 1293, in build
self._build(self._filename, build_save=True, build_restore=True)
File "/data/zhaowenlin/anaconda3/envs/tf10_mobilenet/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 1330, in _build
build_save=build_save, build_restore=build_restore)
File "/data/zhaowenlin/anaconda3/envs/tf10_mobilenet/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 778, in _build_internal
restore_sequentially, reshape)
File "/data/zhaowenlin/anaconda3/envs/tf10_mobilenet/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 419, in _AddRestoreOps
assign_ops.append(saveable.restore(saveable_tensors, shapes))
File "/data/zhaowenlin/anaconda3/envs/tf10_mobilenet/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 112, in restore
self.op.get_shape().is_fully_defined())
File "/data/zhaowenlin/anaconda3/envs/tf10_mobilenet/lib/python3.6/site-packages/tensorflow/python/ops/state_ops.py", line 216, in assign
validate_shape=validate_shape)
File "/data/zhaowenlin/anaconda3/envs/tf10_mobilenet/lib/python3.6/site-packages/tensorflow/python/ops/gen_state_ops.py", line 60, in assign
use_locking=use_locking, name=name)
File "/data/zhaowenlin/anaconda3/envs/tf10_mobilenet/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper
op_def=op_def)
File "/data/zhaowenlin/anaconda3/envs/tf10_mobilenet/lib/python3.6/site-packages/tensorflow/python/util/deprecation.py", line 454, in new_func
return func(*args, **kwargs)
File "/data/zhaowenlin/anaconda3/envs/tf10_mobilenet/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 3155, in create_op
op_def=op_def)
File "/data/zhaowenlin/anaconda3/envs/tf10_mobilenet/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1717, in init
self._traceback = tf_stack.extract_stack()
InvalidArgumentError (see above for traceback): Assign requires shapes of both tensors to match. lhs shape= [6] rhs shape= [1001]
[[Node: save/Assign_10 = Assign[T=DT_FLOAT, _class=["loc:@MobilenetV2/Logits/Conv2d_1c_1x1/biases"], use_locking=true, validate_shape=true, _device="/job:localhost/replica:0/task:0/device:CPU:0"](MobilenetV2/Logits/Conv2d_1c_1x1/biases, save/RestoreV2:10)]]
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "slim/train_image_classifier.py", line 587, in
tf.app.run()
File "/data/zhaowenlin/anaconda3/envs/tf10_mobilenet/lib/python3.6/site-packages/tensorflow/python/platform/app.py", line 125, in run
_sys.exit(main(argv))
File "slim/train_image_classifier.py", line 580, in main
sync_optimizer=optimizer if FLAGS.sync_replicas else None)
File "/data/zhaowenlin/anaconda3/envs/tf10_mobilenet/lib/python3.6/site-packages/tensorflow/contrib/slim/python/slim/learning.py", line 748, in train
master, start_standard_services=False, config=session_config) as sess:
File "/data/zhaowenlin/anaconda3/envs/tf10_mobilenet/lib/python3.6/contextlib.py", line 81, in enter
return next(self.gen)
File "/data/zhaowenlin/anaconda3/envs/tf10_mobilenet/lib/python3.6/site-packages/tensorflow/python/training/supervisor.py", line 1005, in managed_session
self.stop(close_summary_writer=close_summary_writer)
File "/data/zhaowenlin/anaconda3/envs/tf10_mobilenet/lib/python3.6/site-packages/tensorflow/python/training/supervisor.py", line 833, in stop
ignore_live_threads=ignore_live_threads)
File "/data/zhaowenlin/anaconda3/envs/tf10_mobilenet/lib/python3.6/site-packages/tensorflow/python/training/coordinator.py", line 389, in join
six.reraise(*self._exc_info_to_raise)
File "/data/zhaowenlin/anaconda3/envs/tf10_mobilenet/lib/python3.6/site-packages/six.py", line 693, in reraise
raise value
File "/data/zhaowenlin/anaconda3/envs/tf10_mobilenet/lib/python3.6/site-packages/tensorflow/python/training/supervisor.py", line 994, in managed_session
start_standard_services=start_standard_services)
File "/data/zhaowenlin/anaconda3/envs/tf10_mobilenet/lib/python3.6/site-packages/tensorflow/python/training/supervisor.py", line 731, in prepare_or_wait_for_session
init_feed_dict=self._init_feed_dict, init_fn=self._init_fn)
File "/data/zhaowenlin/anaconda3/envs/tf10_mobilenet/lib/python3.6/site-packages/tensorflow/python/training/session_manager.py", line 289, in prepare_session
init_fn(sess)
File "/data/zhaowenlin/anaconda3/envs/tf10_mobilenet/lib/python3.6/site-packages/tensorflow/contrib/framework/python/ops/variables.py", line 697, in callback
saver.restore(session, model_path)
File "/data/zhaowenlin/anaconda3/envs/tf10_mobilenet/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 1759, in restore
err, "a mismatch between the current graph and the graph")
tensorflow.python.framework.errors_impl.InvalidArgumentError: Restoring from checkpoint failed. This is most likely due to a mismatch between the current graph and the graph from the checkpoint. Please ensure that you have not altered the graph expected based on the checkpoint. Original error:
Assign requires shapes of both tensors to match. lhs shape= [6] rhs shape= [1001]
[[Node: save/Assign_10 = Assign[T=DT_FLOAT, _class=["loc:@MobilenetV2/Logits/Conv2d_1c_1x1/biases"], use_locking=true, validate_shape=true, _device="/job:localhost/replica:0/task:0/device:CPU:0"](MobilenetV2/Logits/Conv2d_1c_1x1/biases, save/RestoreV2:10)]]
Caused by op 'save/Assign_10', defined at:
File "slim/train_image_classifier.py", line 587, in
tf.app.run()
File "/data/zhaowenlin/anaconda3/envs/tf10_mobilenet/lib/python3.6/site-packages/tensorflow/python/platform/app.py", line 125, in run
_sys.exit(main(argv))
File "slim/train_image_classifier.py", line 574, in main
init_fn=_get_init_fn(),
File "slim/train_image_classifier.py", line 372, in _get_init_fn
ignore_missing_vars=FLAGS.ignore_missing_vars)
File "/data/zhaowenlin/anaconda3/envs/tf10_mobilenet/lib/python3.6/site-packages/tensorflow/contrib/framework/python/ops/variables.py", line 695, in assign_from_checkpoint_fn
write_version=saver_pb2.SaverDef.V1)
File "/data/zhaowenlin/anaconda3/envs/tf10_mobilenet/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 1281, in init
self.build()
File "/data/zhaowenlin/anaconda3/envs/tf10_mobilenet/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 1293, in build
self._build(self._filename, build_save=True, build_restore=True)
File "/data/zhaowenlin/anaconda3/envs/tf10_mobilenet/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 1330, in _build
build_save=build_save, build_restore=build_restore)
File "/data/zhaowenlin/anaconda3/envs/tf10_mobilenet/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 778, in _build_internal
restore_sequentially, reshape)
File "/data/zhaowenlin/anaconda3/envs/tf10_mobilenet/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 419, in _AddRestoreOps
assign_ops.append(saveable.restore(saveable_tensors, shapes))
File "/data/zhaowenlin/anaconda3/envs/tf10_mobilenet/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 112, in restore
self.op.get_shape().is_fully_defined())
File "/data/zhaowenlin/anaconda3/envs/tf10_mobilenet/lib/python3.6/site-packages/tensorflow/python/ops/state_ops.py", line 216, in assign
validate_shape=validate_shape)
File "/data/zhaowenlin/anaconda3/envs/tf10_mobilenet/lib/python3.6/site-packages/tensorflow/python/ops/gen_state_ops.py", line 60, in assign
use_locking=use_locking, name=name)
File "/data/zhaowenlin/anaconda3/envs/tf10_mobilenet/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper
op_def=op_def)
File "/data/zhaowenlin/anaconda3/envs/tf10_mobilenet/lib/python3.6/site-packages/tensorflow/python/util/deprecation.py", line 454, in new_func
return func(*args, **kwargs)
File "/data/zhaowenlin/anaconda3/envs/tf10_mobilenet/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 3155, in create_op
op_def=op_def)
File "/data/zhaowenlin/anaconda3/envs/tf10_mobilenet/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1717, in init
self._traceback = tf_stack.extract_stack()
InvalidArgumentError (see above for traceback): Restoring from checkpoint failed. This is most likely due to a mismatch between the current graph and the graph from the checkpoint. Please ensure that you have not altered the graph expected based on the checkpoint. Original error:
Assign requires shapes of both tensors to match. lhs shape= [6] rhs shape= [1001]
[[Node: save/Assign_10 = Assign[T=DT_FLOAT, _class=["loc:@MobilenetV2/Logits/Conv2d_1c_1x1/biases"], use_locking=true, validate_shape=true, _device="/job:localhost/replica:0/task:0/device:CPU:0"](MobilenetV2/Logits/Conv2d_1c_1x1/biases, save/RestoreV2:10)]]
这里用的模型是官方提供的。
请问我应该怎么解决这个问题?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.