GantMan / GantMan/nsfw_model

Finetune error: layer keras_layer expects 262 weights, but the saved weights have 260 elements

Open
#77 1 comment 0 reactions 0 assignees View on GitHub
training
Dominant language
Python
Stars
2.1k
Forks
303
PR merge metrics
No merged PRs in 30d

Description

I want to feed more samples base on trained model, to do some fine tune. But I got Error:

`Traceback (most recent call last):
File "make_nsfw_model.py", line 273, in
run_main()
File "make_nsfw_model.py", line 269, in run_main
app.run(main)
File "/Users/bill/lab/py/nsfw_model/venv/lib/python3.7/site-packages/absl/app.py", line 300, in run
_run_main(main, args)
File "/Users/bill/lab/py/nsfw_model/venv/lib/python3.7/site-packages/absl/app.py", line 251, in _run_main
sys.exit(main(argv))
File "make_nsfw_model.py", line 197, in main
FLAGS.tfhub_module, image_dir, hparams, FLAGS.image_size, FLAGS.saved_model_dir)
File "/Users/bill/lab/py/nsfw_model/training/make_nsfw_model_lib.py", line 427, in make_image_classifier
model.load_weights(existingWeightsPath)
File "/Users/bill/lab/py/nsfw_model/venv/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/training.py", line 234, in load_weights
return super(Model, self).load_weights(filepath, by_name, skip_mismatch)
File "/Users/bill/lab/py/nsfw_model/venv/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/network.py", line 1222, in load_weights
hdf5_format.load_weights_from_hdf5_group(f, self.layers)
File "/Users/bill/lab/py/nsfw_model/venv/lib/python3.7/site-packages/tensorflow_core/python/keras/saving/hdf5_format.py", line 701, in load_weights_from_hdf5_group
str(len(weight_values)) + ' elements.')
ValueError: Layer #0 (named "keras_layer" in the current model) was found to correspond to layer keras_layer in the save file. However the new layer keras_layer expects 262 weights, but the saved weights have 260 elements.`

My command is:
`python3 make_nsfw_model.py --image_dir /nsfw/training --image_size 224 --saved_model_dir /Users/bill/lab/nsfw/mobilenet_v2_140_224 --labels_output_file /nsfw/mobilenet_v2_140_224/class_labels.txt --tfhub_module https://tfhub.dev/google/imagenet/mobilenet_v2_140_224/classification/4 --tflite_output_file /nsfw/saved_model.tflite --train_epochs 3 --batch_size 32 --do_fine_tuning --learning_rate 0.001 --dropout_rate 0.0 --momentum 0.9`

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at make_nsfw_model.py around line 197 and training/make_nsfw_model_lib.py around line 427, where model.load_weights(existingWeightsPath) is called. Reproduce the supplied fine-tuning command and inspect the saved weights alongside the TensorFlow Hub module configuration. Done means the existing weights load without the keras_layer mismatch and fine-tuning completes.

Written by the indexing model from the issue text.

Assessment

Tech stack
keras, python, tensorflow
Domain
machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.