ValueError:检查时出错:预期density_1_input具有2维,但数组的形状为(1,16,16,512)

时间:2019-01-05 01:57:08

标签: python tensorflow keras vgg-net transfer-learning

我遇到以下错误:

  

ValueError:检查时出错:预期density_1_input具有2   尺寸,但数组的形状为(1、16、16、512)

发生在此行:

  

img_class = model.predict_classes(feature_value)

关于如何解决此问题的任何想法吗?

这是完整的脚本:

SELECT date_part('day', users.created::date) as day_of_month,
       count(users.id) FILTER (
           WHERE users.created::date < now() - interval '12 month'
           AND users.created::date > now() - interval '13 month') AS month_12,
       count(users.id) FILTER (
           WHERE users.created::date > now() - interval '1 month') AS month_1
FROM users
WHERE (
       (
            users.created::date < now() - interval '12 month'
        AND users.created::date > now() - interval '13 month'
       ) OR users.created::date > now() - interval '1 month'
      )
  AND users.thirdpartyid = 100
GROUP BY day_of_month
ORDER BY day_of_month

谢谢。

1 个答案:

答案 0 :(得分:1)

您正在尝试使用4D数组进行预测:

feature_value= np.reshape(feature_value,(1,16,16,512))

但是您在2D阵列上训练了网络:

train_features = np.reshape(train_features, (number_of_training_samples,16*16*512))

您应该使用在模型上训练过的相同形状进行预测:

feature_value= np.reshape(feature_value,(1,16*16*512))