Python Keras模型预测的回报是什么?

Python Keras模型预测的回报是什么?,python,tensorflow,keras,deep-learning,Python,Tensorflow,Keras,Deep Learning,我正在构建一个自动编码器网络,用于在单列文本列表中查找异常值 我提取每个字符,将其转换为ASCII码,并将它们放入一个数组中 数组的每一行都是我输入的一行,数组中的每个元素都是字符ascii码的整数表示 每个数组都有我数组中最大元素的大小,较小元素的右边用零填充 因此,我最终使用了带有ascii码的Numpy数组,我创建了一个自动编码器网络,这样我就可以找到那些不遵循某种模式的数组,它们从其他数组中脱颖而出 我的全部代码是: 导入系统 从keras导入输入,模型 将matplotlib.pypl

我正在构建一个自动编码器网络,用于在单列文本列表中查找异常值

我提取每个字符,将其转换为ASCII码,并将它们放入一个数组中

数组的每一行都是我输入的一行,数组中的每个元素都是字符ascii码的整数表示

每个数组都有我数组中最大元素的大小,较小元素的右边用零填充

因此,我最终使用了带有ascii码的Numpy数组,我创建了一个自动编码器网络,这样我就可以找到那些不遵循某种模式的数组,它们从其他数组中脱颖而出

我的全部代码是:

导入系统 从keras导入输入,模型 将matplotlib.pyplot作为plt导入 从keras.layers导入稠密 将numpy作为np导入 从pprint导入pprint 从google.colab导入驱动器 #蒙塔阿奎沃谷歌路 安装(“/content/drive”) 打开('/content/drive/My drive/Colab Notebooks/drawables.txt',r')作为arquivo: dados=arquivo.read().splitlines() #定义我们的目标是什么 #梅奥·埃莱门托 def tamanho_maior_elemento(列表A): maior=0 对于列表A中的elemento: tamanho_elemento=len(elemento) 如果tamanho_elemento>maior: maior=tamanho_elemento 回程票 #定义所有要素的含义 #我们的目标是实现我们的目标 #ascii,转换器的antes de converter são adicionados将数据归零 #我是梅斯莫·塔曼霍。 def texto_para_ascii(列表,tamanho_maior_elemento): #帕拉卡达林哈酒店 lista_ascii=list() 对于列表A中的elemento: elemento_ascii_lista=list() #科罗卡零度拉多达字符串 elemento_com_zeros=elemento.ljust(tamanho_maior_elemento,“0”) 对于elemento_com_零中的字符: 附加(ord(字符)) lista_ascii.append(elemento_ascii_lista) 返回列表a_ascii def ascii_para_texto(列表A): #帕拉卡达林哈酒店 lista_ascii=list() 对于列表A中的elemento: elemento_ascii_lista=list() 对于elemento中的caractere: elemento_ascii_lista.append(chr(字符)) elemento_ascii_string=”“.join(elemento_ascii_lista) lista_ascii.append(elemento_ascii_字符串) 返回列表a_ascii #佩加·塔曼霍·多梅奥·莱门托 tamanho_maior_elemento=tamanho_maior_elemento(护墙板) #佩加·塔曼霍·达利斯塔 tamanho_lista=len(护墙板) #转换为墙裙 护墙板ascii=texto\u para\u ascii(护墙板,tamanho\u maior\u elemento) #转换linha de dados em ascii参数数组numpy np_dados_ascii=np.数组(dados_ascii) #定义tamanho da camada Compmida tamanho_compimido=int(tamanho_maior_elemento/5) #这是一个很好的输入法 护墙板输入=输入(形状=(tamanho_maior_elemento,) #我的天啊,我的天啊,我的天啊,我的天啊 隐藏=密集(tamanho_compimido,activation='relu')(数据输入) #我的天啊,我的孩子们,我的孩子们 输出=密集(tamanho\u maior\u elemento,激活='relu')(隐藏) #resultado=密集(tamanho_maior_elemento,activation='sigmoid')(输出) resultado=稠密(tamanho_maior_elemento)(输出) #克里亚奥莫代洛酒店 自动编码器=模型(输入=数据\输入,输出=结果) #编译o模式 编译(优化器='adam',loss='mse') #Faz o fit com os护墙板 history=autoencoder.fit(np_dados_ascii,np_dados_ascii,epochs=20) #时代图景 plt.绘图(历史记录[“损失”]) plt.ylabel(“损失”) plt.xlabel(“时代”) plt.show() #佩加·萨伊达:你能预测吗 predict=自动编码器。predict(np\U dados\U ascii) #现在怎么办? 我想知道的是,我已经预测了值,下一步是什么?我的意思是,keras的model.predict函数返回了一个浮点值数组。如何将其恢复为ascii字符,以便查看预测的文本


我不知道我说的对不对,英语不是我的主要语言,我对此完全不知所措。

您可以将ASCII数字转换回文本,并将结果可视化。使用,一个python内置函数。它需要输入0到255范围内的整数值。因此,请确保您的模型预测此范围之间的值

predict = np.random.uniform(0,255,(1,100)) # Replace with your original prediction
predict_text=[]
for i in range(predict.shape[1]):
  predict_text.append(chr(int(predict[0][i])))
predict_text =  np.expand_dims(np.asarray(predict_text),axis=0)