【问题标题】:ERROR: cannot import name 'squeeze_or_expand_dimensions'错误:无法导入名称“squeeze_or_expand_dimensions”
【发布时间】:2020-08-19 05:27:19
【问题描述】:
import tflearn
from tflearn.layers.conv import conv_2d,max_pool_2d
from tflearn.layers.core import input_data,dropout,fully_connected
from tflearn.layers.estimator import regression

[代码片段][1] [1]:https://i.stack.imgur.com/rRcp4.png

我用过张量流==1.13.2,1.4,1.5,2.0 但错误仍然存​​在。

实际上,当我尝试导入 tflearn 和 tensorflow 时,它会抛出相同的错误 ModuleNotFoundError:

没有名为“_pywrap_tensorflow”的模块

无法加载原生 TensorFlow 运行时。 https://github.com/tensorflow/tensorflow/blob/master/tensorflow/g3doc/get_started/os_setup.md#import_error

出于一些常见原因和解决方案。包括整个堆栈跟踪 寻求帮助时出现此错误消息。

【问题讨论】:

    标签: tensorflow tflearn


    【解决方案1】:

    首先,不要给你的代码/错误截图,直接写在那里。

    其次,您应该告诉我们您的库版本。

    我的:

    • 张量流==2.1
    • keras==2.2.4

    我检查了 loss_utils 文件,显然没有调用函数:

    squeeze_or_expend_dims

    我不知道您为什么需要它们,但这可能会对您有所帮助:

    import numpy as np
    
    a = np.ones((10,10))
    print(a.shape)
    
    a=np.expand_dims(a,axis=0)
    print(a.shape)
    
    a=np.squeeze(a, axis=0)
    print(a.shape)
    
    #(10,10)
    #(1,10,10)
    #(10,10)
    

    另外,如果你想使用 tensorflow 的内置函数 使用:

    tf.expand_dims 和 tf.squeeze 有关更多信息,请参阅此帖子Tensorflow: When use tf.expand_dims?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-11
      • 2021-02-19
      • 2014-01-29
      • 2016-11-21
      • 2018-05-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多