Hi!
I try to train my own datasets with your pre-trained weights.
First I set load_weights=True in cfg.py, then an error occurs in advanced_east.py as follow:
Traceback (most recent call last):
File "D:/Workspace/Ad_new/advanced_east.py", line 17, in main
east_network.load_weights(cfg.saved_model_weights_file_path)
File "D:\ProgramData\Anaconda3\envs\gpu\lib\site-packages\tensorflow\python\keras\engine\network.py", line 1391, in load_weights
saving.load_weights_from_hdf5_group(f, self.layers)
File "D:\ProgramData\Anaconda3\envs\gpu\lib\site-packages\tensorflow\python\keras\engine\saving.py", line 732, in load_weights_from_hdf5_group
' layers.')
ValueError: You are trying to load a weight file containing 30 layers into a model with 1 layers.
According to stackoverflow, I rewrite advanced_east.py :
import os
from tensorflow.python.keras.callbacks import EarlyStopping, ModelCheckpoint
from tensorflow.python.keras.optimizers import Adam
from tensorflow.python.keras.models import load_model
from tensorflow.python.keras.models import model_from_json
import cfg
from network import East
from losses import quad_loss
from data_generator import gen
east = East()
east_network = east.east_network()
if cfg.load_weights and os.path.exists(cfg.saved_model_weights_file_path):
east_network.load_weights(cfg.saved_model_weights_file_path, by_name=True)
json_string = east_network.to_json()
east_network = model_from_json(json_string)
east_network.summary()
east_network.compile(loss=quad_loss, optimizer=Adam(lr=cfg.lr,
# clipvalue=cfg.clipvalue,
decay=cfg.decay))
east_network.fit_generator(generator=gen(),
steps_per_epoch=cfg.steps_per_epoch,
epochs=cfg.epoch_num,
validation_data=gen(is_val=True),
validation_steps=cfg.validation_steps,
verbose=1,
# use_multiprocessing=True,
initial_epoch=cfg.initial_epoch,
callbacks=[
EarlyStopping(patience=cfg.patience, verbose=1),
ModelCheckpoint(filepath=cfg.model_weights_path,
save_best_only=False,
save_weights_only=True,
verbose=1)])
east_network.save(cfg.saved_model_file_path)
east_network.save_weights(cfg.saved_model_weights_file_path)
After then, my training process started successfully.
While I tried to predict images with my trained weights east_model_weights_3T736.h5 in folder saved_model , the error showing up again:
Traceback (most recent call last):
File "D:/Workspace/Ad_new/test_img.py", line 163, in
main()
File "D:/Workspace/Ad_new/test_img.py", line 137, in main
east_detect.load_weights("saved_model/east_model_weights_3T736.h5")
File "D:\ProgramData\Anaconda3\envs\gpu\lib\site-packages\tensorflow\python\keras\engine\network.py", line 1391, in load_weights
saving.load_weights_from_hdf5_group(f, self.layers)
File "D:\ProgramData\Anaconda3\envs\gpu\lib\site-packages\tensorflow\python\keras\engine\saving.py", line 732, in load_weights_from_hdf5_group
' layers.')
ValueError: You are trying to load a weight file containing 1 layers into a model with 30 layers.
I wanted to use the same solution and code as follow:
east = East()
east_detect = east.east_network()
east_detect.load_weights("saved_model/east_model_weights_3T736.h5", by_name=True)
json_string = east_detect.to_json()
east_detect = model_from_json(json_string)
Here occurs new error:
File "D:/Workspace/Ad_new/test_img.py", line 163, in
main()
File "D:/Workspace/Ad_new/test_img.py", line 130, in main
east_detect.load_weights("saved_model/east_model_weights_3T736.h5", by_name=True)
File "D:\ProgramData\Anaconda3\envs\gpu\lib\site-packages\tensorflow\python\keras\engine\network.py", line 1389, in load_weights
saving.load_weights_from_hdf5_group_by_name(f, self.layers)
File "D:\ProgramData\Anaconda3\envs\gpu\lib\site-packages\tensorflow\python\keras\engine\saving.py", line 810, in load_weights_from_hdf5_group_by_name
K.batch_set_value(weight_value_tuples)
File "D:\ProgramData\Anaconda3\envs\gpu\lib\site-packages\tensorflow\python\keras\backend.py", line 2711, in batch_set_value
assign_op = x.assign(assign_placeholder)
File "D:\ProgramData\Anaconda3\envs\gpu\lib\site-packages\tensorflow\python\ops\resource_variable_ops.py", line 945, in assign
self._shape.assert_is_compatible_with(value_tensor.shape)
File "D:\ProgramData\Anaconda3\envs\gpu\lib\site-packages\tensorflow\python\framework\tensor_shape.py", line 847, in assert_is_compatible_with
raise ValueError("Shapes %s and %s are incompatible" % (self, other))
ValueError: Shapes (128,) and (1024,) are incompatible
Am I using a wrong way loading or saving weights? And is there anyone else facing the same problem?