tiaya01 2022-11-29 17:16 采纳率: 85.7%
浏览 9
已结题

关于#python#的问题:data.files

#建立模型
import numpy as np
import tensorflow as tf
#读取数据
data = np.load('mnist.npz')
data.files
train_images, train_labels, test_images, test_labels = data['x_train'], data['y_train'], data['x_test'],data['y_test']
print(train_images.shape)
print(train_labels.shape)
print(test_images.shape)
print(test_labels.shape)
#交叉熵
target_y = np.array([1, 0, 0, 0, 0, 0, 0, 0, 0, 0])
predicted_y1 = np.array([0.4, 0.5, 0.1, 0, 0, 0, 0, 0, 0, 0])
predicted_y2 = np.array([0.1, 0.2, 0.7, 0, 0, 0, 0, 0, 0, 0])
-np.sum( target_y * np.log(predicted_y1+0.0000001))
-np.sum( target_y * np.log(predicted_y2+0.0000001))
#搭建网络结构
model = tf.keras.models.Sequential()
model.add(tf.keras.layers.Flatten(input_shape=(28,28)))
model.add(tf.keras.layers.Dense(128, activation = 'relu'))
model.add(tf.keras.layers.Dense(10, activation = 'softmax'))
#编译模型
model.compile(optimizer = 'adam', loss = 'sparse_categorical_crossentropy', metrics = ['accuracy'])
#训练
model.fit(train_images, train_labels, verbose = 1, epochs = 20, validation_data = (test_images,test_labels))
#模型保存
model.save('model_mnist.h5')
#用模型进行预测
import tensorflow as tf
import matplotlib.pyplot as plt
model = tf.keras.models.load_model('model_mnist.h5')
model.summary()
for i in range(30):
    image = plt.imread('testimages/' + str(i)+ '.jpg')
    image_new = image.reshape([1, 28, 28])
    result = model.predict(image_new)[0].argmax()
    print('The', i + 1, 'th picture shows:', result)


img

这是为什么啊?怎么改啊?谢谢!

  • 写回答

1条回答 默认 最新

  • Richard.sysout 2022-11-29 18:11
    关注
    • 没有查到对应的files方法,不知你要的是不是tofile()方法

    img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 12月26日
  • 已采纳回答 12月18日
  • 创建了问题 11月29日

悬赏问题

  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示