Detectron.pytorch代码解读--lib core test_engine.py

本文详细解读Detectron.pytorch库中lib/core/test_engine.py的代码,重点解析test_net()函数,该函数负责在指定数据集上进行预测,并返回包括边界框、分割掩模和关键点的结果。test_net_on_dataset()用于在数据集上运行推理,根据GPU数量选择多GPU或单GPU预测。最后,run_inference()整合结果并输出map和recall等指标。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

从小函数开始  代码

1 test_net()

def test_net(
        args,
        dataset_name,
        proposal_file,
        output_dir,
        ind_range=None,
        gpu_id=0):
    """Run inference on all images in a dataset or over an index range of images
    in a dataset using a single GPU.
    """

在一个数据集指定的图片或所有图片上进行预测,返回 all_boxes, all_segms, all_keyps

其中all_boxes的格式值得关注:

    Box detections are collected into:
      all_boxes[cls][image] = N x 5 array with columns (x1, y1, x2, y2, score)

这个函数的一个附加功能是 将预测结果直接保存到.pkl文件了

    if ind_range is not None:
        det_name = 'detection_range_%s_%s.pkl' % tuple(ind_range)
    else:
        det_name = 'detections.pkl'
    det_file = os.path.join(output_dir, det_name)
    save_object(
        dict(
            all_boxes=all_boxes,
            all_segms=all_segms,
            all_keyps=all_keyps,
            cfg=cfg_yaml
        ), det_file
    )
    logger.info('Wrote detections to: {}'.format(os.path.abspath(det_file))) # 将检测结果保存下来
    return all_boxes, all_segms, all_keyps

2 test_net_on_dataset()"""Run inference on a dataset."""

如果是多个GPU预测,那么调用 multi_gpu_test_net_on_dataset

单个GPU预测,那么调用 test_net()

最后会返回results  , map recall等(这个有待进一步确定)

   results = task_evaluation.evaluate_all(  # 对预测结果进行评估 (挺重要的)
        dataset, all_boxes, all_segms, all_keyps, output_dir
    )

3 run_inference()

调用 了 test_net_on_dataset,最后将结果综合起来,输出 map recall那个界面

 

# Copyright (c) 2017-present, Facebook, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
##############################################################################

"""Test a Detectron network on an imdb (image database)."""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

from collections import defaultdict
import cv2
import datetime
import logging
import numpy as np
import os
import yaml

import torch

from core.config import cfg
# from core.rpn_generator import generate_rpn_on_dataset  #TODO: for rpn only case
# from core.rpn_generator import generate_rpn_on_range
from core.test import im_detect_all
from datasets import task_evaluation
from datasets.json_dataset import JsonDataset
from modeling import model_builder
import nn as mynn
from utils.detectron_weight_helper import load_detectron_weight
import utils.env as envu
import utils.net as net_utils
import utils.subprocess as subprocess_utils
import utils.vis as vis_utils
from utils.io import save_object
from utils.timer import Timer

logger = logging.getLogger(__name__)


def get_eval_functions():
    # Determine which parent or child function should handle inference
    if cfg.MODEL.RPN_ONLY:
        raise NotImplementedError
        # child_func = generate_rpn_on_range
        # parent_func = generate_rpn_on_dataset
    else:
        # Generic case that handles all network types other than RPN-only nets
        # and RetinaNet
        child_func = test_net
        parent_func = test_net_on_dataset

    return parent_func, child_func


def get_inference_dataset(index, is_parent=True): # 得到要预测的数据库以及  proposal_file
    assert is_parent or len(cfg.TEST.DATASETS) == 1, \
        'The child inference process can only work on a single dataset'

    dataset_name = cfg.TEST.DATASETS[index]

    if cfg.TEST.PRECOMPUTED_PROPOSALS:  # 默认为True
        assert is_parent or len(cfg.TEST.PROPOSAL_FILES) == 1, \
            'The child inference process can only work on a single proposal file'
        assert len(cfg.TEST.PROPOSAL_FILES) == len(cfg.TEST.DATASETS), \
            'If proposals are used, one proposal file must be specified for ' \
            'each dataset'
        proposal_file = cfg.TEST.PROPOSAL_FILES[index]  # 为空
    else:
        proposal_file = None

    return dataset_name, proposal_file


