小编rAy*_*yyy的帖子

Keras 使用 TimeDistributed 预训练 CNN

这是我的问题,我想在 TimeDistributed 层中使用预训练 CNN 网络之一。但是我在实施它时遇到了一些问题。

这是我的模型:

def bnn_model(max_len):
    # sequence length and resnet input size
    x = Input(shape=(maxlen, 224, 224, 3))

    base_model = ResNet50.ResNet50(weights='imagenet',  include_top=False)

    for layer in base_model.layers:
        layer.trainable = False

    som = TimeDistributed(base_model)(x)

    #the ouput of the model is [1, 1, 2048], need to squeeze
    som = Lambda(lambda x: K.squeeze(K.squeeze(x,2),2))(som)

    bnn = Bidirectional(LSTM(300))(som)
    bnn = Dropout(0.5)(bnn)

    pred = Dense(1, activation='sigmoid')(bnn)

    model = Model(input=x, output=pred)

    model.compile(optimizer=Adam(lr=1.0e-5), loss="mse", metrics=["accuracy"])

    return model
Run Code Online (Sandbox Code Playgroud)

编译模型时我没有错误。但是当我开始训练时,我收到以下错误:

tensorflow/core/framework/op_kernel.cc:975] Invalid argument: You must feed a value …
Run Code Online (Sandbox Code Playgroud)

python keras tensorflow recurrent-neural-network resnet

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

从std :: vector创建tensorflow :: tensor的最有效方法

所以我的问题是要知道是否有一种方法可以将值直接从vector(但我们也可以考虑array)传递给a tensorflow::tensor

我知道的唯一方法是一个一个地复制每个值。

示例(2D矢量)

tensorflow::Tensor input(tensorflow::DT_FLOAT, tensorflow::TensorShape({50, 20})); 
auto input_map = input.tensor<float, 2>();


for (int b = 0; b < 50; b++) {
  for (int c = 0; c < 20; c++) {
    input_map(b, c) = (vector_name)[b][c];
  }
}
Run Code Online (Sandbox Code Playgroud)

有更方便的方法吗?

例如arrayvector

int x[3] = {1, 2, 3};
std::vector<int> v(x, x + sizeof x / sizeof x[0]);
Run Code Online (Sandbox Code Playgroud)

c++ tensorflow

5
推荐指数
2
解决办法
5555
查看次数