3 개의 입력 "뉴런"(높이, 무게, 체지방의 3 가지 기능)과 2 개의 출력 "뉴런"으로 구성된 간단한 신경망을 실행하여 새 데이터를 분류하고 싶습니다. softmax 로지스틱 회귀, 남성 또는 여성). 모델에 데이터 입력을 연습하기 위해이 데이터를 구성했습니다. 텐서 플로우 웹 사이트의 MNIST 튜토리얼과 비슷하지만 784 개의 입력 피쳐 대신에 훨씬 간단하고 실제적인 MNIST 이미지의 픽셀 - 우리 모델을 훈련시키기 위해 여러 개의 일괄 처리 대신 3 개만을 가지고 있습니다. 동일한 데이터에서 여러 번 훈련하십시오.)Tensorflow : numpy ndarray를 자리 표시 자에 넣을 때 InvalidArgumentError
이 방법은 k-means 클러스터링과 같은 간단한 알고리즘을 통해 수행 할 수 있습니다. 그러나 작을 때 데이터를 입력하는 방법을 배우고 싶습니다.
나는이 얻을 : 나는 (tf.float32과 동일 함) np.float32에 목록 값을 변환 때문에
InvalidArgumentError: You must feed a value lue for placeholder tensor 'Placeholder' with dtype float
내가 ... 이유를 알고하지 않습니다와 나는 바로 그것을 확인 함수를 정의하기 전에. 아직, 나는 아직도이 성가신 오류를 얻는다. 첫 번째 palceholder에로드 할 때 아무리 변경 무엇을, 난 항상이 오류를 얻을 : X.
를이 내 코드입니다 :
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
import tensorflow as tf
import time
#TRAINING DATA
#3 VIs en columna
#est, pes, %gb_fat
persones = np.asarray([[175,70,2], #H
[155,45,15], #F
[190,85,8], #H
[185,90,7], #H
[169,60,3], #H
[150,40,13], #F
[173,69,12]], dtype = np.float32) #H
# H , D --> one-hot!!
etiquetes = np.asarray([[1,0],
[0,1],
[1,0],
[1,0],
[1,0],
[0,1],
[1,0]], dtype = np.float32)
#TESTING DATA
persones_evaluacio = np.asarray([[190,89,4], #H
[155,52,16], #D
[171,55,18]], dtype = np.float32) #D
etiquetes_evaluacio = np.asarray([[1,0],
[0,1],
[0,1]], dtype = np.float32)
#WE TEST THE DATATYPES
print("dades dels nombres: ",type(persones[0][0]))
print("tipus estructura de dades de la matriu: ", type(persones))
time.sleep(3)
print("files de la matriu:")
time.sleep(0.5)
for i in range(len(persones)):
print(persones[i])
time.sleep(0.5)
def classifica_H_D(nombre_VIs, categories_VD):
#placeholders
x = tf.placeholder(tf.float32, [None,nombre_VIs])
y_reals = tf.placeholder(tf.float32, [None,categories_VD])
#variables
w = tf.Variable(tf.zeros([nombre_VIs, categories_VD], dtype = tf.float32))
b = tf.Variable(tf.zeros([categories_VD], dtype = tf.float32))
#DEFINE MODEL
y_predits = tf.nn.softmax(tf.matmul(x,w) + b)
# define LOSS FUNCTION
cross_entropy = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(labels=y_reals, logits=y_predits))
#define optimizer to get cross_entropy minimized
train_step = tf.train.GradientDescentOptimizer(0.001).minimize(cross_entropy)
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
print("finsaqui")
time.sleep(2)
for i in range(1000): #iterate over same data.
sess.run(train_step, feed_dict = {x : persones, y_reals : etiquetes})
if i%50:
print(w.eval(), sess.run(cross_entropy))
prediccio_correcta = tf.equal(tf.argmax(y_predit,1), tf.argmax(y_correctes,1))
accuracy = tf.reduce_mean(tf.cast(prediccio_correcta, tf.float32))
return "\naccuracy: {:.2f}".format(sess.run(accuracy, feed_dict={x: persones_evaluacio, y_reals: etiquetes_evaluacio}))
print(classifica_H_D(3,2))
대단히 감사합니다 !!!!! 그것은 효과가있다! :) :) – americansanti