Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python TypeError:无法使用Kerastenor类型生成TypeSpec_Python_Tensorflow_Machine Learning_Image Processing_Deep Learning - Fatal编程技术网

Python TypeError:无法使用Kerastenor类型生成TypeSpec

Python TypeError:无法使用Kerastenor类型生成TypeSpec,python,tensorflow,machine-learning,image-processing,deep-learning,Python,Tensorflow,Machine Learning,Image Processing,Deep Learning,我是深度学习的新手,因此当我试图构建一个掩蔽的R-CNN模型来训练我的自定义数据集时,我遇到了一个错误,错误如下: TypeError: Could not build a TypeSpec for <KerasTensor: shape=(None, None, 4) dtype=float32 (created by layer 'tf.math.truediv')> with type KerasTensor 我得到以下信息: 2020-12-21 00:41:06.2522

我是深度学习的新手,因此当我试图构建一个掩蔽的R-CNN模型来训练我的自定义数据集时,我遇到了一个错误,错误如下:

TypeError: Could not build a TypeSpec for <KerasTensor: shape=(None, None, 4) dtype=float32 (created by layer 'tf.math.truediv')> with type KerasTensor
我得到以下信息:

2020-12-21 00:41:06.252236: W tensorflow/stream_executor/platform/default/dso_loader.cc:60] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
2020-12-21 00:41:06.260248: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.

(base) C:\Users\HP>python C:\Users\HP\Desktop\try.py train --dataset=C:\Users\HP\Test\Train --model=C:\Users\HP\mask_rcnn_coco.h5
2020-12-21 00:42:34.586446: W tensorflow/stream_executor/platform/default/dso_loader.cc:60] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
2020-12-21 00:42:34.594568: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.

(base) C:\Users\HP>python C:\Users\HP\Mask_RCNN\samples\coco\coco.py train --dataset=C:\Users\HP\Test\Train --model=coco
2020-12-21 00:44:41.479421: W tensorflow/stream_executor/platform/default/dso_loader.cc:60] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
2020-12-21 00:44:41.490317: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
Command:  train
Model:  coco
Dataset:  C:\Users\HP\Test\Train
Year:  2014
Logs:  C:\Mask_RCNN\logs
Auto Download:  False

Configurations:
BACKBONE                       resnet101
BACKBONE_STRIDES               [4, 8, 16, 32, 64]
BATCH_SIZE                     2
BBOX_STD_DEV                   [0.1 0.1 0.2 0.2]
COMPUTE_BACKBONE_SHAPE         None
DETECTION_MAX_INSTANCES        100
DETECTION_MIN_CONFIDENCE       0.7
DETECTION_NMS_THRESHOLD        0.3
FPN_CLASSIF_FC_LAYERS_SIZE     1024
GPU_COUNT                      1
GRADIENT_CLIP_NORM             5.0
IMAGES_PER_GPU                 2
IMAGE_MAX_DIM                  1024
IMAGE_META_SIZE                93
IMAGE_MIN_DIM                  800
IMAGE_MIN_SCALE                0
IMAGE_RESIZE_MODE              square
IMAGE_SHAPE                    [1024 1024    3]
LEARNING_MOMENTUM              0.9
LEARNING_RATE                  0.001
LOSS_WEIGHTS                   {'rpn_class_loss': 1.0, 'rpn_bbox_loss': 1.0, 'mrcnn_class_loss': 1.0, 'mrcnn_bbox_loss': 1.0, 'mrcnn_mask_loss': 1.0}
MASK_POOL_SIZE                 14
MASK_SHAPE                     [28, 28]
MAX_GT_INSTANCES               100
MEAN_PIXEL                     [123.7 116.8 103.9]
MINI_MASK_SHAPE                (56, 56)
NAME                           coco
NUM_CLASSES                    81
POOL_SIZE                      7
POST_NMS_ROIS_INFERENCE        1000
POST_NMS_ROIS_TRAINING         2000
ROI_POSITIVE_RATIO             0.33
RPN_ANCHOR_RATIOS              [0.5, 1, 2]
RPN_ANCHOR_SCALES              (32, 64, 128, 256, 512)
RPN_ANCHOR_STRIDE              1
RPN_BBOX_STD_DEV               [0.1 0.1 0.2 0.2]
RPN_NMS_THRESHOLD              0.7
RPN_TRAIN_ANCHORS_PER_IMAGE    256
STEPS_PER_EPOCH                1000
TOP_DOWN_PYRAMID_SIZE          256
TRAIN_BN                       False
TRAIN_ROIS_PER_IMAGE           200
USE_MINI_MASK                  True
USE_RPN_ROIS                   True
VALIDATION_STEPS               50
WEIGHT_DECAY                   0.0001