def run_inference(  # 测试的入口,最后返回的是测试结果与groun_truth的分析
        args, ind_range=None,
        multi_gpu_testing=False, gpu_id=0,
        check_expected_results=False):
    parent_func, child_func = get_eval_functions() # test_net_on_dataset  test_net
    is_parent = ind_range is None

    def result_getter():#得到一个或多个数据集的测试结果
        if is_parent:
            # Parent case:
            # In this case we're either running inference on the entire dataset in a
            # single process or (if multi_gpu_testing is True) using this process to
            # launch subprocesses that each run inference on a range of the dataset
            all_results = {}
            for i in range(len(cfg.TEST.DATASETS)):
                dataset_name, proposal_file = get_inference_dataset(i)
                output_dir = args.output_dir
                results = parent_func(
                    args,
                    dataset_name,
                    proposal_file,
                    output_dir,
                    multi_gpu=multi_gpu_testing
                )
                all_results.update(results)

            return all_results  # 将多个数据集的结果合并起来
        else:
            # Subprocess child case:
            # In this case test_net was called via subprocess.Popen to execute on a
            # range of inputs on a single dataset
            dataset_name, proposal_file = get_inference_dataset(0, is_parent=False)
            output_dir = args.output_dir
            return child_func(
                args,
                dataset_name,
                proposal_file,
                output_dir,
                ind_range=ind_range,
                gpu_id=gpu_id
            )

    all_results = result_getter()
    if check_expected_results and is_parent:  # 这个是要看的,感觉不太重要
        task_evaluation.check_expected_results(
            all_results,
            atol=cfg.EXPECTED_RESULTS_ATOL,
            rtol=cfg.EXPECTED_RESULTS_RTOL
        )
        task_evaluation.log_copy_paste_friendly_results(all_results)

    return all_results


def test_net_on_dataset(
        args,
        dataset_name,
        proposal_file,
        output_dir,
        multi_gpu=False,
        gpu_id=0):
    """Run inference on a dataset."""
    dataset = JsonDataset(dataset_name)
    test_timer = Timer()
    test_timer.tic()
    if multi_gpu:
        num_images = len(dataset.get_roidb())
        all_boxes, all_segms, all_keyps = multi_gpu_test_net_on_dataset(
            args, dataset_name, proposal_file, num_images, output_dir
        )
    else:
        all_boxes, all_segms, all_keyps = test_net(
            args, dataset_name, proposal_file, output_dir, gpu_id=gpu_id
        )
    test_timer.toc()
    logger.info('Total inference time: {:.3f}s'.format(test_timer.average_time))
    results = task_evaluation.evaluate_all(  # 对预测结果进行评估 (挺重要的)
        dataset, all_boxes, all_segms, all_keyps, output_dir
    )
    return results


