问题前言: 我有一个存储在 MongoDB 中的用户创建的神经网络架构数据库(用我转编译为 Keras 模型的不同语言编写)。我的目标是采用这些架构,用它们创建一个 Keras 模型,然后使用 SageMaker 在云中训练它们。截至目前,我可以从 MongoDB 加载模型并将它们转译为 Keras,效果非常好。 但是,我无法使用 Python SDK 将这些动态创建的模型发送到 SageMaker。
有没有一种方法可以通过将估算器的 entry_point 属性指定为定义了这些模型对象的文件来在 SageMaker 中训练和部署这些 Keras 模型架构(即只是 Python Keras 模型对象)?
迄今为止的工作和代码示例 截至目前,当模型架构在单独的文件中定义时,我可以创建训练作业并部署端点。在 SageMaker's GitHub. 上查看单独文件和部署/培训过程的示例
train-and-deploy-sagemaker.py
# Import Sagemaker Tensorflow
from sagemaker.tensorflow import TensorFlow
# Create an estimator object using the entry_point file entry_point.py
estimator = TensorFlow(entry_point='entry_point.py',
role=arn_role,
framework_version='1.12.0',
hyperparameters={...some hyperparams for the model...},
training_steps=1000,
evaluation_steps=100,
train_instance_count=4, train_instance_type='ml.p3.8xlarge')
# Start the training job to train the above estimator
estimator.fit(training_data_inputs)
# Deploy said estimator after training
predictor = estimator.deploy(initial_instance_count=1, instance_type='ml.m4.xlarge')
入口点.py
def keras_model_fn(hyperparameters):
"""keras_model_fn receives hyperparameters from the training job and returns a compiled keras model.
The model will be transformed into a TensorFlow Estimator before training and it will be saved in a
TensorFlow Serving SavedModel at the end of training.
Args:
hyperparameters: The hyperparameters passed to the SageMaker TrainingJob that runs your TensorFlow
training script.
Returns: A compiled Keras model
"""
model = Sequential()
... add layers ...
return model
def train_input_fn():
...
# other functions for inference and training, see link above
但是,有没有一种方法可以动态定义该架构? I.E 从 MongoDB 中获取预先编写的架构,然后将其转译为 entrypoint.py 中相同的 Sequential Keras 模型?
潜在的想法和疑虑:
想法:只需从 MongoDB 中获取模型并在 entry_point 文件中进行转译。然后AWS需要的每个方法都可以引用编译后的模型对象。
问题:考虑到 AWS 将从该文件创建 VM 以在其云中运行代码,这种做法是否安全或最佳实践?此外,源随后存储在 S3 存储桶中,因此无论权限如何,这都可能带来另一个安全风险。此外,像 pymongo 这样的依赖项无法从 entry_point 文件中加载,这使得在不更改训练图像的情况下无法获取数据。
想法:在创建训练作业和部署实例的文件中执行提取和转译 - 上面的 train-and-deploy-sagemaker.py。然后通过估计器中的 hyperparams 属性传递一些可以重建模型的代码——比如 Keras 模型 JSON。
问题:根据 AWS,超参数的长度只能是 256 个字符。
思路:根据需要包含的模型架构,动态生成entry_point文件。
关注点: 许多问题,例如出于不必要的 I/O 原因不想在服务器上创建一次性文件,生成代码是困惑和不好的做法,必须有更好的方式。
想法:将entry_point 属性设为非外部文件,而是在创建估算器的文件中指定所需的方法。这表面上可以解决我所有的问题,但是......
问题:我在 SageMaker 文档中没有看到任何关于此的信息。尽管如此,这是最理想的。
如有任何帮助,我们将不胜感激并提前致谢!
最佳答案
请注意,为了简化您的训练脚本,您可以使用 SageMaker script mode而不是 entry_point.py。
source_dir (str): Path (absolute or relative) to a directory with any other training source code dependencies aside from tne entry point file (default: None). Structure within this directory will be preserved when training on SageMaker. If the directory points to S3, no code will be uploaded and the S3 location will be used instead.
dependencies (list[str]): A list of paths to directories (absolute or relative) with any additional libraries that will be exported to the container (default: []). The library folders will be copied to SageMaker in the same folder where the entrypoint is copied. If the
source_dirpoints to S3, code will be uploaded and the S3 location will be used instead
希望对您有所帮助。
关于python - 使用 'entrypoint' 在 Sagemaker 中使用预先创建的 Keras 架构训练和部署模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55787726/
我正在学习如何使用Nokogiri,根据这段代码我遇到了一些问题:require'rubygems'require'mechanize'post_agent=WWW::Mechanize.newpost_page=post_agent.get('http://www.vbulletin.org/forum/showthread.php?t=230708')puts"\nabsolutepathwithtbodygivesnil"putspost_page.parser.xpath('/html/body/div/div/div/div/div/table/tbody/tr/td/div
我有一个Ruby程序,它使用rubyzip压缩XML文件的目录树。gem。我的问题是文件开始变得很重,我想提高压缩级别,因为压缩时间不是问题。我在rubyzipdocumentation中找不到一种为创建的ZIP文件指定压缩级别的方法。有人知道如何更改此设置吗?是否有另一个允许指定压缩级别的Ruby库? 最佳答案 这是我通过查看rubyzip内部创建的代码。level=Zlib::BEST_COMPRESSIONZip::ZipOutputStream.open(zip_file)do|zip|Dir.glob("**/*")d
类classAprivatedeffooputs:fooendpublicdefbarputs:barendprivatedefzimputs:zimendprotecteddefdibputs:dibendendA的实例a=A.new测试a.foorescueputs:faila.barrescueputs:faila.zimrescueputs:faila.dibrescueputs:faila.gazrescueputs:fail测试输出failbarfailfailfail.发送测试[:foo,:bar,:zim,:dib,:gaz].each{|m|a.send(m)resc
很好奇,就使用rubyonrails自动化单元测试而言,你们正在做什么?您是否创建了一个脚本来在cron中运行rake作业并将结果邮寄给您?git中的预提交Hook?只是手动调用?我完全理解测试,但想知道在错误发生之前捕获错误的最佳实践是什么。让我们理所当然地认为测试本身是完美无缺的,并且可以正常工作。下一步是什么以确保他们在正确的时间将可能有害的结果传达给您? 最佳答案 不确定您到底想听什么,但是有几个级别的自动代码库控制:在处理某项功能时,您可以使用类似autotest的内容获得关于哪些有效,哪些无效的即时反馈。要确保您的提
假设我做了一个模块如下:m=Module.newdoclassCendend三个问题:除了对m的引用之外,还有什么方法可以访问C和m中的其他内容?我可以在创建匿名模块后为其命名吗(就像我输入“module...”一样)?如何在使用完匿名模块后将其删除,使其定义的常量不再存在? 最佳答案 三个答案:是的,使用ObjectSpace.此代码使c引用你的类(class)C不引用m:c=nilObjectSpace.each_object{|obj|c=objif(Class===objandobj.name=~/::C$/)}当然这取决于
出于纯粹的兴趣,我很好奇如何按顺序创建PI,而不是在过程结果之后生成数字,而是让数字在过程本身生成时显示。如果是这种情况,那么数字可以自行产生,我可以对以前看到的数字实现垃圾收集,从而创建一个无限系列。结果只是在Pi系列之后每秒生成一个数字。这是我通过互联网筛选的结果:这是流行的计算机友好算法,类机器算法:defarccot(x,unity)xpow=unity/xn=1sign=1sum=0loopdoterm=xpow/nbreakifterm==0sum+=sign*(xpow/n)xpow/=x*xn+=2sign=-signendsumenddefcalc_pi(digits
我正在尝试使用ruby和Savon来使用网络服务。测试服务为http://www.webservicex.net/WS/WSDetails.aspx?WSID=9&CATID=2require'rubygems'require'savon'client=Savon::Client.new"http://www.webservicex.net/stockquote.asmx?WSDL"client.get_quotedo|soap|soap.body={:symbol=>"AAPL"}end返回SOAP异常。检查soap信封,在我看来soap请求没有正确的命名空间。任何人都可以建议我
关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭4年前。Improvethisquestion我想在固定时间创建一系列低音和高音调的哔哔声。例如:在150毫秒时发出高音调的蜂鸣声在151毫秒时发出低音调的蜂鸣声200毫秒时发出低音调的蜂鸣声250毫秒的高音调蜂鸣声有没有办法在Ruby或Python中做到这一点?我真的不在乎输出编码是什么(.wav、.mp3、.ogg等等),但我确实想创建一个输出文件。
我正在尝试测试是否存在表单。我是Rails新手。我的new.html.erb_spec.rb文件的内容是:require'spec_helper'describe"messages/new.html.erb"doit"shouldrendertheform"dorender'/messages/new.html.erb'reponse.shouldhave_form_putting_to(@message)with_submit_buttonendendView本身,new.html.erb,有代码:当我运行rspec时,它失败了:1)messages/new.html.erbshou
我在我的项目目录中完成了compasscreate.和compassinitrails。几个问题:我已将我的.sass文件放在public/stylesheets中。这是放置它们的正确位置吗?当我运行compasswatch时,它不会自动编译这些.sass文件。我必须手动指定文件:compasswatchpublic/stylesheets/myfile.sass等。如何让它自动运行?文件ie.css、print.css和screen.css已放在stylesheets/compiled。如何在编译后不让它们重新出现的情况下删除它们?我自己编译的.sass文件编译成compiled/t