Traceback (most recent call last):
  File "C:\Users\HP\Mask_RCNN\samples\coco\coco.py", line 456, in <module>
    model_dir=args.logs)
  File "C:\Users\HP\anaconda3\lib\site-packages\mrcnn\model.py", line 1832, in __init__
    self.keras_model = self.build(mode=mode, config=config)
  File "C:\Users\HP\anaconda3\lib\site-packages\mrcnn\model.py", line 1871, in build
    x, K.shape(input_image)[1:3]))(input_gt_boxes)
  File "C:\Users\HP\anaconda3\lib\site-packages\tensorflow\python\keras\engine\base_layer.py", line 952, in __call__
    input_list)
  File "C:\Users\HP\anaconda3\lib\site-packages\tensorflow\python\keras\engine\base_layer.py", line 1091, in _functional_construction_call
    inputs, input_masks, args, kwargs)
  File "C:\Users\HP\anaconda3\lib\site-packages\tensorflow\python\keras\engine\base_layer.py", line 822, in _keras_tensor_symbolic_call
    return self._infer_output_signature(inputs, args, kwargs, input_masks)
  File "C:\Users\HP\anaconda3\lib\site-packages\tensorflow\python\keras\engine\base_layer.py", line 869, in _infer_output_signature
    keras_tensor.keras_tensor_from_tensor, outputs)
  File "C:\Users\HP\anaconda3\lib\site-packages\tensorflow\python\util\nest.py", line 659, in map_structure
    structure[0], [func(*x) for x in entries],
  File "C:\Users\HP\anaconda3\lib\site-packages\tensorflow\python\util\nest.py", line 659, in <listcomp>
    structure[0], [func(*x) for x in entries],
  File "C:\Users\HP\anaconda3\lib\site-packages\tensorflow\python\keras\engine\keras_tensor.py", line 606, in keras_tensor_from_tensor
    out = keras_tensor_cls.from_tensor(tensor)
  File "C:\Users\HP\anaconda3\lib\site-packages\tensorflow\python\keras\engine\keras_tensor.py", line 205, in from_tensor
    type_spec = type_spec_module.type_spec_from_value(tensor)
  File "C:\Users\HP\anaconda3\lib\site-packages\tensorflow\python\framework\type_spec.py", line 554, in type_spec_from_value
    (value, type(value).__name__))
