问题标签 [siamese-network]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
83 浏览

python - 比较孪生网络的嵌入

我使用 tensorflow 2.4 创建了一个连体网络。

我可以成功地训练并使用它来计算所需图像对之间的距离。然而,出于部署效率的目的,我想首先将所有图像转换为它们的 1D 嵌入(我可以使用编码器模型),然后使用子模型直接计算嵌入之间的距离。

但是当我尝试使用以下内容创建比较器模型时:

我得到错误:

那么我如何调整这个网络以拥有一个完整的训练模型,一个将单个图像转换为嵌入的编码器,以及一个直接比较 2 个嵌入的最终模型?

注意:我知道每个人都使用编码器将图像转换为嵌入,然后计算欧几里得距离来计算样本之间的相似性。然而,欧几里得距离和从整个模型计算的距离并不相同,并且遵循以下关系:

在此处输入图像描述

谁不想要一个介于 0 到 1 范围内的漂亮距离度量?

0 投票
0 回答
146 浏览

python - 如何将图像对单独加载到连体神经网络 Keras

对于 Context,我有一个装满图像的验证文件夹和一个 txt 文件来区分图像对是正面的1还是负面的0

在我见过的大多数教程中,它们都有一个锚、正面和负面文件夹。并使用此代码加载图像数据

但问题就在这里,教程(youtube.com/watch?v=UMjW4Db4E_g&list=PLgNJO2hghbmhHuhURAGbe6KWpiYZt0AMH&index=3)从一个文件夹中加载了他们的图像,只有同一张脸,因此很容易提取,因为文件夹充当类,但我的 txt 文件区分图像对只有一个文件夹中存在所有图像我尝试使用数组来分隔图像对。

但我不知道如何将图像对单独加载到连体网络中。

0 投票
1 回答
164 浏览

tensorflow - 实现 TensorFlow Triplet Loss

我想用这里的连体网络教程来实现内置的 TensorFlow 插件版本的三元组损失,但是我似乎不能完全正确。无论我如何处理代码,都会弹出另一个错误,目前

请注意,这只是一个简单的令牌实现,以便了解如何实现 Triplet Loss。我不希望模型真正学到任何东西。
代码:

0 投票
0 回答
27 浏览

deep-learning - Incremental learning for image similarity (Siamese Network) and predicting the label

The requirement of the task is to predict correct labels for the correct product. Suppose, a company produces 100 cork disks with a serial number. Then it captures the surface images of cork disks and trains a neural network (Siamese/CNN/Embeddings) model with the augmented part of the same image for training the texture similarity invariant to rotation, translation or change in brightness. Now the products are shipped to the destination along with this trained model but the images are discarded and new images are captured that have arrived. When these new images (which are different in brightness, translation and rotation from the original images captured at the company and on which the model was trained) are fed into the model, it should predict the correct serial number corresponding to the products.

I have already trained a Siamese network which gives good similarity score when 2 images are compared (one from the company and one taken at the destination). But there are 2 problems with this approach:

  1. During testing, the old images won't be available. They will be discarded since the images are high resolution and takes a lot of space. So we need to train a model which properly maps images to some embedding vectors that we can store and maps it to the serial number.

  2. The model needs to be trained incrementally. Another 1000 disks will be produced the next day and the model should be tuned according to the new dataset.

Any help on this topic would be really appreciated!

0 投票
0 回答
87 浏览

tensorflow - TypeError: _logger_find_caller() 采用 0 到 1 个位置参数,但给出了 2 个

我正在尝试运行可以在此处找到的基线模型:https ://github.com/gniknoil/FG2020-kinship/tree/master/Track1

这是代码:

我得到了错误:

我怎样才能解决这个问题?

我的 Keras 版本是 2.2.4 我的张量流版本是 1.14.0 我使用的是 python 3.8.1 和 anaconda 环境。

我在这里尝试了解决方案:https ://medium.com/the-rising-tilde/typeerror-logger-find-caller-takes-from-0-to-1-positional-arguments-but-2-were- given-cb24b74a6125 不起作用

0 投票
0 回答
34 浏览

tensorflow - I am getting error layer max_pooling2d_111 is incompatible with the layer: expected ndim=4, found ndim=5

I am currently writing the code, the model to take 4 images as an input. All 4 images are passed through the convolution network and then all image's output is concatenated. But while compiling I am getting an error of "Input 0 of layer max_pooling2d_111 is incompatible with the layer: expected ndim=4 found ndim=5. Full shape received: [None, 4, 128, 128, 16]"

Error

I know there is 1 more dimension in the input (size of 4) but how should I do this or solve this issue?

My model code is :

#Build the model

Anyone can please help me or suggest to me how to do it.

0 投票
0 回答
31 浏览

keras - 在 TF/Keras 中解冻 ResNet-Siamese 模型的所有层

