首页 > 解决方案 > Azure ML 中的 Keras model.fit 失败

问题描述

我正在尝试用很少的图像在 Azure ML 中训练一个简单的测试模型。我正在将培训代码从本地 PC 推送到 Azure 云。它使用图像生成器数据流在云中找到图像(下面的屏幕截图)。 验证图像

模型创建也很好,我可以打印模型的摘要。但是当我在做 model.fit 时,得到了这个预期的错误。但是当我在本地 PC 上运行相同的代码时,我没有收到任何错误。

任何线索都会有所帮助。提前致谢。

model.fit(train_generator,validation_data=valid_generator,epochs=1,steps_per_epoch=STEP_SIZE_TRAIN,validation_steps=STEP_SIZE_VALID)
  File "/azureml-envs/azureml_ad50fdad40ee16a2c46e9c45c93908c0/lib/python3.6/site-packages/tensorflow/python/keras/engine/training.py", line 108, in _method_wrapper
    return method(self, *args, **kwargs)
  File "/azureml-envs/azureml_ad50fdad40ee16a2c46e9c45c93908c0/lib/python3.6/site-packages/tensorflow/python/keras/engine/training.py", line 1063, in fit
    steps_per_execution=self._steps_per_execution)
  File "/azureml-envs/azureml_ad50fdad40ee16a2c46e9c45c93908c0/lib/python3.6/site-packages/tensorflow/python/keras/engine/data_adapter.py", line 1117, in __init__
    model=model)
  File "/azureml-envs/azureml_ad50fdad40ee16a2c46e9c45c93908c0/lib/python3.6/site-packages/tensorflow/python/keras/engine/data_adapter.py", line 916, in __init__
    **kwargs)
  File "/azureml-envs/azureml_ad50fdad40ee16a2c46e9c45c93908c0/lib/python3.6/site-packages/tensorflow/python/keras/engine/data_adapter.py", line 786, in __init__
    peek, x = self._peek_and_restore(x)
  File "/azureml-envs/azureml_ad50fdad40ee16a2c46e9c45c93908c0/lib/python3.6/site-packages/tensorflow/python/keras/engine/data_adapter.py", line 920, in _peek_and_restore
    return x[0], x
  File "/azureml-envs/azureml_ad50fdad40ee16a2c46e9c45c93908c0/lib/python3.6/site-packages/keras_preprocessing/image/iterator.py", line 65, in __getitem__
    return self._get_batches_of_transformed_samples(index_array)
  File "/azureml-envs/azureml_ad50fdad40ee16a2c46e9c45c93908c0/lib/python3.6/site-packages/keras_preprocessing/image/iterator.py", line 231, in _get_batches_of_transformed_samples
    x = img_to_array(img, data_format=self.data_format)
  File "/azureml-envs/azureml_ad50fdad40ee16a2c46e9c45c93908c0/lib/python3.6/site-packages/keras_preprocessing/image/utils.py", line 309, in img_to_array
    x = np.asarray(img, dtype=dtype)
  File "/azureml-envs/azureml_ad50fdad40ee16a2c46e9c45c93908c0/lib/python3.6/site-packages/numpy/core/_asarray.py", line 83, in asarray
    return array(a, dtype, copy=False, order=order)
TypeError: __array__() takes 1 positional argument but 2 were given

更新:通过降级 PIL 解决了这个问题,从 Kaveh 在这篇文章中的回答中找到了解决方案:here。我不会删除这个问题,因为有人可能正在寻找类似的问题。

问候,

标签: python-3.xtensorflowkerasazure-machine-learning-studiomodel-fitting

解决方案


推荐阅读