tests.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:cs224n_prj 作者: lps-stanf 项目源码 文件源码
def perform_testing(settings, id_to_word_dict, captions_data=None, coco_images_dir=None, coco_num_images=None,
                    coco_out_path=None):
    from preprocess import TokenBegin, TokenEnd

    with h5py.File(settings.preprocessed_images_file, 'r') as h5_images_file:
        image_shape = h5_images_file['images'].shape[1:]

    with h5py.File(settings.preprocessed_text_file, 'r') as h5_text_file:
        sentence_max_len = len(h5_text_file['sentences'][0])

    dict_size = len(id_to_word_dict)

    TokenBeginIndex = find_token_index(id_to_word_dict, TokenBegin)
    TokenEndIndex = find_token_index(id_to_word_dict, TokenEnd)

    model = create_model(image_shape, dict_size, sentence_max_len, settings)
    model.load_weights(settings.weights)

    if captions_data is not None and coco_images_dir is not None and coco_num_images is not None \
            and coco_out_path is not None:
        calculate_metrics(settings, model, id_to_word_dict, captions_data, coco_images_dir, coco_num_images,
                          coco_out_path, image_shape[:2], sentence_max_len, TokenBeginIndex, TokenEndIndex)
    else:
        create_caption_for_path(settings.test_source, model, image_shape[:2], sentence_max_len, TokenBeginIndex,
                                TokenEndIndex, id_to_word_dict, settings.output_dir,
                                (settings.out_max_width, settings.out_max_height))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号