IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 人工智能 -> maskrcnn边缘检测 -> 正文阅读

[人工智能]maskrcnn边缘检测

def mrcnn_edge_loss_graph(target_masks, target_class_ids, pred_masks):
    """Edge L2 loss for mask edge head

    target_masks: [batch, num_rois, height, width].
        A float32 tensor of Value 0 or 1(boolean?). Use zero padding to fill array
    target_class_ids: [batch, num_rois]. Integer class IDs. Zeros padded.
    pred_masks: [batch, proposal, height, width, num_classes] float32 tensor
                with value from 0 to 1(soft mask)(more information)
    """
    # Reshape for simplicity. Merge first two dimensions into one
    # 即将batch 和 num_rois 合并为一项
    target_class_ids = K.reshape(target_class_ids, (-1,))
    mask_shape = tf.shape(target_masks)
    target_masks = K.reshape(target_masks, (-1, mask_shape[2], mask_shape[3]))
    pred_shape = tf.shape(pred_masks)
    pred_masks = K.reshape(pred_masks,
                           (-1, pred_shape[2], pred_shape[3], pred_shape[4]))
    # Permute predicted masks to [N, num_classes, height, width]
    pred_masks = tf.transpose(pred_masks, [0, 3, 1, 2])

    # Only positive ROIs contribute to the loss. (正的ROI是相对BG而言吗)
    # And only the class specific mask of each ROI
    # tf.where 获得索引值
    # tf.gather 根据索引值从张量中获得元素构成新张量Tensor
    # tf.cast 类型转换
    # tf.stack
    positive_ix = tf.where(target_class_ids > 0)[:, 0]
    positive_class_ids = tf.cast(
        tf.gather(target_class_ids, positive_ix), tf.int64)
    indices = tf.stack([positive_ix, positive_class_ids], axis=1)

    # Gather the masks (predicted and true) that contribute to loss
    y_true = tf.gather(target_masks, positive_ix)
    y_pred = tf.gather_nd(pred_masks, indices)

    # shape: [batch * rois, height, width, 1]
    y_true = tf.expand_dims(y_true, -1)
    y_pred = tf.expand_dims(y_pred, -1)

    y_true = 255 * y_true
    y_pred = 255 * y_pred

    # shape: [3, 3, 1, 2]
    sobel_kernel = tf.constant([[[[1, 1]], [[0, 2]], [[-1, 1]]],
                                [[[2, 0]], [[0, 0]], [[-2, 0]]],
                                [[[1, -1]], [[0, -2]], [[-1, -1]]]], dtype=tf.float32)

    # Conv2D with kernel
    edge_true = tf.nn.conv2d(y_true, sobel_kernel, strides=[1, 1, 1, 1], padding="SAME")
    edge_pred = tf.nn.conv2d(y_pred, sobel_kernel, strides=[1, 1, 1, 1], padding="SAME")

    # abs and clip
    edge_true = tf.clip_by_value(abs(edge_true), 0, 255)
    edge_pred = tf.clip_by_value(abs(edge_pred), 0, 255)

    # Mean Square Error(MSE) Loss
    return tf.reduce_mean(tf.square(edge_true / 255. - edge_pred / 255.))

  人工智能 最新文章
2022吴恩达机器学习课程——第二课(神经网
第十五章 规则学习
FixMatch: Simplifying Semi-Supervised Le
数据挖掘Java——Kmeans算法的实现
大脑皮层的分割方法
【翻译】GPT-3是如何工作的
论文笔记:TEACHTEXT: CrossModal Generaliz
python从零学(六)
详解Python 3.x 导入(import)
【答读者问27】backtrader不支持最新版本的
上一篇文章      下一篇文章      查看所有文章
加:2021-07-28 00:15:18  更:2021-07-28 00:15:22 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年5日历 -2024/5/9 5:08:55-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码