tensorflow:张量到ndarray的转换不起作用 - python3.x

时间:2018-01-19 17:23:52

标签: python-3.x numpy tensorflow deep-learning

我正在研究Tensorflow CNN模型,并根据我的方案进行了更改。以前相同的代码在MNIST数据集上运行良好,但是现在,在为我自己的数据集提供标签的占位符y_true之后会导致问题。代码段:

x = tf.placeholder("float",shape=[88, 128])
y_true = tf.placeholder("float",shape=[None, 3])
会话中的

y_true让我错误。代码段:

sess.run(train,feed_dict={x:batch_x, y_true:batch_y,hold_prob:0.5})

错误:

TypeError: The value of a feed cannot be a tf.Tensor object.
Acceptable feed values include Python scalars, strings, lists, 
numpy ndarrays, or TensorHandles.

我通过numpy array将其投放到y = np.array(y_true)并根据y调整了该声明但又错误:

TypeError: unhashable type: 'numpy.ndarray'

按照stackoverflow上的建议尝试了y_true.eval(session = my_sess)但又错误了:

InvalidArgumentError: You must feed a value for placeholder tensor
'Placeholder_4' with dtype float and shape [?,3]

有什么想法吗?这里有什么问题以及如何将其转换/转换为合适的格式。 其他信息:

batch_x = batch of 50 images (total 200K), 88x128 single channel
batch_y = labels (string) same batch as above

1 个答案:

答案 0 :(得分:0)

input[type="checkbox"],
    input[type="radio"] {
        -moz-appearance: none;
        -webkit-appearance: none;
        -ms-appearance: none;
        appearance: none;
        display: block;
        float: left;
        margin-right: -2em;
        opacity: 0;
        width: 1em;
        z-index: -1;
    }

        input[type="checkbox"] + label,
        input[type="radio"] + label {
            text-decoration: none;
            color: #fff;
            cursor: pointer;
            display: inline-block;
            font-size: 1em;
            font-weight: 400;
            padding-left: 2.4em;
            padding-right: 0.75em;
            position: relative;
        }

            input[type="checkbox"] + label:before,
            input[type="radio"] + label:before {
                -moz-osx-font-smoothing: grayscale;
                -webkit-font-smoothing: antialiased;
                font-family: FontAwesome;
                font-style: normal;
                font-weight: normal;
                text-transform: none !important;
            }

            input[type="checkbox"] + label:before,
            input[type="radio"] + label:before {
                background: rgba(144, 144, 144, 0.25);
                border-radius: 3px;
                content: '';
                display: inline-block;
                height: 1.65em;
                left: 0;
                line-height: 1.58125em;
                position: absolute;
                text-align: center;
                top: 0;
                width: 1.65em;
            }

        input[type="checkbox"]:checked + label:before,
        input[type="radio"]:checked + label:before {
            background: #2e3842;
            color: #fff;
            content: '\f00c';
        }

        input[type="checkbox"]:focus + label:before,
        input[type="radio"]:focus + label:before {
            box-shadow: 0 0 0 2px #21b2a6;
        }
input[type="checkbox"] + label:before {
    border-radius: 3px;
}

input[type="radio"] + label:before {
    border-radius: 100%;
}

如果这意味着您的标签是字符串,那可能是错误的原因,因为占位符被定义为浮点数。

否则,请重新检查数据类型和尺寸。