def multi_gpu_test_net_on_dataset(
        args, dataset_name, proposal_file, num_images, output_dir):
    """Multi-gpu inference on a dataset."""
    binary_dir = envu.get_runtime_dir()
    binary_ext = envu.get_py_bin_ext()
    binary = os.path.join(binary_dir, args.test_net_file + binary_ext)
    assert os.path.exists(binary), 'Binary \'{}\' not found'.format(binary)

    # Pass the target dataset and proposal file (if any) via the command line
    opts = ['TEST.DATASETS', '("{}",)'.format(dataset_name)]
    if proposal_file:
        opts += ['TEST.PROPOSAL_FILES', '("{}",)'.format(proposal_file)]

    # Run inference in parallel in subprocesses
    # Outputs will be a list of outputs from each subprocess, where the output
    # of each subprocess is the dictionary saved by test_net().
    outputs = subprocess_utils.process_in_parallel(
        'detection', num_images, binary, output_dir,
        args.load_ckpt, args.load_detectron, opts
    )

    # Collate the results from each subprocess
    all_boxes = [[] for _ in range(cfg.MODEL.NUM_CLASSES)]
    all_segms = [[] for _ in range(cfg.MODEL.NUM_CLASSES)]
    all_keyps = [[] for _ in range(cfg.MODEL.NUM_CLASSES)]
    for det_data in outputs:
        all_boxes_batch = det_data['all_boxes']
        all_segms_batch = det_data['all_segms']
        all_keyps_batch = det_data['all_keyps']
        for cls_idx in range(1, cfg.MODEL.NUM_CLASSES):
            all_boxes[cls_idx] += all_boxes_batch[cls_idx]
            all_segms[cls_idx] += all_segms_batch[cls_idx]
            all_keyps[cls_idx] += all_keyps_batch[cls_idx]
    det_file = os.path.join(output_dir, 'detections.pkl')
    cfg_yaml = yaml.dump(cfg)
    save_object(
        dict(
            all_boxes=all_boxes,
            all_segms=all_segms,
            all_keyps=all_keyps,
            cfg=cfg_yaml
        ), det_file
    )
    logger.info('Wrote detections to: {}'.format(os.path.abspath(det_file)))

    return all_boxes, all_segms, all_keyps


def test_net(
        args,
        dataset_name,
        proposal_file,
        output_dir,
        ind_range=None,
        gpu_id=0):
    """Run inference on all images in a dataset or over an index range of images
    in a dataset using a single GPU.
    """
    assert not cfg.MODEL.RPN_ONLY, \
        'Use rpn_generate to generate proposals from RPN-only models'

    roidb, dataset, start_ind, end_ind, total_num_images = get_roidb_and_dataset(
        dataset_name, proposal_file, ind_range
    )  # 用于提取对应的数据
    model = initialize_model_from_cfg(args, gpu_id=gpu_id)
    num_images = len(roidb)
    num_classes = cfg.MODEL.NUM_CLASSES
    all_boxes, all_segms, all_keyps = empty_results(num_classes, num_images)
    timers = defaultdict(Timer)
    for i, entry in enumerate(roidb):
        if cfg.TEST.PRECOMPUTED_PROPOSALS:
            # The roidb may contain ground-truth rois (for example, if the roidb
            # comes from the training or val split). We only want to evaluate
            # detection on the *non*-ground-truth rois. We select only the rois
            # that have the gt_classes field set to 0, which means there's no
            # ground truth.
            box_proposals = entry['boxes'][entry['gt_classes'] == 0]
            if len(box_proposals) == 0:
                continue
        else:
            # Faster R-CNN type models generate proposals on-the-fly with an
            # in-network RPN; 1-stage models don't require proposals.
            box_proposals = None

        im = cv2.imread(entry['image'])
        # 在每张图片上进行测试,得到相应结果
        cls_boxes_i, cls_segms_i, cls_keyps_i = im_detect_all(model, im, box_proposals, timers)
        # 将第i个图片的预测结果加入到all_boxes 相应位置
        extend_results(i, all_boxes, cls_boxes_i)  #
        if cls_segms_i is not None:
            extend_results(i, all_segms, cls_segms_i)
        if cls_keyps_i is not None:
            extend_results(i, all_keyps, cls_keyps_i)

        if i % 10 == 0:  # Reduce log file size
            ave_total_time = np.sum([t.average_time for t in timers.values()])
            eta_seconds = ave_total_time * (num_images - i - 1)
            eta = str(datetime.timedelta(seconds=int(eta_seconds)))
            det_time = (
                    timers['im_detect_bbox'].average_time +
                    timers['im_detect_mask'].average_time +
                    timers['im_detect_keypoints'].average_time
            )
            misc_time = (
                    timers['misc_bbox'].average_time +
                    timers['misc_mask'].average_time +
                    timers['misc_keypoints'].average_time
            )
            logger.info(
                (
                    'im_detect: range [{:d}, {:d}] of {:d}: '
                    '{:d}/{:d} {:.3f}s + {:.3f}s (eta: {})'
                ).format(
                    start_ind + 1, end_ind, total_num_images, start_ind + i + 1,
                    start_ind + num_images, det_time, misc_time, eta
                )
            )

        if cfg.VIS:
            im_name = os.path.splitext(os.path.basename(entry['image']))[0]
            vis_utils.vis_one_image(
                im[:, :, ::-1],
                '{:d}_{:s}'.format(i, im_name),
                os.path.join(output_dir, 'vis'),
                cls_boxes_i,
                segms=cls_segms_i,
                keypoints=cls_keyps_i,
                thresh=cfg.VIS_TH,
                box_alpha=0.8,
                dataset=dataset,
                show_class=True
            )

    cfg_yaml = yaml.dump(cfg)
    if ind_range is not None:
        det_name = 'detection_range_%s_%s.pkl' % tuple(ind_range)
    else:
        det_name = 'detections.pkl'
    det_file = os.path.join(output_dir, det_name)
    save_object(
        dict(
            all_boxes=all_boxes,
            all_segms=all_segms,
            all_keyps=all_keyps,
            cfg=cfg_yaml
        ), det_file
    )
    logger.info('Wrote detections to: {}'.format(os.path.abspath(det_file))) # 将检测结果保存下来
    return all_boxes, all_segms, all_keyps