我正在尝试训练一个称为 Siamese 模型的双流模型,该模型在其两个分支中的每一个上都有一个预训练的 resnet。我正在使用 Keras TF 后端。由于我的数据集非常小,我首先只解冻每个 resnet 的最后一层(avg_pool),将它们重命名为backbone_model1 和 2,然后将整个模型微调 30 个 Epoch。这是我如何做这部分的片段:

如果我不解冻 resnet 的内层并仅通过微调两个 resnet 的 avg_pool 层来训练模型,那么一切都很好,我可以保存模型。但是,如果在 30 个 epoch 之后我想解冻所有内层,然后在微调所有层的同时再训练模型 30 个 epoch,我会收到此错误:

我开始意识到问题所在:两个 resnet 的层名称相同。所以难怪在第一个时代之后我得到这个“名字已经存在”的错误。在这个答案的帮助下,我将第二个 resnet 的名称更改为以下代码段:

但是我仍然遇到该名称已经存在的相同错误,这是因为我没有在第二个 resnet 中重命名 avg_pool。但是,如果我重命名它,则会收到此错误:

如果我重命名 input_3 层,它会抛出这个错误:

那么我做错了什么?如何微调两个 resnet 的所有层并让这两个输入模型进行训练?

0 投票
0 回答
90 浏览

python - 如何为连体网络生成所有可能的正负对

这个问题类似于这个 SO question。我有以下代码,它就像一个魅力,用于为连体网络配对:

好的,此代码通过为 MNIST 数据集中的每个图像选择对来工作。它通过随机选择同一类(标签)的另一张图像和不同类(标签)的另一个补丁来制作另一对来为该图像构建一对。通过运行代码,返回的两个矩阵的最终形状为:

我想make_pair通过匹配同一类标签正对的图像来扩展上述功能。

而对于负对,我想将每个图像(例如 Img_A)与来自其他类的所有图像进行匹配。

以下是修改后功能的预期示例

上面的函数输出正对 =[[A,A],[B,B],[C,C],[D,D],[E,E]标签为 1. 和负对[[A,B],[B,A],[C,D],[D,A],[E,D]标签为 0 。

我想像这样输出所有可能的负对[[A,B],[A,C],[A,D],[A,E],[B,A],[B,C],[B,D],[B,E],[C,A],[C,B],[C,D],[C,E],[D,A],[D,B],[D,C],[D,E],[E,A],[E,B],[E,C],[E,D]

我的数据集

我想对另一个数据集做一些不同的事情。

我有另一个数组,我们称之为labels2,它为所有420个图像有41个标签,每个标签有10个图像,如下所示:

make_pairs函数的预期输出是

我将函数修改为以下函数,但是当我尝试使用生成的数据训练模型时系统崩溃。

0 投票
0 回答
52 浏览

keras - 如何为连体神经网络准备数据集?

我有点困惑如何为连体神经网络创建数据集。我正在关注教程,了解如何实现具有对比损失的孪生网络。他们正在创建正负对,但在他们的情况下这相对容易,因为它们对于每个类都有相同数量的图像,并且相同的数字将是正对,不同的数字将是负数。

还有一个三元组损失的例子,他们使用名为 Totally Looks Like 的数据集,但在该数据集中有两个文件夹leftright并且文件夹中的每个图像在文件夹left中都有它的正对right。同样,等量的正负对。

但就我而言,我有大约 1000 张未标记的图像(我将手动进行配对)。一个图像可以与 N 个其他图像相似,N 可以是 0 到 len(dataset)(理论上)。因此图像可以是唯一的,也可以具有任意数量的其他类似图像。在这种情况下如何创建对?我在班级之间没有任何平衡。如果五个图像相似,我是否创建所有可能的配对/组合(我的意思是组合,例如,配对 1,5 和 5,1 是两个不同的配对)?如果图像是唯一的,我什至会在数据集中使用它吗?

0 投票
0 回答
28 浏览

matlab - 燃烧的图像相似性

有人可以建议我一种方法来比较相同燃烧的 2 张图片的相似性。

它需要是一个无监督的神经网络。Per Combustion 每帧有 2 张图片是从不同的相机拍摄的,总共有 60 帧。图片具有相同的大小和分辨率。一台相机有滤镜,另一台没有。这 2 张图片可以有相似的图案或不同的图案。总之,我有点需要比较边缘。输出将相似或不相似。

以下是图案不相似的图片对示例。

在此处输入图像描述

我有大约 60gb 的数据,所以有很多图片。大多数图片都是示例的变体。

我的建议是具有卷积和反向传播的连体网络,但我不确定我是否可以正确训练网络,或者更好地如何训练它?

用什么方法开始向网络展示它需要寻找什么是好的。

提前致谢。对于初学者来说,您将是一个很好的帮助。