0
我正在運行代碼從here。Keras:chmod導致未找到keras模塊
當我運行使用的代碼:
python mycode.py
它運行沒有問題,產生預期的輸出。
然而,當我添加一行到頂端:
#!/usr/bin/python
和運行
chmod +x mycode.py
,然後這樣的:
./mycode.py
我收到以下錯誤:
Traceback (most recent call last):
File "./mycode.py", line 3, in <module>
from keras.models import Sequential
ImportError: No module named keras.models
我的最終目標是修改代碼以接受諸如命令行中的--epochs之類的東西。我怎麼能用Keras做到這一點?
編輯:
下面是工作的代碼(使用python mycode.py運行)。你可以obtain the dataset here(一個csv,不是很大)。當我將shebang添加到top和chmod並運行替代方式時,問題就出現了。
from keras.models import Sequential
from keras.layers import Dense
import numpy
# fix random seed for reproducibility
seed = 7
numpy.random.seed(seed)
# load pima indians dataset
dataset = numpy.loadtxt("pima-indians-diabetes.csv", delimiter=",")
# split into input (X) and output (Y) variables
X = dataset[:,0:8]
Y = dataset[:,8]
# create model
model = Sequential()
model.add(Dense(12, input_dim=8, init='uniform', activation='relu'))
model.add(Dense(8, init='uniform', activation='relu'))
model.add(Dense(1, init='uniform', activation='sigmoid'))
# Compile model
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
# Fit the model
model.fit(X, Y, nb_epoch=2, batch_size=10)
# evaluate the model
scores = model.evaluate(X, Y)
print("%s: %.2f%%" % (model.metrics_names[1], scores[1]*100))