Tensorflow学习过程问题整理(TensorFlow版本:1.13.1,Python版本:3.6)

1.代码错误整理

(1)Spyder中Python代码运行出错
错误信息:Check failed: PyBfloat16_Type.tp_base != nullptr,
原因:numpy版本问题
解决方法:python -m pip install --upgrade numpy
(2)使用keras下载fashion_mnist出错
错误原因:无法连接外网,下载不了
解决办法:下载数据集到C:\Users\用户名.keras\datasets\fashion-mnist中,不需要更改官方的代码
数据集地址:https://github.com/zalandoresearch/fashion-mnist
代码:

import tensorflow as tf
from tensorflow import keras

fashion_mnist = keras.datasets.fashion_mnist
(train_images,train_labels),(test_images,test_labels) = fashion_mnist.load_data()

class_names = ['T-shirt/top', 'Trouser', 'Pullover', 'Dress', 'Coat',
               'Sandal', 'Shirt', 'Sneaker', 'Bag', 'Ankle boot']

#检查数据集
print(train_images.shape)

(3)使用http链接下载分类花卉图片失败
问题描述:运行到下载图片时会卡住
解决办法:直接打开链接“https://storage.googleapis.com/download.tensorflow.org/example_images/flower_photos.tgz”,下载后解压到目标位置,将原来的链接替换成本地地址;

from __future__ import absolute_import,division,print_function

import matplotlib.pylab as plt

import tensorflow as tf
import tensorflow_hub as hub

from tensorflow.keras import layers

data_root = tf.keras.utils.get_file(
  'flower_photos','C://Users//用户名//.keras//datasets//flower_photos',
   untar=False)

你可能感兴趣的:(TensorFlow)