栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

yolov3 tf1->tf2

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

yolov3 tf1->tf2

1.Tensorflow 2.0 不兼容 Session()
删除session相关代码

2.把keras的相关代码改为tf2.x的代码

# from keras import backend as K
# from keras.layers import Conv2D, Add, ZeroPadding2D, UpSampling2D, Concatenate, MaxPooling2D
# from keras.layers.advanced_activations import LeakyReLU
# from keras.layers.normalization import BatchNormalization
# from keras.models import Model
# from keras.regularizers import l2

from tensorflow.keras import backend as K
from tensorflow.keras.layers import Conv2D, Add, ZeroPadding2D, UpSampling2D, Concatenate, MaxPooling2D, LeakyReLU, BatchNormalization
from tensorflow.keras.models import Model
from tensorflow.keras.regularizers import l2

TypeError: Tensor is unhashable if Tensor equality is enabled. Instead, use tensor.experimental_ref() as the key.
tf2.x数据为tensor,与tf1.x数据格式不兼容
修改数据格式

target_box[(predicted_class, score.numpy())] = (left, top, right, bottom)

3.模型预测代码修改

# out_boxes, out_scores, out_classes = self.sess.run(
#     [self.boxes, self.scores, self.classes],
#     feed_dict={
#         self.yolo_model.input: image_data,
#         self.input_image_shape: [image.size[1], image.size[0]],
#         K.learning_phase(): 0
#     })

input_image_shape = tf.constant([image.size[1], image.size[0]]) 

out_boxes, out_scores, out_classes = yolo_eval(self.yolo_model(image_data), self.anchors,   len(self.class_names), input_image_shape,   score_threshold=self.score, iou_threshold=self.iou)

tensorflow.python.framework.errors_impl.InvalidArgumentError: Subshape must have computed start >= end since stride is negative, but is 0 and 2 (computed from start 0 and end 9223372036854775807 over shape with rank 2 and stride-1)

张量切片问题

#     box_xy = (K.sigmoid(feats[..., :2]) + grid) / tf.cast(grid_shape[::-1], feats.dtype)
#     box_wh = K.exp(feats[..., 2:4]) * anchors_tensor / tf.cast(input_shape[::-1], feats.dtype)
    
    box_xy = (K.sigmoid(feats[..., :2]) + grid) / tf.cast(grid_shape[..., ::-1], feats.dtype)
    box_wh = K.exp(feats[..., 2:4]) * anchors_tensor / tf.cast(input_shape[..., ::-1], feats.dtype)
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/916038.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号