Keras 尝试计算TensorFlow张量时出错
我试图用TensorFlow和Keras建立一个CNN模型,我试图计算一个张量来得到它的值。特别是,我正在尝试读取我创建的TFR记录 这是我的代码:Keras 尝试计算TensorFlow张量时出错,keras,tensorflow2.0,Keras,Tensorflow2.0,我试图用TensorFlow和Keras建立一个CNN模型,我试图计算一个张量来得到它的值。特别是,我正在尝试读取我创建的TFR记录 这是我的代码: def parse_tfrecord_example(example, config): features = { 'image': tf.io.FixedLenFeature((), tf.string), 'width': tf.io.FixedLenFeature((), tf.int64),
def parse_tfrecord_example(example, config):
features = {
'image': tf.io.FixedLenFeature((), tf.string),
'width': tf.io.FixedLenFeature((), tf.int64),
'height': tf.io.FixedLenFeature((), tf.int64),
'num_obj': tf.io.FixedLenFeature((), tf.int64),
'obj': tf.io.VarLenFeature(tf.int64)
}
parsed_features = tf.io.parse_single_example(example, features)
#This is what I would like to do but I have to evaluate the tensors in parsed_features
"""
annotation = annotation_from(
int(parsed_features['width']),
int(parsed_features['height']),
int(parsed_features['num_obj']),
parsed_features['obj']
)
"""
print(parsed_features['width'].eval())
image = cv2.imdecode(str(parsed_features['image']), cv2.IMREAD_UNCHANGED)
image = normalize_image(image, config)
image = resize_image(image, config)
return image, get_target(annotation, config)
这不管用。如果我尝试获取会话(使用tf.compat.v1.keras.backend.get_session()
)并将其传递给eval
,我会发现张量图与该图的会话不同。如何指定在不创建新会话的情况下使用Keras会话?任何帮助都将不胜感激
注意。我在python 3.8.5中使用Tensorflow 2.3.1和Keras 2.4.3