我有一个非常基本的查询。我制作了 4 个几乎相同的(差异是输入形状)CNN,并在连接到完全连接层的前馈网络时将它们合并。
几乎相同的 CNN(s) 的代码:
model3 = Sequential()
model3.add(Convolution2D(32, (3, 3), activation='relu', padding='same',
input_shape=(batch_size[3], seq_len, channels)))
model3.add(MaxPooling2D(pool_size=(2, 2)))
model3.add(Dropout(0.1))
model3.add(Convolution2D(64, (3, 3), activation='relu', padding='same'))
model3.add(MaxPooling2D(pool_size=(2, 2)))
model3.add(Flatten())
Run Code Online (Sandbox Code Playgroud)
但是在张量板上,我看到所有的 Dropout 层都是相互连接的,并且 Dropout1 的颜色与 Dropout2、3、4 等颜色不同,它们都是相同的颜色。
我有一个关于带有noise_shape参数的Keras函数Dropout的问题。
问题 1:
是什么意思,如果你的输入有形状(batch_size时,时间步长,功能),你想辍学面膜是所有时间步长一样,你可以使用noise_shape =(batch_size时,1,特点)3,什么是增加的好处这个论点?
这是否意味着随着时间步长被丢弃的神经元数量是相同的?这意味着在每个时间步长 t,都会有 n 个神经元被丢弃?
问题 2: 创建模型时是否必须在 noise_shape 中包含“batch_size”?--> 看下面的例子。
假设我有一个形状为 (10000, 1, 100, 2) -->(数据数量、通道、时间步长、特征数量)的多元时间序列数据。
然后我创建批次大小为 64 --> (64, 1, 100, 2)
如果我想创建一个带有 dropout 的 CNN 模型,我会使用 Keras 函数式 API:
inp = Input([1, 100, 2])
conv1 = Conv2D(64, kernel_size=(11,2), strides(1,1),data_format='channels_first')(inp)
max1 = MaxPooling2D((2,1))(conv1)
max1_shape = max1._keras_shape
drop1 = Dropout((0.1, noise_shape=[**?**, max1._keras_shape[1], 1, 1]))
Run Code Online (Sandbox Code Playgroud)
因为层max1的输出shape应该是(None, 64, 50, 1),我不能给问号赋值None(对应batch_size)
我想知道我应该如何应对这种情况?我应该使用 (64, 1, 1) 作为噪声形状吗?或者我应该定义一个名为“batch_size”的变量,然后将它传递给这个参数,比如 (batch_size, 64, 1, 1)?
我正在使用PyCaffe来实现受VGG 16层网络启发的神经网络.我想使用GitHub页面提供的预训练模型.通常,这通过匹配图层名称来实现.
对于我的"fc6"
图层,我在train.prototxt文件中有以下定义:
layer {
name: "fc6"
type: "InnerProduct"
bottom: "pool5"
top: "fc6"
inner_product_param {
num_output: 4096
}
}
Run Code Online (Sandbox Code Playgroud)
以下是VGG-16部署体系结构的prototxt文件.请注意,"fc6"
他们的原型文本与我的相同(除了学习率,但这是无关紧要的).值得注意的是,我的模型中的输入大小也相同:3通道224x224px图像.
我一直非常密切地关注本教程,并且给我一个问题的代码块如下:
solver = caffe.SGDSolver(osp.join(model_root, 'solver.prototxt'))
solver.net.copy_from(model_root + 'VGG_ILSVRC_16_layers.caffemodel')
solver.test_nets[0].share_with(solver.net)
solver.step(1)
Run Code Online (Sandbox Code Playgroud)
第一行加载我的求解器原型,然后第二行从预先训练的模型中复制权重(VGG_ILSVRC_16_layers.caffemodel
).解算器运行时,我收到此错误:
Cannot copy param 0 weights from layer 'fc6'; shape mismatch. Source param
shape is 1 1 4096 25088 (102760448); target param shape is 4096 32768 (134217728).
To learn this layer's parameters from scratch rather than copying from a …
Run Code Online (Sandbox Code Playgroud) 我使用keras的VGG-16网络.这是细节
我的问题是如何使用这个网进行微调,我必须使用这个网络的224*224的图像大小?当我使用这个网时,我必须使用1000个课程?如果我不使用1000个类,则会导致错误
例外:层形状(4096L,10L)与重量形状(4096,1000)不兼容.
求助,谢谢!
我对DL和Keras比较陌生.
我试图在Keras中使用预训练的VGG16来实现感知损失但是有一些麻烦.我已经发现了这个问题,但我仍在努力:/
我的网络应该做的简短说明:
我有一个CNN(后来称为mainModel),它将灰度图像作为输入(#TrackData,512,512,1)并输出相同大小的灰度图像.网络应该减少图像中的伪像 - 但我认为这对于这个问题并不重要.我不想使用例如MSE作为损失函数,而是希望实现感知损失.
我想做什么(我希望我已经正确地理解了感知损失的概念):
我想将一个lossModel(带有固定参数的预先训练的VGG16)附加到我的mainModel.然后我想将mainModel的输出传递给lossModel.另外,我将标签图像(Y_train)传递给lossModel.此外,我使用例如MSE比较lossModel的特定层(例如block1_conv2)处的激活,并将其用作损失函数.
到目前为止我做了什么:
加载数据并创建mainModel:
### Load data ###
with h5py.File('.\train_test_val.h5', 'r') as hf:
X_train = hf['X_train'][:]
Y_train = hf['Y_train'][:]
X_test = hf['X_test'][:]
Y_test = hf['Y_test'][:]
X_val = hf['X_val'][:]
Y_val = hf['Y_val'][:]
### Create Main Model ###
input_1 = Input((512,512,9))
conv0 = Conv2D(64, (3,3), strides=(1,1), activation=relu, use_bias=True, padding='same')(input_1)
.
.
.
mainModel = Model(inputs=input_1, outputs=output)
Run Code Online (Sandbox Code Playgroud)
创建lossModel,将其附加到mainModel并修复params:
### Create Loss Model (VGG16) ###
lossModel = vgg16.VGG16(include_top=False, weights='imagenet', input_tensor=mainModel.output, input_shape=(512,512, 1))
lossModel.trainable=False
for layer …
Run Code Online (Sandbox Code Playgroud) 我想使用VGG预训练模型提取368x368尺寸图像的特征。根据文档,VGGnet接受224x224尺寸的图像。有没有办法给Keras VGG提供可变大小的输入?
这是我的代码:
# VGG Feature Extraction
x_train = np.random.randint(0, 255, (100, 224, 224, 3))
base_model = VGG19(weights='imagenet')
modelVGG = Model(inputs=base_model.input, outputs=base_model.get_layer('block4_conv2').output)
block4_conv2_features = modelVGG.predict(x_train)
Run Code Online (Sandbox Code Playgroud)
编辑代码(有效!)
# VGG Feature Extraction
x_train = np.random.randint(0, 255, (100, 368, 368, 3))
base_model = VGG19(weights='imagenet', include_top=False)
modelVGG = Model(inputs=base_model.input, outputs=base_model.get_layer('block4_conv2').output)
block4_conv2_features = modelVGG.predict(x_train)
Run Code Online (Sandbox Code Playgroud) 我想编写一个函数,它接受两个自然参数,并返回一个可能的相等证明.
我正在尝试
equal : (a: Nat) -> (b: Nat) -> Maybe ((a == b) = True)
equal a b = case (a == b) of
True => Just Refl
False => Nothing
Run Code Online (Sandbox Code Playgroud)
但是我收到以下错误
When checking argument x to constructor Prelude.Maybe.Just:
Type mismatch between
True = True (Type of Refl)
and
Prelude.Nat.Nat implementation of Prelude.Interfaces.Eq, method == a
b =
True (Expected type)
Specifically:
Type mismatch between
True
and
Prelude.Nat.Nat implementation of Prelude.Interfaces.Eq, method == a
b
Run Code Online (Sandbox Code Playgroud)
这是正确的方法吗?
而且,作为奖金问题,如果我这样做
equal : …
Run Code Online (Sandbox Code Playgroud) 我有一个非常简单的问题,但在谷歌中找不到任何相关信息。
我使用 NUnit3 和 NunitAdapter 通过 Visual Studio 或构建代理上的 dotnet 测试来运行我的测试。我需要添加属性[assembly: Parallelizable()]
和[assembly: LevelOfParallelism()]
.
但 netCore 项目没有 assemblyInfo.cs,我不知道在哪里添加此属性。应该放在哪里?
PS:我以前从未使用过 netCore,我们几天前迁移到它。
如何在 Coq 中压缩两个向量?我尝试了下面的代码,但遇到了问题:
Require Import Vectors.Vector.
Import VectorNotations.
(* Non exhaustive pattern-matching: no clause found for patterns [], _ :: _ *)
Fail Fixpoint zip {A B : Type} {n : nat} (a : t A n) (b : t B n) : t (A * B) n :=
match a, b with
| ha :: ta, hb :: tb => (ha, hb) :: zip ta tb
| [], [] => []
end.
(* The term "tb" has type "t …
Run Code Online (Sandbox Code Playgroud) 在我项目的某个地方,我需要创建一个具体的泛型类型,将泛型类型定义(带有单个参数)和该参数的类型作为参数。
为此,我编写了一个非常简单的方法:
Type MakeGenericType(Type definition, Type parameter)
{
return definition.MakeGenericType(parameter);
}
Run Code Online (Sandbox Code Playgroud)
但是,在某些时候,我需要List<List<T>>
使用给定的元素 type创建一个类型T
。尽管我能够List<List<T>>
使用我的方法创建一个类型,但随后尝试从中创建一个具体类型List<List<int>>
失败了 - 请参阅下面的代码:
var genericList = MakeGenericType(typeof(List<>), typeof(List<>)); // success
MakeGenericType(genericList, typeof(int)); // exception
Run Code Online (Sandbox Code Playgroud)
mscorlib.dll 中发生类型为“System.InvalidOperationException”的未处理异常
附加信息:System.Collections.Generic.List`1[System.Collections.Generic.List`1[T]] 不是 GenericTypeDefinition。MakeGenericType 只能在 Type.IsGenericTypeDefinition 为 true 的类型上调用。
此外,以下调用甚至不会编译:
MakeGenericType(typeof(List<List<>>), typeof(int));
Run Code Online (Sandbox Code Playgroud)
我已经检查了这个关于IsGenericTypeDefinition
和之间差异的问题ContainsGenericParameters
。但是,我仍然没有想法,如何处理像genericList
.
显然,使用反射我可以构造一个类型对象,这与它无关 - 这对我来说很困惑。
所以问题是,如何从包含泛型类型定义作为参数的泛型创建具体类型?有可能吗?