tf.import_graph_def()

错误代码:

Input 0 of node import/YOLOV3/MobilenetV2/Conv/BatchNorm/cond/Assign/Switch was passed float from import/YOLOV3/MobilenetV2    /Conv/BatchNorm/moving_mean:0 incompatible with expected float_ref.

解决方案:

fix nodes

for node in frozen_graph_def.node:
    if node.op == 'RefSwitch':
        node.op = 'Switch'
        for index in range(len(node.input)):
            if 'moving_' in node.input[index]:
                node.input[index] = node.input[index] + '/read'
    elif node.op == 'AssignSub':
        node.op = 'Sub'
        if 'use_locking' in node.attr: del node.attr['use_locking']
    elif node.op == 'AssignAdd':
        node.op = 'Add'
        if 'use_locking' in node.attr: del node.attr['use_locking']
    elif node.op == 'Assign':
        node.op = 'Identity'
        if 'use_locking' in node.attr: del node.attr['use_locking']
        if 'validate_shape' in node.attr: del node.attr['validate_shape']
        if len(node.input) == 2:
            # input0: ref: Should be from a Variable node. May be uninitialized.
            # input1: value: The value to be assigned to the variable.
            node.input[0] = node.input[1]
            del node.input[1]
  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 9
    评论
将这两个代码结合import cv2 import numpy as np import urllib.request import tensorflow as tf # 下载DeepLabv3+模型权重文件 model_url = "http://download.tensorflow.org/models/deeplabv3_mnv2_pascal_train_aug_2018_01_29.tar.gz" tar_filename = "deeplabv3_mnv2_pascal_train_aug.tar.gz" urllib.request.urlretrieve(model_url, tar_filename) # 解压缩 with tarfile.open(tar_filename, "r:gz") as tar: tar.extractall() model_filename = "deeplabv3_mnv2_pascal_train_aug/frozen_inference_graph.pb" # 加载模型 graph = tf.Graph() with graph.as_default(): od_graph_def = tf.GraphDef() with tf.io.gfile.GFile(model_filename, 'rb') as fid: serialized_graph = fid.read() od_graph_def.ParseFromString(serialized_graph) tf.import_graph_def(od_graph_def, name='') # 读取图像 image_path = "your_image.jpg" image = cv2.imread(image_path) # 进行图像分割 with tf.compat.v1.Session(graph=graph) as sess: input_tensor = graph.get_tensor_by_name('ImageTensor:0') output_tensor = graph.get_tensor_by_name('SemanticPredictions:0') output = sess.run(output_tensor, feed_dict={input_tensor: image}) # 解码并可视化分割结果 segmentation_mask = np.squeeze(output) segmentation_mask = np.uint8(segmentation_mask) segmentation_mask = cv2.resize(segmentation_mask, (image.shape[1], image.shape[0]), interpolation=cv2.INTER_NEAREST) # 显示原始图像和分割结果 cv2.imshow("Image", image) cv2.imshow("Segmentation Mask", segmentation_mask) cv2.waitKey(0) cv2.destroyAllWindows() model1 = models.CellposeModel(gpu=True, model_type='livecell') model2 = models.Cellpose(gpu=True,model_type='nuclei') model3= models.Cellpose(gpu=True,model_type='cyto2') 集成DeepLabv3+模型和cellpose模型
最新发布
07-14
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值