我正在构建模型来训练frcnn卷积神经网络,问题是在建立模型时,它说我有一个错误,我怀疑这可能是由于tensorflow版本的不兼容。
下面的代码(错误第4行):
# define the RPN, built on the base layers
num_anchors = len(C.anchor_box_scales) * len(C.anchor_box_ratios) # 9
rpn = rpn_layer(shared_layers, num_anchors)
classifier = classifier_layer(shared_layers, roi_input, C.num_rois, nb_classes=len(classes_count))
model_rpn = Model(img_input, rpn[:2])
model_classifier = Model([img_input, roi_input], classifier)
# this is a model that holds both the RPN and the classifier, used to load/save weights for the models
model_all = Model([img_input, roi_input], rpn[:2] + classifier)
# Because the google colab can only run the session several hours one time (then you need to connect again),
# we need to save the model and load the model to continue training
if not os.path.isfile(C.model_path):
#If this is the begin of the training, load the pre-traind base network such as vgg-16
try:
print('This is the first time of your training')
print('loading weights from {}'.format(C.base_net_weights))
model_rpn.load_weights(C.base_net_weights, by_name=True)
model_classifier.load_weights(C.base_net_weights, by_name=True)
except:
print('Could not load pretrained model weights. Weights can be found in the keras application folder \
https://github.com/fchollet/keras/tree/master/keras/applications')
# Create the record.csv file to record losses, acc and mAP
record_df = pd.DataFrame(columns=['mean_overlapping_bboxes', 'class_acc', 'loss_rpn_cls', 'loss_rpn_regr', 'loss_class_cls', 'loss_class_regr', 'curr_loss', 'elapsed_time', 'mAP'])
else:
# If this is a continued training, load the trained model from before
print('Continue training based on previous trained model')
print('Loading weights from {}'.format(C.model_path))
model_rpn.load_weights(C.model_path, by_name=True)
model_classifier.load_weights(C.model_path, by_name=True)
# Load the records
record_df = pd.read_csv(record_path)
r_mean_overlapping_bboxes = record_df['mean_overlapping_bboxes']
r_class_acc = record_df['class_acc']
r_loss_rpn_cls = record_df['loss_rpn_cls']
r_loss_rpn_regr = record_df['loss_rpn_regr']
r_loss_class_cls = record_df['loss_class_cls']
r_loss_class_regr = record_df['loss_class_regr']
r_curr_loss = record_df['curr_loss']
r_elapsed_time = record_df['elapsed_time']
r_mAP = record_df['mAP']
print('Already train %dK batches'% (len(record_df)))这就是输出:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-55-039b2b159de7> in <module>()
2 rpn = rpn_layer(shared_layers, num_anchors)
3
----> 4 classifier = classifier_layer(shared_layers, roi_input, C.num_rois, nb_classes=len(classes_count))
5
6 model_rpn = Model(img_input, rpn[:2])
1 frames
<ipython-input-33-3ad8e8cb6f84> in __init__(self, pool_size, num_rois, **kwargs)
19 def __init__(self, pool_size, num_rois, **kwargs):
20
---> 21 self.dim_ordering = K.image_dim_ordering()
22 self.pool_size = pool_size
23 self.num_rois = num_rois
AttributeError: module 'keras.backend' has no attribute 'image_dim_ordering'我不知道怎么修复它,任何帮助我都很感激。
发布于 2019-12-12 03:11:05
你使用的是什么版本的keras和TensorFlow?
尝试使用:
keras.backend.image_data_format()发布于 2020-12-04 20:35:03
如果你只想执行现有的代码,我建议将版本降级到keras 2.2.4和TF 1.13.1,这样你就可以执行它了。
https://stackoverflow.com/questions/59289932
复制相似问题