我目前正在嘗試使用 Azure ML 生態系統的不同架構。目前,我正在測驗 Azure ML Studio Designer。
當我使用“創建 Python 模型”組件創建自定義 Tensorflow 模型時。當我運行設計器管道時,我收到一條錯誤訊息,提示找不到 Tensorlfow。
錯誤:
---------- Start of error message from Python interpreter ----------
Got exception when importing script: 'No module named 'tensorflow''.
---------- End of error message from Python interpreter ----------
任務中的腳本:
# The script MUST define a class named AzureMLModel.
# This class MUST at least define the following three methods: "__init__", "train" and "predict".
# The signatures (method and argument names) of all these methods MUST be exactly the same as the following example.
# Please do not install extra packages such as "pip install xgboost" in this script,
# otherwise errors will be raised when reading models in down-stream modules.
import pandas as pd
import numpy as np
import tensorflow as tf
from sklearn.preprocessing import OneHotEncoder
class AzureMLModel:
# The __init__ method is only invoked in module "Create Python Model",
# and will not be invoked again in the following modules "Train Model" and "Score Model".
# The attributes defined in the __init__ method are preserved and usable in the train and predict method.
def __init__(self):
# self.model must be assigned
model = tf.keras.Sequential()
model.add(tf.keras.layers.Convolution1D(filters=2, kernel_size=1,input_shape=(4,1), name='Conv1'))
model.add(tf.keras.layers.Flatten())
model.add(tf.keras.layers.Dense(10, activation='relu', name='Dense1'))
model.add(tf.keras.layers.Dense(10, activation='relu', name='Dense2'))
model.add(tf.keras.layers.Dense(3, activation='softmax', name='output'))
optimizer = tf.keras.optimizers.Adam(lr=0.001)
model.compile(optimizer, loss='categorical_crossentropy', metrics=['accuracy'])
self.model = model
self.feature_column_names = list()
# Train model
# Param<df_train>: a pandas.DataFrame
# Param<df_label>: a pandas.Series
def train(self, df_train, df_label):
# self.feature_column_names records the column names used for training.
# It is recommended to set this attribute before training so that the
# feature columns used in predict and train methods have the same names.
self.feature_column_names = df_train.columns.tolist()
encoder = OneHotEncoder(sparse=False)
df_label = encoder.fit_transform(df_label)
ES = tf.keras.callbacks.EarlyStopping(monitor="val_loss", patience=10)
self.model.fit(df_train, df_label, validation_split=0.1 ,epochs=1000, callbacks=[ES])
# Predict results
# Param<df>: a pandas.DataFrame
# Must return a pandas.DataFrame
def predict(self, df):
# The feature columns used for prediction MUST have the same names as the ones for training.
# The name of score column ("Scored Labels" in this case) MUST be different from any other
# columns in input data.
pred = self.model.predict(df[self.feature_column_names])
return pd.DataFrame({'Scored Labels': np.argmax(pred, axis=1)})
我該如何解決這個問題?我在筆記本中嘗試了該模型并且作業正常,因此沒有語法錯誤,只是 Tensorflow 的問題。
uj5u.com熱心網友回復:
我們不能直接在設計器中安裝 TensorFlow。相反,我們可以在內部呼叫包含 TensorFlow 的演算法的節點。例如,我正在使用 DenseNet 執行影像分類。檢查以下流程。




下面的螢屏是設計器中流程的完整圖片。

轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/531230.html
