小编tag*_*tag的帖子

Tensorflow GetNext()失败,因为迭代器尚未初始化

tensorflow建议使用tf.data.Dataset导入数据.如果图像的验证尺寸与训练图像不同,是否可以将其用于验证和培训?

import tensorflow as tf
import generator
import glob
import cv2

BATCH_SIZE = 4
filenames_train = glob.glob("/home/user/Datasets/MsCoco/train2017/*.jpg")
filenames_valid = glob.glob("/home/user/Datasets/Set5_14/*.png")

# TensorFlow `tf.read_file()` operation.
def _read_py_function(filename):
  image_decoded = cv2.imread(filename, cv2.IMREAD_COLOR)
  image_blurred_decoded = cv2.GaussianBlur(image_decoded, (1, 1), 0)
  return image_decoded, image_blurred_decoded

# Use standard TensorFlow operations to resize the image to a fixed shape.
def _resize_function(image_decoded, image_blurred_decoded):
  image_decoded.set_shape([None, None, None])
  image_blurred_decoded.set_shape([None, None, None])
  image_resized = tf.cast(tf.image.resize_images(image_decoded, [288, 288]),tf.uint8)
  image_blurred = tf.cast(tf.image.resize_images(image_blurred_decoded, [72, 72]),tf.uint8)
  return image_resized, image_blurred

def _cast_function(image_decoded, image_blurred_decoded):
  image_resized = tf.cast(image_decoded,tf.uint8) …
Run Code Online (Sandbox Code Playgroud)

python tensorflow

8
推荐指数
1
解决办法
6789
查看次数

马修斯相关系数作为 keras 的损失

我尝试使用 tf 后端为 keras 编写自定义损失函数。我收到以下错误

ValueError:一个操作有None梯度。请确保您的所有操作都定义了梯度(即可微分)。没有梯度的常见操作:K.argmax、K.round、K.eval。

def matthews_correlation(y_true, y_pred):
    y_pred_pos = K.round(K.clip(y_pred, 0, 1))
    y_pred_neg = 1 - y_pred_pos

    y_pos = K.round(K.clip(y_true, 0, 1))
    y_neg = 1 - y_pos

    tp = K.sum(y_pos * y_pred_pos)
    tn = K.sum(y_neg * y_pred_neg)

    fp = K.sum(y_neg * y_pred_pos)
    fn = K.sum(y_pos * y_pred_neg)

    numerator = (tp * tn - fp * fn)
    denominator = K.sqrt((tp + fp) * (tp + fn) * (tn + fp) * (tn + fn))

    return 1.0 - …
Run Code Online (Sandbox Code Playgroud)

python keras tensorflow

1
推荐指数
1
解决办法
1551
查看次数

标签 统计

python ×2

tensorflow ×2

keras ×1