我正在嘗試按照本教程將 aws 連接到 jupyter 筆記本以進行本地開發(我在 vscode 中運行 jupyter,我認為這并不重要,只是為了以防萬一)。
我從教程中獲得了這個ipynb 檔案,并讓它一直成功運行,直到您嘗試在資料上擬合 tensorflow 估計器的單元格:
代碼如下所示:
# Train! This will pull (once) the SageMaker CPU/GPU container for TensorFlow to your local machine.
# Make sure that Docker is running and that docker-compose is installed
tf_estimator.fit({'training': training_input_path, 'validation': validation_input_path})
我安裝了 docker,但我真的不知道我在用它做什么,因為我以前從未使用過它。我不知道這是 docker 問題還是 sagemaker 問題,但這是我嘗試運行該單元時引發的錯誤:
Failed to import yaml. Local mode features will be impaired or broken. Please run "pip install 'sagemaker[local]'" to install all required dependencies.
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
/var/folders/cf/ft88j_856fv5rk3whgs12d9w0000gq/T/ipykernel_97461/84733352.py in <module>
2 # Make sure that Docker is running and that docker-compose is installed
3
----> 4 tf_estimator.fit({'training': training_input_path, 'validation': validation_input_path})
~/opt/anaconda3/envs/localsm/lib/python3.7/site-packages/sagemaker/workflow/pipeline_context.py in wrapper(*args, **kwargs)
207 return self_instance.sagemaker_session.context
208
--> 209 return run_func(*args, **kwargs)
210
211 return wrapper
~/opt/anaconda3/envs/localsm/lib/python3.7/site-packages/sagemaker/estimator.py in fit(self, inputs, wait, logs, job_name, experiment_config)
976 self._prepare_for_training(job_name=job_name)
977
--> 978 self.latest_training_job = _TrainingJob.start_new(self, inputs, experiment_config)
979 self.jobs.append(self.latest_training_job)
980 if wait:
~/opt/anaconda3/envs/localsm/lib/python3.7/site-packages/sagemaker/estimator.py in start_new(cls, estimator, inputs, experiment_config)
1806 train_args = cls._get_train_args(estimator, inputs, experiment_config)
1807
-> 1808 estimator.sagemaker_session.train(**train_args)
1809
1810 return cls(estimator.sagemaker_session, estimator._current_job_name)
~/opt/anaconda3/envs/localsm/lib/python3.7/site-packages/sagemaker/session.py in train(self, input_mode, input_config, role, job_name, output_config, resource_config, vpc_config, hyperparameters, stop_condition, tags, metric_definitions, enable_network_isolation, image_uri, algorithm_arn, encrypt_inter_container_traffic, use_spot_instances, checkpoint_s3_uri, checkpoint_local_path, experiment_config, debugger_rule_configs, debugger_hook_config, tensorboard_output_config, enable_sagemaker_metrics, profiler_rule_configs, profiler_config, environment, retry_strategy)
592 self.sagemaker_client.create_training_job(**request)
593
--> 594 self._intercept_create_request(train_request, submit, self.train.__name__)
595
596 def _get_train_request( # noqa: C901
~/opt/anaconda3/envs/localsm/lib/python3.7/site-packages/sagemaker/session.py in _intercept_create_request(self, request, create, func_name)
4201 func_name (str): the name of the function needed intercepting
4202 """
-> 4203 return create(request)
4204
4205
~/opt/anaconda3/envs/localsm/lib/python3.7/site-packages/sagemaker/session.py in submit(request)
590 LOGGER.info("Creating training-job with name: %s", job_name)
591 LOGGER.debug("train request: %s", json.dumps(request, indent=4))
--> 592 self.sagemaker_client.create_training_job(**request)
593
594 self._intercept_create_request(train_request, submit, self.train.__name__)
~/opt/anaconda3/envs/localsm/lib/python3.7/site-packages/sagemaker/local/local_session.py in create_training_job(self, TrainingJobName, AlgorithmSpecification, OutputDataConfig, ResourceConfig, InputDataConfig, Environment, **kwargs)
190 logger.info("Starting training job")
191 training_job.start(
--> 192 InputDataConfig, OutputDataConfig, hyperparameters, Environment, TrainingJobName
193 )
194
~/opt/anaconda3/envs/localsm/lib/python3.7/site-packages/sagemaker/local/entities.py in start(self, input_data_config, output_data_config, hyperparameters, environment, job_name)
235
236 self.model_artifacts = self.container.train(
--> 237 input_data_config, output_data_config, hyperparameters, environment, job_name
238 )
239 self.end_time = datetime.datetime.now()
~/opt/anaconda3/envs/localsm/lib/python3.7/site-packages/sagemaker/local/image.py in train(self, input_data_config, output_data_config, hyperparameters, environment, job_name)
234
235 compose_data = self._generate_compose_file(
--> 236 "train", additional_volumes=volumes, additional_env_vars=training_env_vars
237 )
238 compose_command = self._compose()
~/opt/anaconda3/envs/localsm/lib/python3.7/site-packages/sagemaker/local/image.py in _generate_compose_file(self, command, additional_volumes, additional_env_vars)
687 except ImportError as e:
688 logger.error(sagemaker.utils._module_import_error("yaml", "Local mode", "local"))
--> 689 raise e
690
691 yaml_content = yaml.dump(content, default_flow_style=False)
~/opt/anaconda3/envs/localsm/lib/python3.7/site-packages/sagemaker/local/image.py in _generate_compose_file(self, command, additional_volumes, additional_env_vars)
684
685 try:
--> 686 import yaml
687 except ImportError as e:
688 logger.error(sagemaker.utils._module_import_error("yaml", "Local mode", "local"))
ModuleNotFoundError: No module named 'yaml'
想知道是否有其他人發生過這種情況,或者是否有人可以指出正確的方向來嘗試找出問題所在以及如何解決。謝謝!
uj5u.com熱心網友回復:
您只是缺少 pyyaml 模塊
通過以下方式安裝它:
pip install pyyaml
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/489704.html
標籤:Python 码头工人 张量流 amazon-sagemaker
上一篇:TensorFlow如何處理傳遞給神經網路的訓練資料?
下一篇:使用ImageDataGenerator和flow_from_directory時如何使用來自TensorHub的遷移學習和自定義影像大小
