1.Tensorflow 2.0 不兼容 Session()
删除session相关代码
2.把keras的相关代码改为tf2.x的代码
复制代码
1
2
3
4
5
6
7
8
9
10
11
12# 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数据格式不兼容
修改数据格式
复制代码
1
2target_box[(predicted_class, score.numpy())] = (left, top, right, bottom)
3.模型预测代码修改
复制代码
1
2
3
4
5
6
7
8
9
10
11
12# 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)
张量切片问题
复制代码
1
2
3
4
5
6# 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)
最后
以上就是执着洋葱最近收集整理的关于yolov3 tf1->tf2的全部内容,更多相关yolov3内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复