Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 培训部';t 2bit x 12重复序列的进度_Python_Tensorflow_Machine Learning_Keras - Fatal编程技术网

Python 培训部';t 2bit x 12重复序列的进度

Python 培训部';t 2bit x 12重复序列的进度,python,tensorflow,machine-learning,keras,Python,Tensorflow,Machine Learning,Keras,我正在测试SimpleRN模型 我的测试数据是超简单的重复三倍2bit*12 [1,0,0,0,1,0,0,0,1,0,0,0,0],[1,0,0,0,0,0,1,0,0],[0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,1] for i in range(0,100): temp = [[1,0,0,0,1,0,0,1,0,0,0,0], [1,0,0,0,0,1,0,0,0,1,0,0], [0,0,1,0,0,0,0,1,0,0,0,1

我正在测试SimpleRN模型

我的测试数据是超简单的重复三倍2bit*12

[1,0,0,0,1,0,0,0,1,0,0,0,0],[1,0,0,0,0,0,1,0,0],[0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,1]

for i in range(0,100):
    temp = [[1,0,0,0,1,0,0,1,0,0,0,0],
        [1,0,0,0,0,1,0,0,0,1,0,0],
        [0,0,1,0,0,0,0,1,0,0,0,1]]
    line.extend(temp)
total = []
for j in range(0,500):
    total.append(line)
total = np.array(total)
print(total.shape) # (500, 300, 12)
它使
(500300,12)
numpy。所有的数据都是重复的,所以我希望训练和预测能够完美地工作

然而,
valu损失
没有减少,预测也没有有效地工作

Epoch 1/5
743/743 [==============================] - 5s 5ms/step - loss: 0.1386 - val_loss: 0.1305
Epoch 2/5
743/743 [==============================] - 3s 4ms/step - loss: 0.1305 - val_loss: 0.1294
Epoch 3/5
743/743 [==============================] - 3s 4ms/step - loss: 0.1299 - val_loss: 0.1292
Epoch 4/5
743/743 [==============================] - 3s 4ms/step - loss: 0.1300 - val_loss: 0.1291
Epoch 5/5
743/743 [==============================] - 3s 4ms/step - loss: 0.1299 - val_loss: 0.1293
[[ 0.67032564 -0.0020391   0.3332582  -0.0095186   0.35370785  0.3042156
   0.00809216  0.7059332   0.00199411  0.30952734 -0.0021943   0.333712  ]]
tf.Tensor([[1 0 0 0 0 0 0 1 0 0 0 0]], shape=(1, 12), dtype=int32)
我希望结果是smillar
[1,0,0,0,1,0,0,0,1,0,0,0]
但是

我需要换个地方,否则我的代码错了

这是我的全部绳索

import tensorflow as tf
from django.core.management.base import BaseCommand, CommandError
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import LSTM,Dropout,Dense
from tensorflow.keras.layers import SimpleRNN
import numpy as np
from tensorflow.keras.optimizers import SGD
from tensorflow.keras.optimizers import Adam
from sklearn.model_selection import train_test_split

def makeModel(input_len,n_in):
    n_hidden = 512
    model = Sequential()
    model.add(SimpleRNN(n_hidden, input_shape=(input_len, n_in), return_sequences=False))
    model.add(Dense(n_hidden, activation="relu")) 
    model.add(Dense(n_in, activation="relu"))
    opt = Adam(lr=0.001)
    model.compile(loss='mse', optimizer=opt)
    model.summary()
    return model
 

line = []
    
for i in range(0,100):
    temp = [[1,0,0,0,1,0,0,1,0,0,0,0],
        [1,0,0,0,0,1,0,0,0,1,0,0],
        [0,0,1,0,0,0,0,1,0,0,0,1]]
    line.extend(temp)
total = []
for j in range(0,500):
    total.append(line)
total = np.array(total)
print(total.shape) # (500, 300, 12)

chordIdList = total
n_in = 12 # dimention
input_len = 3 # length to use prediction.
model = makeModel(input_len,n_in)

input_=[]
target_=[]
for C in chordIdList:
    for i in range(0, len(C) - input_len):  
        input_.append( C[i:i+input_len] )  
        target_.append( C[i+input_len] )  
        
X = np.array(input_)
Y = np.array(target_).reshape((len(input_),1,n_in))

from sklearn.model_selection import train_test_split
x, x_val,y, y_val = train_test_split(X, Y, train_size=0.8, random_state=1)
print(x.shape) # (23760, 3, 12)
print(y.shape) # (23760, 1, 12)
print(x_val.shape) #(5940, 3, 12)
print(y_val.shape) # (5940, 1, 12)

epoch = 5
history = model.fit(x, y, epochs=epoch,validation_data=(x_val, y_val))

in_ = np.array([[1,0,0,0,1,0,0,1,0,0,0,0],
        [1,0,0,0,0,1,0,0,0,1,0,0],
        [0,0,1,0,0,0,0,1,0,0,0,1]]).reshape(1,3,12) 
        
print(in_.shape)
out_ = model.predict(in_)
print(out_)

好的,这里有一个主要的问题,你试图做回归,而你的问题是纯粹的分类

在本部分代码中,您需要做什么:

def makeModel(输入长度,n英寸):
n_hidden=512
模型=顺序()
add(simpleRN(n_隐藏,input_形状=(input_len,n_in),return_sequences=False))
model.add(密集(n_hidden,activation=“relu”))
添加(密集(n_in,activation=“relu”))
opt=Adam(lr=0.001)
compile(loss='mse',optimizer=opt)
model.summary()
回归模型
将最后一层更改为sigmoid激活(输出介于0和1之间,如您的情况)

model.add(密集(n_-in,activation=“sigmoid”))
将损失更改为二进制交叉熵

model.compile(loss='binary\u crossentropy',optimizer=opt)
通过使用relu,您试图将值映射到一个无限函数,这使得学习变得复杂

另外,使用挤压工具挤压Y形孔

history=model.fit(x,np.squence(y),epochs=epoch,validation_data=(x_val,np.squence(y_val)))

请先显示x.shape,y.shape,然后再调用
fit()
我更新了文章。尝试使用标准adam学习率1e-5@Andrey谢谢你的建议,我测试了许多Adam模式(0.1~0.000001),但没有太大变化。最新的文章说明迟了回复,但是你的解释很清楚,我的问题解决了!!!