名称错误:试图运行名为PspN的Keras分割模型时出现名称 'np' 未定义

2024-05-14 09:58:39 发布

您现在位置:Python中文网/ 问答频道 /正文

事情是这样的:安装完所有包和依赖项之后。我运行了以下代码:

import numpy as np
from sys import exit
from sys import argv,exit
from keras import optimizers
from keras import backend as K
import keras_segmentation

一切都很好。但是,后来我跑了:

model = keras_segmentation.models.pspnet.vgg_pspnet(n_classes = 4)

出现了这个错误:

2019-11-13 19:01:15.403630: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
Traceback (most recent call last):
  File "semantic_sg.py", line 27, in <module>
    model = keras_segmentation.models.pspnet.vgg_pspnet(n_classes = 4)
  File "C:\Users\rodgu\AppData\Local\Continuum\anaconda3\envs\tensorflow_env\lib\site-packages\keras_segmentation\models\pspnet.py", line 91, in vgg_pspnet
    model =  _pspnet( n_classes , get_vgg_encoder ,  input_height=input_height, input_width=input_width  )
  File "C:\Users\rodgu\AppData\Local\Continuum\anaconda3\envs\tensorflow_env\lib\site-packages\keras_segmentation\models\pspnet.py", line 63, in _pspnet
    pooled = pool_block(  o , p  )
  File "C:\Users\rodgu\AppData\Local\Continuum\anaconda3\envs\tensorflow_env\lib\site-packages\keras_segmentation\models\pspnet.py", line 34, in pool_block
    pool_size = strides = [int(np.round( float(h) /  pool_factor)), int(np.round(  float(w )/  pool_factor))]
NameError: name 'np' is not defined

这太疯狂了,因为我肯定安装了numpy。我用指纹写了同样的代码(np.version.version版本)within和got:1.17.3(这也意味着numpy可以在除Keras函数之外的任何地方工作)。我重新安装了numpy,但还是一无所获。我被困在这里好几天了。你知道吗

谢谢,太多了!你知道吗


Tags: infrompyimportnumpymodelstensorflownp
1条回答
网友
1楼 · 发布于 2024-05-14 09:58:39

多亏了Aditya Shankar,我成功了。为了使用keras分段包,必须先降级python,然后再降级tensorflow(至少,据我所知)。(另外,请确保安装中列出的任何其他依赖项。)设置.py文件)

conda create -n lower_env pip python=3.6
conda activate lower_env
pip install  ignore-installed  upgrade tensorflow
conda install -c anaconda keras
pip install tensorflow==1.4
conda install -c conda-forge shapely
pip install imgaug>=0.2.9

相关问题 更多 >

    热门问题