我正在尝试使用keras进行图像分类。我想为我的项目加载一个已经训练好的模型(VGG16)。但是当我跑步
from keras.applications.vgg16 import VGG16
我得到一个错误。
ImportError: cannot import name 'abs'
我使用
重新安装了tensorflow和keraspip install --ignore-installed --upgrade tensorflow
conda install -c conda-forge keras
因为我发现了一些建议,尽管与tfp无关,但重新安装可以对here有所帮助,而不是VGG16。
有人可以帮我吗?为什么我收到此错误,我该如何解决?
操作系统:windows Tensorflow和keras安装在CPU上
答案 0 :(得分:1)
毕竟尝试在虚拟环境中安装tensorflow和keras可以解决问题。但是,仍然不知道为什么这个问题首先存在。已采取步骤:
conda create --name vgg16project python # you can name it other than vgg16project
activate vgg16project
然后安装您需要的其他软件包,例如pandas,seaborn等,然后使用pip安装tensorflow和keras
pip install --upgrade tensorflow
pip install --upgrade keras
简单地解决了。我想一定有理由建议在虚拟环境中使用tensorflow和keras。
答案 1 :(得分:0)
我在keras上遇到类似问题,无法导入Abs。尝试更新,发现tensorflow文件仍在使用中。
由于环境错误而无法安装软件包:[WinError 32]该过程
无法访问该文件,因为该文件正在被另一个进程使用:'c:\ progra
m个文件(x86)\ Microsoft Visual Studio \ shared \ python36_64 \ Lib \ site-packages \
\ tensorflow \ python \ ops \ gen_dataset_ops.py'
考虑使用 SELECT
@date AS event_date,
event.timestamp_micros AS event_timestamp,
event.previous_timestamp_micros AS event_previous_timestamp,
event.name AS event_name,
event.value_in_usd AS event_value_in_usd,
user_dim.bundle_info.bundle_sequence_id AS event_bundle_sequence_id,
user_dim.bundle_info.server_timestamp_offset_micros as event_server_timestamp_offset,
(
SELECT
ARRAY_AGG(STRUCT(event_param.key AS key,
STRUCT(event_param.value.string_value AS string_value,
event_param.value.int_value AS int_value,
event_param.value.double_value AS double_value,
event_param.value.float_value AS float_value) AS value))
FROM
UNNEST(event.params) AS event_param) AS event_params,
user_dim.first_open_timestamp_micros AS user_first_touch_timestamp,
user_dim.user_id AS user_id,
user_dim.app_info.app_instance_id AS user_pseudo_id,
"" AS stream_id,
user_dim.app_info.app_platform AS platform,
STRUCT( user_dim.ltv_info.revenue AS revenue,
user_dim.ltv_info.currency AS currency ) AS user_ltv,
STRUCT( user_dim.traffic_source.user_acquired_campaign AS name,
user_dim.traffic_source.user_acquired_medium AS medium,
user_dim.traffic_source.user_acquired_source AS source ) AS traffic_source,
STRUCT( user_dim.geo_info.continent AS continent,
user_dim.geo_info.country AS country,
user_dim.geo_info.region AS region,
user_dim.geo_info.city AS city ) AS geo,
STRUCT( user_dim.device_info.device_category AS category,
user_dim.device_info.mobile_brand_name,
user_dim.device_info.mobile_model_name,
user_dim.device_info.mobile_marketing_name,
user_dim.device_info.device_model AS mobile_os_hardware_model,
@platform AS operating_system,
user_dim.device_info.platform_version AS operating_system_version,
user_dim.device_info.device_id AS vendor_id,
user_dim.device_info.resettable_device_id AS advertising_id,
user_dim.device_info.user_default_language AS language,
user_dim.device_info.device_time_zone_offset_seconds AS time_zone_offset_seconds,
IF(user_dim.device_info.limited_ad_tracking, "Yes", "No") AS is_limited_ad_tracking ) AS device,
STRUCT( user_dim.app_info.app_id AS id,
@firebase_app_id AS firebase_app_id,
user_dim.app_info.app_version AS version,
user_dim.app_info.app_store AS install_source ) AS app_info,
(
SELECT
ARRAY_AGG(STRUCT(user_property.key AS key,
STRUCT(user_property.value.value.string_value AS string_value,
user_property.value.value.int_value AS int_value,
user_property.value.value.double_value AS double_value,
user_property.value.value.float_value AS float_value,
user_property.value.set_timestamp_usec AS set_timestamp_micros ) AS value))
FROM
UNNEST(user_dim.user_properties) AS user_property) AS user_properties
FROM
`SCRIPT_GENERATED_TABLE_NAME`,
UNNEST(event_dim) AS event
选项或检查权限。
在卸载keras和tensorflow之后-我删除了整个tensorflow文件夹并重新安装了tensorflow 1.10和keras。这解决了我的问题。
答案 2 :(得分:0)
我遇到了同样的问题,只是卸载(并删除了)张量流。
之后,我再次使用以下命令进行安装:
pip install tensorflow-gpu==2.0.0-rc1
在使它工作之前,我尝试了三种不同的版本。