首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >构建训练frcnn的模型,AttributeError classifier_layer

构建训练frcnn的模型,AttributeError classifier_layer
EN

Stack Overflow用户
提问于 2019-12-12 00:14:36
回答 2查看 146关注 0票数 0

我正在构建模型来训练frcnn卷积神经网络,问题是在建立模型时,它说我有一个错误,我怀疑这可能是由于tensorflow版本的不兼容。

下面的代码(错误第4行):

代码语言:javascript
复制
# 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)))

这就是输出:

代码语言:javascript
复制
---------------------------------------------------------------------------
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'

我不知道怎么修复它,任何帮助我都很感激。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-12-12 03:11:05

你使用的是什么版本的keras和TensorFlow?

尝试使用:

代码语言:javascript
复制
keras.backend.image_data_format()
票数 1
EN

Stack Overflow用户

发布于 2020-12-04 20:35:03

如果你只想执行现有的代码,我建议将版本降级到keras 2.2.4和TF 1.13.1,这样你就可以执行它了。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59289932

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档