使用gcloud ML引擎时如何设置环境变量? [英] How to set an environment variable when using gcloud ML engine?
问题描述
全部
(环境:Windows 7,Python 3.6,Keras& tensorflow库,gcloud ml引擎)
(Environments: Windows 7, Python 3.6, Keras & tensorflow libs, gcloud ml engine)
我正在使用gcloud ml引擎运行某些Keras ML模型示例,如
I am running certain Keras ML model examples using gcloud ml engine as introduced here. Everything was fine but I just got various results among multiple runs although I was using the same training and validation data. My goal is to make reproductive training results from multiple runs.
我搜索了一段时间,在此 Keras Q&A 关于获得生殖结果.基本上,他们首先建议这样做:
I googled it for a while and found some solutions in this Keras Q&A regarding making reproductive results. Basically they first suggested this:
首先,您需要在程序启动之前将PYTHONHASHSEED环境变量设置为0(而不是在程序本身内部).
First, you need to set the PYTHONHASHSEED environment variable to 0 before the program starts (not within the program itself).
我知道我可以在自己的计算机上本地设置变量,也可以如介绍的那样在部署gcloud函数时进行设置此处.
I know I could set the variables locally on my own machine, or I could set it when I deploy gcloud function as introduced here.
但是,当我使用 gcloud ML引擎(在服务器端但不在本地)时,我只是不知道如何设置环境变量.因此,当我的模型程序在那里运行时,我无法在gcloud服务器上设置"PYTHONHASHSEED = 0".
But, I just do not know how to set environment variables when I was using gcloud ML engine (on server side but NOT on local). So I cannot set "PYTHONHASHSEED=0" on the gcloud server when my model programs running there.
顺便说一句,总的来说,我知道随机性在ML领域是有用的,但是我对产生生殖结果的话题还不是很熟悉,因此也欢迎对此话题提出任何想法.谢谢!
BTW, in general I know the randomness is a useful nature in the ML field but I am not very familiar about the topic of making reproductive results yet, so any thoughts regarding this topic are also welcome. Thanks!
大七
PS: 我尝试在下面的运行时设置环境变量:
PS: I have tried to setting the environment variables in running time below:
import os
os.environ["PYTHONHASHSEED"] = "0"
print(hash("keras"))
但是不能起到在程序启动前设置变量"的作用.因此,有了此代码,我仍然无法从多次运行中获得相同的哈希结果.另一方面,在本地,如果在运行代码之前设置"PYTHONHASHSEED = 0",则可能会得到相同的哈希结果.
But it cannot make the effect that "setting the variables before the program starts". So by having this code, I still cannot get the same hash results from the multiple runs. On the other hand, on local, if I set "PYTHONHASHSEED=0" before running the code, I may get the same hash results.
推荐答案
我不认为Cloud ML Engine API提供了设置环境变量的机制.但是,您可以通过编写包装脚本(NB:未测试的代码)来解决此问题:
I don't believe the Cloud ML Engine API provides a mechanism to set environment variables. However, you might be able to workaround this by writing a wrapper script (NB: UNTESTED CODE):
import os
import subprocess
env = os.environ.copy()
env["PYTHONHASHSEED"] = "0"
subprocess.check_call(['python', 'main.py'], env=env)
这篇关于使用gcloud ML引擎时如何设置环境变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!