TypeError: Could not build a TypeSpec for <KerasTensor: shape=(None, None, 4) dtype=float32 (created by layer 'tf.math.truediv')> with type KerasTensor
2020-12-21 00:41:06.252236:W tensorflow/stream_executor/platform/default/dso_loader.cc:60]无法加载动态库“cudart64_110.dll”;错误:找不到cudart64_110.dll
2020-12-21 00:41:06.260248:I tensorflow/stream_executor/cuda/cudart_stub.cc:29]如果您的计算机上没有设置GPU,请忽略上面的cudart-dler错误。
(基本)C:\Users\HP>python C:\Users\HP\Desktop\try.py train--dataset=C:\Users\HP\Test\train--model=C:\Users\HP\mask\rcnn\u coco.h5
2020-12-21 00:42:34.586446:W tensorflow/stream_executor/platform/default/dso_loader.cc:60]无法加载动态库“cudart64_110.dll”;错误:找不到cudart64_110.dll
2020-12-21 00:42:34.594568:I tensorflow/stream_executor/cuda/cudart_stub.cc:29]如果您的机器上没有设置GPU,请忽略上面的cudart dler。
(基本)C:\Users\HP>python C:\Users\HP\Mask\u RCNN\samples\coco\coco.py train--dataset=C:\Users\HP\Test\train--model=coco
2020-12-21 00:44:41.479421:W tensorflow/stream_executor/platform/default/dso_loader.cc:60]无法加载动态库“cudart64_110.dll”;错误:找不到cudart64_110.dll
2020-12-21 00:44:41.490317:I tensorflow/stream_executor/cuda/cudart_stub.cc:29]如果您的机器上没有设置GPU,请忽略上面的cudart-dler错误。
指挥:列车
模特:可可
数据集:C:\Users\HP\Test\Train
年份:2014年
日志:C:\Mask\u RCNN\Logs
自动下载:错误
配置:
主干网resnet101
主干步幅[4,8,16,32,64]
批量大小2
BBOX_标准_开发[0.1 0.1 0.2 0.2]
计算主干形状无
检测\u最大\u实例100
检测最小置信度0.7
检测\u NMS\u阈值0.3
FPN\u CLASSIF\u FC\u层\u尺寸1024
GPU计数1
梯度剪辑标准5.0
每个GPU的图像数2
图像最大尺寸1024
图像\元\尺寸93
图像\u最小\u尺寸800
图像\u最小\u比例0
图像\调整大小\模式方形
图像形状[1024 1024 3]
学习动力0.9
学习率0.001
损失权重{'rpn_类损失:1.0,'rpn_-bbox_损失:1.0,'mrcnn_类损失:1.0,'mrcnn_-bbox_损失:1.0,'mrcnn_-bbox_损失:1.0}
遮罩\u池\u尺寸14
面具形状[28,28]
最大\u GT \u实例数100
平均像素[123.7116.8103.9]
迷你面具形状(56,56)
名字叫可可
第81类
游泳池大小7
后NMS\U ROIS\U推理1000
2000年后NMS\U ROIS\U培训
投资回报率/正投资回报率0.33
RPN_锚定比[0.5,1,2]
RPN_锚定_比例(32、64、128、256、512)
RPN_锚定_跨步1
RPN_BBOX_标准_开发[0.1 0.1 0.2 0.2]
RPN\u NMS\u阈值0.7
RPN\u列车\u锚定\u每个\u图像256
每1000步
上下金字塔尺寸256
火车误点
按图像200训练ROIS
使用_MINI_MASK True
使用\u RPN\u ROI为真
验证步骤50
重量衰减0.0001
回溯(最近一次呼叫最后一次):
文件“C:\Users\HP\Mask\u RCNN\samples\coco\coco.py”,第456行,在
model_dir=args.logs)
文件“C:\Users\HP\anaconda3\lib\site packages\mrcnn\model.py”,第1832行,在\uuu init中__
self.keras_model=self.build(mode=mode,config=config)
文件“C:\Users\HP\anaconda3\lib\site packages\mrcnn\model.py”,第1871行,内部版本
x、 K.形状(输入图像)[1:3])(输入框)
文件“C:\Users\HP\anaconda3\lib\site packages\tensorflow\python\keras\engine\base\u layer.py”,第952行,在调用中__
输入(U列表)
文件“C:\Users\HP\anaconda3\lib\site packages\tensorflow\python\keras\engine\base\u layer.py”,第1091行,在函数构造调用中
输入、输入(U掩码、参数、kwargs)
文件“C:\Users\HP\anaconda3\lib\site packages\tensorflow\python\keras\engine\base\u layer.py”,第822行,在\u keras\u tensor\u symbol\u调用中
返回自我。推断输出签名(输入、参数、kwargs、输入掩码)
文件“C:\Users\HP\anaconda3\lib\site packages\tensorflow\python\keras\engine\base\u layer.py”,第869行,在\u推断\u输出\u签名中
keras_张量。keras_张量来自_张量,输出)
文件“C:\Users\HP\anaconda3\lib\site packages\tensorflow\python\util\nest.py”,第659行,映射结构
结构[0],[func(*x)表示条目中的x],
文件“C:\Users\HP\anaconda3\lib\site packages\tensorflow\python\util\nest.py”,第659行,在
结构[0],[func(*x)表示条目中的x],
文件“C:\Users\HP\anaconda3\lib\site packages\tensorflow\python\keras\engine\keras\u tensor.py”,第606行,位于keras\u tensor\u中
out=keras\u张量\u cls.自\u张量(张量)
文件“C:\Users\HP\anaconda3\lib\site packages\tensorflow\python\keras\engine\keras\u tensor.py”,第205行,from\u tensor
类型规格=类型规格模块。类型规格值(张量)
文件“C:\Users\HP\anaconda3\lib\site packages\tensorflow\python\framework\type\u spec.py”,第554行,type\u spec\u from\u value
(值,类型(值)。_名称_;)
TypeError:无法使用KerasTensor类型为生成TypeSpec