def initialize_model_from_cfg(args, gpu_id=0):
    """Initialize a model from the global cfg. Loads test-time weights and
    set to evaluation mode.
    """
    model = model_builder.Generalized_RCNN()
    model.eval()

    if args.cuda:
        model.cuda()

    if args.load_ckpt:
        load_name = args.load_ckpt
        logger.info("loading checkpoint %s", load_name)
        checkpoint = torch.load(load_name, map_location=lambda storage, loc: storage)
        net_utils.load_ckpt(model, checkpoint['model'])

    if args.load_detectron:
        logger.info("loading detectron weights %s", args.load_detectron)
        load_detectron_weight(model, args.load_detectron)

    model = mynn.DataParallel(model, cpu_keywords=['im_info', 'roidb'], minibatch=True)

    return model


def get_roidb_and_dataset(dataset_name, proposal_file, ind_range):
    """Get the roidb for the dataset specified in the global cfg. Optionally
    restrict it to a range of indices if ind_range is a pair of integers.
    """
    dataset = JsonDataset(dataset_name)
    if cfg.TEST.PRECOMPUTED_PROPOSALS:
        assert proposal_file, 'No proposal file given'
        roidb = dataset.get_roidb(
            proposal_file=proposal_file,
            proposal_limit=cfg.TEST.PROPOSAL_LIMIT
        )
    else:
        roidb = dataset.get_roidb()

    if ind_range is not None:
        total_num_images = len(roidb)
        start, end = ind_range
        roidb = roidb[start:end]
    else:
        start = 0
        end = len(roidb)
        total_num_images = end

    return roidb, dataset, start, end, total_num_images


def empty_results(num_classes, num_images):
    """Return empty results lists for boxes, masks, and keypoints.
    Box detections are collected into:
      all_boxes[cls][image] = N x 5 array with columns (x1, y1, x2, y2, score)
    Instance mask predictions are collected into:
      all_segms[cls][image] = [...] list of COCO RLE encoded masks that are in
      1:1 correspondence with the boxes in all_boxes[cls][image]
    Keypoint predictions are collected into:
      all_keyps[cls][image] = [...] list of keypoints results, each encoded as
      a 3D array (#rois, 4, #keypoints) with the 4 rows corresponding to
      [x, y, logit, prob] (See: utils.keypoints.heatmaps_to_keypoints).
      Keypoints are recorded for person (cls = 1); they are in 1:1
      correspondence with the boxes in all_boxes[cls][image].
    """
    # Note: do not be tempted to use [[] * N], which gives N references to the
    # *same* empty list.
    all_boxes = [[[] for _ in range(num_images)] for _ in range(num_classes)]
    all_segms = [[[] for _ in range(num_images)] for _ in range(num_classes)]
    all_keyps = [[[] for _ in range(num_images)] for _ in range(num_classes)]
    return all_boxes, all_segms, all_keyps


