4

sacredPython のセットアップを試みており、チュートリアルを進めています。神聖な使用を問題なく設定できましたpip install sacred。基本的なコードの実行に問題があります:

from sacred import Experiment

ex = Experiment("hello_world")

このコードを実行すると、次の a が返されますValueError

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-25-66f549cfb192> in <module>()
      1 from sacred import Experiment
      2 
----> 3 ex = Experiment("hello_world")

/Users/ryandevera/anaconda/lib/python2.7/site-packages/sacred/experiment.pyc in __init__(self, name, ingredients)
     42         super(Experiment, self).__init__(path=name,
     43                                          ingredients=ingredients,
---> 44                                          _caller_globals=caller_globals)
     45         self.default_command = ""
     46         self.command(print_config, unobserved=True)

/Users/ryandevera/anaconda/lib/python2.7/site-packages/sacred/ingredient.pyc in __init__(self, path, ingredients, _caller_globals)
     48         self.doc = _caller_globals.get('__doc__', "")
     49         self.sources, self.dependencies = \
---> 50             gather_sources_and_dependencies(_caller_globals)
     51 
     52     # =========================== Decorators ==================================

/Users/ryandevera/anaconda/lib/python2.7/site-packages/sacred/dependencies.pyc in gather_sources_and_dependencies(globs)
    204 def gather_sources_and_dependencies(globs):
    205     dependencies = set()
--> 206     main = Source.create(globs.get('__file__'))
    207     sources = {main}
    208     experiment_path = os.path.dirname(main.filename)

/Users/ryandevera/anaconda/lib/python2.7/site-packages/sacred/dependencies.pyc in create(filename)
     61         if not filename or not os.path.exists(filename):
     62             raise ValueError('invalid filename or file not found "{}"'
---> 63                              .format(filename))
     64 
     65         mainfile = get_py_file_if_possible(os.path.abspath(filename))

ValueError: invalid filename or file not found "None"

このエラーが返される理由がわかりません。ドキュメントには、コードを実行する前に実験ファイルを設定することについては何も書かれていません。どんな助けでも大歓迎です!

4

3 に答える 3

3

ドキュメントによると、IPython/Jupyter を使用している場合、Experiment を再現性のないインタラクティブな環境で実行できるようにすることができます。

ex = Experiment('jupyter_ex', interactive=True)

https://sacred.readthedocs.io/en/latest/experiment.html#run-the-experiment

于 2016-12-02T05:47:33.907 に答える
3

指定されたトレースバックは、コンストラクターがExperiment名前空間を検索して、定義されているファイルを見つけることを示しています。

したがって、この例を機能させるには、サンプル コードをファイルに配置し、そのファイルを直接実行します。

を使用している場合は、いつでもコマンドipythonを使用して試すことができます%%python。これにより、実行する前に、指定したコードをファイルに効果的にキャプチャできます (別の python プロセスで)。

于 2016-03-30T00:46:50.363 に答える