从tensorflow 1.2.1升级到2.4时,我遇到了这个错误。 似乎是语句“x,K.shape(input_image)[1:3])(input_gt_box)”导致了该错误。这可能是由于tensorflow和/或Keras的API变化所致。 我怀疑您试图运行的代码是为tensorflow的不同版本编写的,而不是您安装的版本。 您可以尝试安装tensorflow和keras的匹配版本,也可以尝试修复代码以符合您的要求
(base) C:\Users\HP>python C:\Users\HP\Mask_RCNN\samples\coco\coco.py train --dataset=C:\Users\HP\Test\Train --model=coco
2020-12-21 00:41:06.252236: W tensorflow/stream_executor/platform/default/dso_loader.cc:60] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
2020-12-21 00:41:06.260248: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.

(base) C:\Users\HP>python C:\Users\HP\Desktop\try.py train --dataset=C:\Users\HP\Test\Train --model=C:\Users\HP\mask_rcnn_coco.h5
2020-12-21 00:42:34.586446: W tensorflow/stream_executor/platform/default/dso_loader.cc:60] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
2020-12-21 00:42:34.594568: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.

(base) C:\Users\HP>python C:\Users\HP\Mask_RCNN\samples\coco\coco.py train --dataset=C:\Users\HP\Test\Train --model=coco
2020-12-21 00:44:41.479421: W tensorflow/stream_executor/platform/default/dso_loader.cc:60] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
2020-12-21 00:44:41.490317: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
Command:  train
Model:  coco
Dataset:  C:\Users\HP\Test\Train
Year:  2014
Logs:  C:\Mask_RCNN\logs
Auto Download:  False