def extend_results(index, all_res, im_res):
    """Add results for an image to the set of all results at the specified
    index.
    """
    # Skip cls_idx 0 (__background__)
    for cls_idx in range(1, len(im_res)):
        all_res[cls_idx][index] = im_res[cls_idx]

 

InvalidArgumentError Traceback (most recent call last) Cell In[6], line 90 88 # ================= 开始训练 ================= 89 print("\n开始GPU加速训练...") ---> 90 bert_history = bert_model.fit( 91 train_ds, 92 validation_data=test_ds, 93 epochs=3, 94 verbose=1, 95 callbacks=[ 96 tensorboard_cb, 97 tf.keras.callbacks.EarlyStopping(monitor='val_loss', patience=2) 98 ] 99 ) 101 # ================= 评估模型 ================= 102 bert_results = bert_model.evaluate(test_ds) File D:\Anaconda\envs\pytorch1\lib\site-packages\transformers\modeling_tf_utils.py:1229, in TFPreTrainedModel.fit(self, *args, **kwargs) 1226 @functools.wraps(keras.Model.fit) 1227 def fit(self, *args, **kwargs): 1228 args, kwargs = convert_batch_encoding(*args, **kwargs) -> 1229 return super().fit(*args, **kwargs) File D:\Anaconda\envs\pytorch1\lib\site-packages\keras\src\utils\traceback_utils.py:70, in filter_traceback.<locals>.error_handler(*args, **kwargs) 67 filtered_tb = _process_traceback_frames(e.__traceback__) 68 # To get the full stack trace, call: 69 # `tf.debugging.disable_traceback_filtering()` ---> 70 raise e.with_traceback(filtered_tb) from None 71 finally: 72 del filtered_tb File D:\Anaconda\envs\pytorch1\lib\site-packages\tensorflow\python\eager\execute.py:53, in quick_execute(op_name, num_outputs, inputs, attrs, ctx, name) 51 try: 52 ctx.ensure_initialized() ---> 53 tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name, 54 inputs, attrs, num_outputs) 55 except core._NotOkStatusException as e: 56 if name is not None: InvalidArgumentError: Graph execution error: Detected at node 'tf_bert_for_sequence_classification/bert/embeddings/assert_less/Assert/Assert' defined at (most recent call last): File "D:\Anaconda\envs\pytorch1\lib\threading.py", line 890, in _bootstrap self._bootstrap_inner() File "D:\Anaconda\envs\pytorch1\lib\threading.py", line 932, in _bootstrap_inner self.run() File "D:\Anaconda\envs\pytorch1\lib\site-packages\keras\src\engine\training.py", line 1303, in run_step outputs = model.train_step(data) File "D:\Anaconda\envs\pytorch1\lib\site-packages\transformers\modeling_tf_utils.py", line 1672, in train_step y_pred = self(x, training=True) File "D:\Anaconda\envs\pytorch1\lib\site-packages\keras\src\utils\traceback_utils.py", line 65, in error_handler return fn(*args, **kwargs) File "D:\Anaconda\envs\pytorch1\lib\site-packages\keras\src\engine\training.py", line 569, in __call__ return super().__call__(*args, **kwargs) File "D:\Anaconda\envs\pytorch1\lib\site-packages\keras\src\utils\traceback_utils.py", line 65, in error_handler return fn(*args, **kwargs) File "D:\Anaconda\envs\pytorch1\lib\site-packages\keras\src\engine\base_layer.py", line 1150, in __call__ outputs = call_fn(inputs, *args, **kwargs) File "D:\Anaconda\envs\pytorch1\lib\site-packages\keras\src\utils\traceback_utils.py", line 96, in error_handler return fn(*args, **kwargs) File "D:\Anaconda\envs\pytorch1\lib\site-packages\transformers\modeling_tf_utils.py", line 1734, in run_call_with_unpacked_inputs if not self._using_dummy_loss and parse(tf.__version__) < parse("2.11.0"): File "D:\Anaconda\envs\pytorch1\lib\site-packages\transformers\models\bert\modeling_tf_bert.py", line 1746, in call outputs = self.bert( File "D:\Anaconda\envs\pytorch1\lib\site-packages\keras\src\utils\traceback_utils.py", line 65, in error_handler return fn(*args, **kwargs) File "D:\Anaconda\envs\pytorch1\lib\site-packages\keras\src\engine\base_layer.py", line 1150, in __call__ outputs = call_fn(inputs, *args, **kwargs) File "D:\Anaconda\envs\pytorch1\lib\site-packages\keras\src\utils\traceback_utils.py", line 96, in error_handler return fn(*args, **kwargs) File "D:\Anaconda\envs\pytorch1\lib\site-packages\transformers\modeling_tf_utils.py", line 1734, in run_call_with_unpacked_inputs if not self._using_dummy_loss and parse(tf.__version__) < parse("2.11.0"): File "D:\Anaconda\envs\pytorch1\lib\site-packages\transformers\models\bert\modeling_tf_bert.py", line 887, in call embedding_output = self.embeddings( File "D:\Anaconda\envs\pytorch1\lib\site-packages\keras\src\utils\traceback_utils.py", line 65, in error_handler return fn(*args, **kwargs) File "D:\Anaconda\envs\pytorch1\lib\site-packages\keras\src\engine\base_layer.py", line 1150, in __call__ outputs = call_fn(inputs, *args, **kwargs) File "D:\Anaconda\envs\pytorch1\lib\site-packages\keras\src\utils\traceback_utils.py", line 96, in error_handler return fn(*args, **kwargs) File "D:\Anaconda\envs\pytorch1\lib\site-packages\transformers\models\bert\modeling_tf_bert.py", line 180, in call if input_ids is not None: File "D:\Anaconda\envs\pytorch1\lib\site-packages\transformers\models\bert\modeling_tf_bert.py", line 181, in call check_embeddings_within_bounds(input_ids, self.config.vocab_size) File "D:\Anaconda\envs\pytorch1\lib\site-packages\transformers\tf_utils.py", line 190, in check_embeddings_within_bounds tf.debugging.assert_less( Node: 'tf_bert_for_sequence_classification/bert/embeddings/assert_less/Assert/Assert' assertion failed: [The maximum value of input_ids (Tensor(\"tf_bert_for_sequence_classification/bert/embeddings/Max:0\", shape=(), dtype=int32, device=/job:localhost/replica:0/task:0/device:CPU:0)) must be smaller than the embedding layer\'s input dimension (30522). The likely cause is some problem at tokenization time.] [Condition x < y did not hold element-wise:] [x (cond/Identity_1:0) = ] [[101 2267 4530...]...] [y (tf_bert_for_sequence_classification/bert/embeddings/Cast/x:0) = ] [30522] [[{{node tf_bert_for_sequence_classification/bert/embeddings/assert_less/Assert/Assert}}]] [Op:__inference_train_function_51172]
最新发布
06-24
86 bert_history = bert_model.fit( 87 train_ds, 88 validation_data=test_ds, 89 epochs=3, 90 verbose=1 报错:InvalidArgumentError: Graph execution error: Detected at node 'tf_bert_for_sequence_classification/bert/embeddings/assert_less/Assert/Assert' defined at (most recent call last): File "D:\Anaconda\envs\pytorch1\lib\runpy.py", line 192, in _run_module_as_main return _run_code(code, main_globals, None, File "D:\Anaconda\envs\pytorch1\lib\runpy.py", line 85, in _run_code exec(code, run_globals) File "D:\Anaconda\envs\pytorch1\lib\site-packages\ipykernel_launcher.py", line 17, in <module> app.launch_new_instance() File "D:\Anaconda\envs\pytorch1\lib\site-packages\traitlets\config\application.py", line 1075, in launch_instance app.start() File "D:\Anaconda\envs\pytorch1\lib\site-packages\ipykernel\kernelapp.py", line 701, in start self.io_loop.start() File "D:\Anaconda\envs\pytorch1\lib\site-packages\tornado\platform\asyncio.py", line 205, in start self.asyncio_loop.run_forever() File "D:\Anaconda\envs\pytorch1\lib\asyncio\windows_events.py", line 316, in run_forever super().run_forever() File "D:\Anaconda\envs\pytorch1\lib\asyncio\base_events.py", line 563, in run_forever self._run_once() File "D:\Anaconda\envs\pytorch1\lib\asyncio\base_events.py", line 1844, in _run_once handle._run() File "D:\Anaconda\envs\pytorch1\lib\asyncio\events.py", line 81, in _run self._context.run(self._callback, *self._args) File "D:\Anaconda\envs\pytorch1\lib\site-packages\ipykernel\kernelbase.py", line 534, in dispatch_queue await self.process_one() File "D:\Anaconda\envs\pytorch1\lib\site-packages\ipykernel\kernelbase.py", line 523, in process_one await dispatch(*args) File "D:\Anaconda\envs\pytorch1\lib\site-packages\ipykernel\kernelbase.py", line 429, in dispatch_shell await result File "D:\Anaconda\envs\pytorch1\lib\site-packages\ipykernel\kernelbase.py", line 767, in execute_request reply_content = await reply_content File "D:\Anaconda\envs\pytorch1\lib\site-packages\ipykernel\ipkernel.py", line 429, in do_execute res = shell.run_cell( File "D:\Anaconda\envs\pytorch1\lib\site-packages\ipykernel\zmqshell.py", line 549, in run_cell return super().run_cell(*args, **kwargs) File "D:\Anaconda\envs\pytorch1\lib\site-packages\IPython\core\interactiveshell.py", line 3009, in run_cell result = self._run_cell( File "D:\Anaconda\envs\pytorch1\lib\site-packages\IPython\core\interactiveshell.py", line 3064, in _run_cell result = runner(coro) File "D:\Anaconda\envs\pytorch1\lib\site-packages\IPython\core\async_helpers.py", line 129, in _pseudo_sync_runner coro.send(None) File "D:\Anaconda\envs\pytorch1\lib\site-packages\IPython\core\interactiveshell.py", line 3269, in run_cell_async has_raised = await self.run_ast_nodes(code_ast.body, cell_name, File "D:\Anaconda\envs\pytorch1\lib\site-packages\IPython\core\interactiveshell.py", line 3448, in run_ast_nodes if await self.run_code(code, result, async_=asy): File "D:\Anaconda\envs\pytorch1\lib\site-packages\IPython\core\interactiveshell.py", line 3508, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "C:\Users\豆崽\AppData\Local\Temp\ipykernel_20320\247762855.py", line 86, in <module> bert_history = bert_model.fit( File "D:\Anaconda\envs\pytorch1\lib\site-packages\transformers\modeling_tf_utils.py", line 1229, in fit return super().fit(*args, **kwargs) File "D:\Anaconda\envs\pytorch1\lib\site-packages\keras\src\utils\traceback_utils.py", line 65, in error_handler return fn(*args, **kwargs) File "D:\Anaconda\envs\pytorch1\lib\site-packages\keras\src\engine\training.py", line 1742, in fit tmp_logs = self.train_function(iterator) File "D:\Anaconda\envs\pytorch1\lib\site-packages\keras\src\engine\training.py", line 1338, in train_function return step_function(self, iterator) File "D:\Anaconda\envs\pytorch1\lib\site-packages\keras\src\engine\training.py", line 1322, in step_function outputs = model.distribute_strategy.run(run_step, args=(data,)) File "D:\Anaconda\envs\pytorch1\lib\site-packages\keras\src\engine\training.py", line 1303, in run_step outputs = model.train_step(data) File "D:\Anaconda\envs\pytorch1\lib\site-packages\transformers\modeling_tf_utils.py", line 1672, in train_step y_pred = self(x, training=True) File "D:\Anaconda\envs\pytorch1\lib\site-packages\keras\src\utils\traceback_utils.py", line 65, in error_handler return fn(*args, **kwargs) File "D:\Anaconda\envs\pytorch1\lib\site-packages\keras\src\engine\training.py", line 569, in __call__ return super().__call__(*args, **kwargs) File "D:\Anaconda\envs\pytorch1\lib\site-packages\keras\src\utils\traceback_utils.py", line 65, in error_handler return fn(*args, **kwargs) File "D:\Anaconda\envs\pytorch1\lib\site-packages\keras\src\engine\base_layer.py", line 1150, in __call__ outputs = call_fn(inputs, *args, **kwargs) File "D:\Anaconda\envs\pytorch1\lib\site-packages\keras\src\utils\traceback_utils.py", line 96, in error_handler return fn(*args, **kwargs) File "D:\Anaconda\envs\pytorch1\lib\site-packages\transformers\modeling_tf_utils.py", line 1734, in run_call_with_unpacked_inputs if not self._using_dummy_loss and parse(tf.__version__) < parse("2.11.0"): File "D:\Anaconda\envs\pytorch1\lib\site-packages\transformers\models\bert\modeling_tf_bert.py", line 1746, in call outputs = self.bert( File "D:\Anaconda\envs\pytorch1\lib\site-packages\keras\src\utils\traceback_utils.py", line 65, in error_handler return fn(*args, **kwargs) File "D:\Anaconda\envs\pytorch1\lib\site-packages\keras\src\engine\base_layer.py", line 1150, in __call__ outputs = call_fn(inputs, *args, **kwargs) File "D:\Anaconda\envs\pytorch1\lib\site-packages\keras\src\utils\traceback_utils.py", line 96, in error_handler return fn(*args, **kwargs) File "D:\Anaconda\envs\pytorch1\lib\site-packages\transformers\modeling_tf_utils.py", line 1734, in run_call_with_unpacked_inputs if not self._using_dummy_loss and parse(tf.__version__) < parse("2.11.0"): File "D:\Anaconda\envs\pytorch1\lib\site-packages\transformers\models\bert\modeling_tf_bert.py", line 887, in call embedding_output = self.embeddings( File "D:\Anaconda\envs\pytorch1\lib\site-packages\keras\src\utils\traceback_utils.py", line 65, in error_handler return fn(*args, **kwargs) File "D:\Anaconda\envs\pytorch1\lib\site-packages\keras\src\engine\base_layer.py", line 1150, in __call__ outputs = call_fn(inputs, *args, **kwargs) File "D:\Anaconda\envs\pytorch1\lib\site-packages\keras\src\utils\traceback_utils.py", line 96, in error_handler return fn(*args, **kwargs) File "D:\Anaconda\envs\pytorch1\lib\site-packages\transformers\models\bert\modeling_tf_bert.py", line 180, in call if input_ids is not None: File "D:\Anaconda\envs\pytorch1\lib\site-packages\transformers\models\bert\modeling_tf_bert.py", line 181, in call check_embeddings_within_bounds(input_ids, self.config.vocab_size) File "D:\Anaconda\envs\pytorch1\lib\site-packages\transformers\tf_utils.py", line 190, in check_embeddings_within_bounds tf.debugging.assert_less( Node: 'tf_bert_for_sequence_classification/bert/embeddings/assert_less/Assert/Assert' assertion failed: [The maximum value of input_ids (Tensor(\"tf_bert_for_sequence_classification/bert/embeddings/Max:0\", shape=(), dtype=int32)) must be smaller than the embedding layer\'s input dimension (30522). The likely cause is some problem at tokenization time.] [Condition x < y did not hold element-wise:] [x (IteratorGetNext:1) = ] [[101 2746 14667...]...] [y (tf_bert_for_sequence_classification/bert/embeddings/Cast/x:0) = ] [30522] [[{{node tf_bert_for_sequence_classification/bert/embeddings/assert_less/Assert/Assert}}]] [Op:__inference_train_function_73426]
06-24
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值