问题描述:试运行TensorFlow官网的第四个例子(Regression)报错:ImportError: cannot import name ‘GeneratorEnqueuer’
代码如下:
from future import absolute_import, division, print_function
import pathlib
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers
print(tf.version)
dataset_path = keras.utils.get_file(“auto-mpg.data”, “https://archive.ics.uci.edu/ml/machine-learning-databases/auto-mpg/auto-mpg.data”)
dataset_path
column_names = [‘MPG’,‘Cylinders’,‘Displacement’,‘Horsepower’,‘Weight’, ‘Acceleration’, ‘Model Year’, ‘Origin’]
raw_dataset = pd.read_csv(dataset_path, names=column_names,na_values = “?”, comment=’\t’,
sep=" ", skipinitialspace=True)
在Spyder和其他软件运行时,一直报错,后来调试发现 在 from tensorflow.keras import layers 处调试中断。后来参考其他博客,隐约知道是版本出了问题,具体原因还不清楚。
解决方案:将 from tensorflow.keras import layers注释掉即可,运行结果与官网一致。如下图所示。