Configurations:
BACKBONE                       resnet101
BACKBONE_STRIDES               [4, 8, 16, 32, 64]
BATCH_SIZE                     2
BBOX_STD_DEV                   [0.1 0.1 0.2 0.2]
COMPUTE_BACKBONE_SHAPE         None
DETECTION_MAX_INSTANCES        100
DETECTION_MIN_CONFIDENCE       0.7
DETECTION_NMS_THRESHOLD        0.3
FPN_CLASSIF_FC_LAYERS_SIZE     1024
GPU_COUNT                      1
GRADIENT_CLIP_NORM             5.0
IMAGES_PER_GPU                 2
IMAGE_MAX_DIM                  1024
IMAGE_META_SIZE                93
IMAGE_MIN_DIM                  800
IMAGE_MIN_SCALE                0
IMAGE_RESIZE_MODE              square
IMAGE_SHAPE                    [1024 1024    3]
LEARNING_MOMENTUM              0.9
LEARNING_RATE                  0.001
LOSS_WEIGHTS                   {'rpn_class_loss': 1.0, 'rpn_bbox_loss': 1.0, 'mrcnn_class_loss': 1.0, 'mrcnn_bbox_loss': 1.0, 'mrcnn_mask_loss': 1.0}
MASK_POOL_SIZE                 14
MASK_SHAPE                     [28, 28]
MAX_GT_INSTANCES               100
MEAN_PIXEL                     [123.7 116.8 103.9]
MINI_MASK_SHAPE                (56, 56)
NAME                           coco
NUM_CLASSES                    81
POOL_SIZE                      7
POST_NMS_ROIS_INFERENCE        1000
POST_NMS_ROIS_TRAINING         2000
ROI_POSITIVE_RATIO             0.33
RPN_ANCHOR_RATIOS              [0.5, 1, 2]
RPN_ANCHOR_SCALES              (32, 64, 128, 256, 512)
RPN_ANCHOR_STRIDE              1
RPN_BBOX_STD_DEV               [0.1 0.1 0.2 0.2]
RPN_NMS_THRESHOLD              0.7
RPN_TRAIN_ANCHORS_PER_IMAGE    256
STEPS_PER_EPOCH                1000
TOP_DOWN_PYRAMID_SIZE          256
TRAIN_BN                       False
TRAIN_ROIS_PER_IMAGE           200
USE_MINI_MASK                  True
USE_RPN_ROIS                   True
VALIDATION_STEPS               50
WEIGHT_DECAY                   0.0001


Traceback (most recent call last):
  File "C:\Users\HP\Mask_RCNN\samples\coco\coco.py", line 456, in <module>
    model_dir=args.logs)
  File "C:\Users\HP\anaconda3\lib\site-packages\mrcnn\model.py", line 1832, in __init__
    self.keras_model = self.build(mode=mode, config=config)
  File "C:\Users\HP\anaconda3\lib\site-packages\mrcnn\model.py", line 1871, in build
    x, K.shape(input_image)[1:3]))(input_gt_boxes)
  File "C:\Users\HP\anaconda3\lib\site-packages\tensorflow\python\keras\engine\base_layer.py", line 952, in __call__
    input_list)
  File "C:\Users\HP\anaconda3\lib\site-packages\tensorflow\python\keras\engine\base_layer.py", line 1091, in _functional_construction_call
    inputs, input_masks, args, kwargs)
  File "C:\Users\HP\anaconda3\lib\site-packages\tensorflow\python\keras\engine\base_layer.py", line 822, in _keras_tensor_symbolic_call
    return self._infer_output_signature(inputs, args, kwargs, input_masks)
  File "C:\Users\HP\anaconda3\lib\site-packages\tensorflow\python\keras\engine\base_layer.py", line 869, in _infer_output_signature
    keras_tensor.keras_tensor_from_tensor, outputs)
  File "C:\Users\HP\anaconda3\lib\site-packages\tensorflow\python\util\nest.py", line 659, in map_structure
    structure[0], [func(*x) for x in entries],
  File "C:\Users\HP\anaconda3\lib\site-packages\tensorflow\python\util\nest.py", line 659, in <listcomp>
    structure[0], [func(*x) for x in entries],
  File "C:\Users\HP\anaconda3\lib\site-packages\tensorflow\python\keras\engine\keras_tensor.py", line 606, in keras_tensor_from_tensor
    out = keras_tensor_cls.from_tensor(tensor)
  File "C:\Users\HP\anaconda3\lib\site-packages\tensorflow\python\keras\engine\keras_tensor.py", line 205, in from_tensor
    type_spec = type_spec_module.type_spec_from_value(tensor)
  File "C:\Users\HP\anaconda3\lib\site-packages\tensorflow\python\framework\type_spec.py", line 554, in type_spec_from_value
    (value, type(value).__name__))
TypeError: Could not build a TypeSpec for <KerasTensor: shape=(None, None, 4) dtype=float32 (created by layer 'tf.math.truediv')> with type KerasTensor