延迟延迟错误-AttributeError:“ _ thread._local”对象没有属性“ value”

时间:2020-05-22 00:15:15

标签: python keras dask dask-distributed dask-delayed

我一直在绞尽脑汁想弄清楚为什么我无法在Dask上执行此可并行化的功能。本质上,我有一个函数可以加载keras模型(我正在使用mlflow存储模型),然后对我批量发送的某些输入数据使用模型的预测方法。这段代码(如下)导致以下错误:

AttributeError: '_thread._local' object has no attribute 'value'

代码示例:

@delayed
def load_and_predict(input_data_chunk):

    def contrastive_loss(y_true, y_pred):
            margin = 1
            square_pred = K.square(y_pred)
            margin_square = K.square(K.maximum(margin - y_pred, 0))
            return K.mean(y_true * square_pred + (1 - y_true) * margin_square)

    mlflow.set_tracking_uri('<tracking_uri>')
    mlflow.set_experiment('experiment_name')
    runs = mlflow.search_runs()
    artifact_uri = runs.loc[runs['start_time'].idxmax()]['artifact_uri']
    model = mlflow.keras.load_model(artifact_uri + '/model', custom_objects={'contrastive_loss': contrastive_loss})
    y_pred = model.predict(input_data_chunk)
    return y_pred

with Client(<scheduler_ip:port>) as client:
    batch_array = np.array_split(X_test, 10)
    results = []
    for batch in batch_array:
        prediction = load_and_predict(batch)
        results.append(prediction)

compute(*results)

我对Dask还是很陌生,因此,非常感谢您提供有关此问题的专家指导。

1 个答案:

答案 0 :(得分:1)

如果打算使用在上下文中创建的Path destination = applicationDataPath.resolve("newImageUploaded"+fileExtension); try { Files.copy(source, destination, StandardCopyOption.REPLACE_EXISTING); System.out.println("Changing image: " + imagePath); // Set the uploaded image in the ImageView in GUI. postImage.setImage(new Image(destination.toUri().toURL().toExternalForm())); } catch (IOException ioException) { ioException.printStackTrace(); System.out.println("Exception Caught"); } 进行计算,则Client行也必须在上下文中:请缩进。