原来这是我的 GCP 配置有问题以下是我为使其工作而采取的步骤:
创建一个 s3 存储桶并将其中的所有文件公开,以便火车作业可以访问它们
在要求 fsspec 和 gcsfs 中包含这两个
像这样从 panda.readCsv 中删除 'engine' 参数
dataset = pandas.read_csv('gs:///USDJPY.fx5.csv', usecols=[2, 3, 4, 5])
由于您将 python 文件上传到 GCP 是一种组织代码的好方法,因此可以将所有训练逻辑放入一个方法中,然后根据云训练标志有条件地调用它:
if tfc.remote():
train()
如果有人感兴趣,这是整个工作代码
import pandas
import numpy
from keras.models import Sequential
from keras.layers import Dense
from keras.layers import LSTM
from keras.layers import Dropout
from sklearn.preprocessing import MinMaxScaler
import tensorflow_cloud as tfc
import os
os.environ["PATH"] = os.environ["PATH"] + ":<path to google-cloud-sdk/bin"
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "<path to google credentials json (you can generate this through their UI"
def create_dataset(data):
dataX = data[0:len(data) - 1]
dataY = data[1:]
return numpy.array(dataX), numpy.array(dataY)
def train():
dataset = pandas.read_csv('gs://<bucket>/USDJPY.fx5.csv', usecols=[2, 3, 4, 5])
scaler = MinMaxScaler(feature_range=(-1, 1))
scaler = scaler.fit(dataset)
dataset = scaler.transform(dataset)
# split into train and test sets
train_size = int(len(dataset) * 0.67)
train, test = dataset[0:train_size], dataset[train_size:len(dataset)]
trainX, trainY = create_dataset(train)
trainX = numpy.reshape(trainX, (trainX.shape[0], 1, trainX.shape[1]))
model = Sequential()
model.add(LSTM(4, input_shape=(1, 4)))
model.add(Dropout(0.2))
model.add(Dense(4))
model.compile(loss='mean_squared_error', optimizer='adam')
model.fit(trainX, trainY, epochs=1000, verbose=1)
job_labels = {"job": "forex-usdjpy", "team": "zver", "user": "zver1"}
tfc.run(requirements_txt="./requirements.txt",
job_labels=job_labels,
stream_logs=True
)
if tfc.remote():
train()
注意:这可能不是最佳的 LSTM 配置,请谨慎对待