3

Ich versuche ein CNN zu bekommen, um exponentielle Signale zu klassifizieren (zwei Klassen). Für den Anfang habe ich die Daten für Zug und Validierung nicht geteilt, sondern ich versuche nur, ob ich es trainieren kann oder nicht.Signalverarbeitung mit CNN im Tensorflow. TypeError: DataType float32 für attr 'Tlabels' nicht in der Liste der erlaubten Werte: int32, int64

Ich habe einige Schwierigkeiten zu verstehen, was logits sind? Sind sie dasselbe wie normalisierte Daten?

Ich habe diese Musik Genre Klassifizierung verwendet und versucht zu sehen, ob ich dieses Modell für meinen Datensatz anpassen kann. https://github.com/RobRomijnders/cnn_music/blob/master/CNN_music_main.py

Ich vermisse einige Teile des Verständnisses, kann jemand bitte helfen/vorschlagen, wo ich falsch liege?

Hier ist der Fehler, den ich nach dem Schritt Verlust = tf.nn.sparse_softmax_cross_entropy_with_logits erhalten (h_fc2, y _) -

Traceback (most recent call last): 
    File "/home/raisa/PycharmProjects/NN_model/patterns.py", line 96, in <module> 
    loss = tf.nn.sparse_softmax_cross_entropy_with_logits(h_fc2,y_) 
    File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/nn_ops.py", line 265, in sparse_softmax_cross_entropy_with_logits 
    logits, labels, name=name) 
    File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gen_nn_ops.py", line 962, in _sparse_softmax_cross_entropy_with_logits 
    features=features, labels=labels, name=name) 
    File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/op_def_library.py", line 486, in apply_op 
_Attr(op_def, input_arg.type_attr)) 
    File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/op_def_library.py", line 59, in _SatisfiesTypeConstraint 
", ".join(dtypes.as_dtype(x).name for x in allowed_list))) 
TypeError: DataType float32 for attr 'Tlabels' not in list of allowed values: int32, int64 

Process finished with exit code 1 

Mein Code so weit

import numpy as np 
import tensorflow as tf 
import matplotlib.pyplot as plt 
import random 
from tensorflow.python.framework import ops 
from tensorflow.python.ops import clip_ops 
from bnf import * 

#hyperparameters 
Batch_size= 100 
max_iteration= 50 
learning_rate=1000 
filt_1= [10,1,1] 
num_fc_1 = 10 
dropout = 0.5 
num_classes = 2 

#training data 
lorange= 1 
hirange= 15 
amplitude= 10 
t= 10 
random.seed() 
tau=np.random.uniform(lorange,hirange) 

def generate_data(randomsignal): 
    X= np.arange(t) 
    Y= amplitude*np.exp(-X/tauA) 
    return X, Y 


#tensors for input data 

X= tf.placeholder(tf.float32, shape= [None, 10]) 
y_= tf.placeholder(tf.float32, shape= [None]) 
Y_class= tf.argmax(y_, dimension=1) 
bn_train = tf.placeholder(tf.bool) 
keep_prob = tf.placeholder('float', name = 'dropout_keep_prob') 

def weight_variable(shape, name): 
    initial = tf.truncated_normal(shape, stddev=0.1) 
    return tf.Variable(initial, name = name) 

def bias_variable(shape, name): 
    initial = tf.constant(0.1, shape=shape) 
    return tf.Variable(initial, name = name) 



def conv2d(X, W): 
    return tf.nn.conv2d(X, W, strides=[1, 1, 1, 1], padding='SAME') 

def max_pool_2x2(x): 
    return tf.nn.max_pool(x, ksize=[1, 2, 2, 1], 
         strides=[1, 2, 2, 1], padding='SAME') 

with tf.name_scope("Reshaping_data") as scope: 
    X_node = tf.reshape(X, [-1,2,1,1]) 


with tf.name_scope("Conv1") as scope: 
    W_conv1 = weight_variable([filt_1[1], 1, 1, filt_1[0]], 'Conv_Layer_1') 
    b_conv1 = bias_variable([filt_1[0]], 'bias_for_Conv_Layer_1') 
    a_conv1 = conv2d(X_node, W_conv1) + b_conv1 
    h_conv1 = tf.nn.relu(a_conv1) 


with tf.name_scope('max_pool1') as scope: 
    h_pool1 = tf.nn.max_pool(h_conv1, ksize=[1, filt_1[2], 1, 1], 
         strides=[1, filt_1[2], 1, 1], padding='VALID') 

    width_pool1 = int(np.floor((10-filt_1[2])/filt_1[2]))+1 
    size1 = tf.shape(h_pool1) 

with tf.name_scope('Batch_norm1') as scope: 
    a_bn1 = batch_norm(h_pool1,filt_1[0],bn_train,'bn') 
    h_bn1 = tf.nn.relu(a_bn1) 

with tf.name_scope("Fully_Connected1") as scope: 
    W_fc1 = weight_variable([width_pool1 * filt_1[0], num_fc_1], 'Fully_Connected_layer_1') 
    b_fc1 = bias_variable([num_fc_1], 'bias_for_Fully_Connected_Layer_1') 
    h_flat = tf.reshape(h_bn1, [-1, width_pool1 * filt_1[0]]) 
    h_flat = tf.nn.dropout(h_flat, keep_prob) 
    h_fc1 = tf.nn.relu(tf.matmul(h_flat, W_fc1) + b_fc1) 



with tf.name_scope("Output_layer") as scope: 
    h_fc1_drop = tf.nn.dropout(h_fc1, keep_prob) 
    W_fc2 = tf.Variable(tf.truncated_normal([num_fc_1, num_classes], stddev=0.1),name = 'W_fc2') 
    b_fc2 = tf.Variable(tf.constant(0.1, shape=[num_classes]),name = 'b_fc2') 
    h_fc2 = tf.matmul(h_fc1_drop, W_fc2) + b_fc2 
size3 = tf.shape(h_fc2) 

with tf.name_scope("SoftMax") as scope: 
    loss = tf.nn.sparse_softmax_cross_entropy_with_logits(h_fc2,y_) 
    cost = tf.reduce_sum(loss)/batch_size 
    loss_summ = tf.scalar_summary("cross entropy_loss", cost) 
+0

Bitte [bearbeiten] Ihre ques Fügen Sie den vollständigen Traceback hinzu oder geben Sie an, welche Codezeile den Fehler verursacht. – martineau

+0

Hallo Ich habe die Frage bearbeitet und das Traceback hinzugefügt. Grundlegend dieser Fehler tritt auf, nachdem ich versuche, Softmax zu berechnen und Entropy- Verlust = tf.nn.sparse_softmax_cross_entropy_with_logits (h_fc2, y_) – zerogravty

+0

Der Fehler besagt, dass Sie etwas übergeben, das 32-Bit-Fließkommawerte aber nur 32 hat oder 64-Bit-Ganzzahlen sind akzeptabel. Ich vermute, dass es an der Zeile 'y_ = tf.placeholder (tf.float32, shape = [None]) 'liegt - also versuche das erste Argument in' tf.int32' zu ändern. Wenn das unerwünscht ist, versuchen Sie, alle 'float32'-Werte direkt vor dem Aufruf in die letzteren zu konvertieren. – martineau

Antwort

1

Ihre wahre Etiketten sein müssen in int32 oder int64 Format, ändern, um die y_ zu

y_= tf.placeholder(tf.int32, shape= [None])

Verwandte Themen