WinError193 %1 不是有效的 Win32 应用程序

对于一个AI项目,我需要使用tensorflow结合anaconda和spyder。然而,自去年以来,我在启动Anaconda时遇到了问题。我一直未能解决这个错误,因为我之前没有使用Anaconda的需求,但现在我必须解决这个问题。

我首先在anaconda提示符中使用conda create -n tf2gpu tensorflow-gpu jupyter matplotlib pillow spyder创建了一个环境,然后使用conda activate tf2-gpu激活该环境,并通过终端使用spyder打开spyder。(注意:我有一块合适的GPU)。

这是我尝试运行的代码:

# -*- coding: utf-8 -*-from tensorflow.keras.datasets import mnist #datasetsfrom tensorflow.keras.models import Sequentialfrom tensorflow.keras.layers import Dense,Activationfrom tensorflow.keras.optimizers import SGDfrom tensorflow.keras.utils import to_categoricalimport matplotlib.pyplot as pltimport numpy as np(tr_imgs,tr_labs),(tst_imgs,tst_labs)=mnist.load_data()#loading dataprint("Training references :",tr_imgs.shape,tr_labs.shape,tr_imgs.dtype,tr_labs.dtype)#60,000 images of 28 by 28 size with 60,000 labels, both integer 8 bits signedprint("Testing references :",tst_imgs.shape,tst_labs.shape,tst_imgs.dtype,tst_labs.dtype)#10,000 images of 28 by 28 size with 10,000 labels, both integer 8 bits signedprint("__________________\n")tr_vec=np.reshape(tr_imgs,(len(tr_imgs),-1)).astype("float32")/255.0tst_vec=np.reshape(tst_imgs,(len(tst_imgs),-1)).astype("float32")/255.0cat_trlabs=to_categorical(tr_labs)cat_tstlabs=to_categorical(tst_labs)model=Sequential([Dense(251,input_shape=(784,)),Activation("sigmoid"),Dense(128),Activation("sigmoid"),Dense(10),Activation("sigmoid")])sgd=SGD(learning_rate=0.15,momentum=0.9,decay=0.0,nesterov=False)model.compile(loss="mse",optimizer=sgd,metrics=["accuracy"])history=model.fit(tr_vec,cat_trlabs,epochs=100,batch_size=200,validation_split=0.1,verbose=2)model_history=history.historyprediction=model.predict(tst_vec)model_loss=model_history["loss"]model_acc=model_history["accuracy"]model_valloss=model_history["val_loss"]model_valaccuracy=model_history["val_accuracy"]epochs=range(len(model_acc))plt.plot(epochs,model_valaccuracy,label="Val_accuracy")plt.plot(epochs,model_acc,label="Accuracy")plt.show()

然后出现了这个错误:[WinError193]%1 不是有效的 Win32 应用程序

我使用的是64位Windows 10,anaconda也是64位的。

提前感谢,我已经卡在这里两天了。

编辑1:似乎是tensorflow.keras库的问题


回答:

我可能有一个解决方案。我之前也遇到过同样的问题…然后我发现这里涉及到两个python环境。我只需要删除其中一个(与Anaconda不相关的那个)。希望这个回答能帮到你。祝你的项目好运,AI很有趣 🙂

Related Posts

L1-L2正则化的不同系数

我想对网络的权重同时应用L1和L2正则化。然而,我找不…

使用scikit-learn的无监督方法将列表分类成不同组别,有没有办法?

我有一系列实例,每个实例都有一份列表,代表它所遵循的不…

f1_score metric in lightgbm

我想使用自定义指标f1_score来训练一个lgb模型…

通过相关系数矩阵进行特征选择

我在测试不同的算法时,如逻辑回归、高斯朴素贝叶斯、随机…

可以将机器学习库用于流式输入和输出吗?

已关闭。此问题需要更加聚焦。目前不接受回答。 想要改进…

在TensorFlow中,queue.dequeue_up_to()方法的用途是什么?

我对这个方法感到非常困惑,特别是当我发现这个令人费解的…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注