記録のために
Project Brainwave public preview
Model Developmentによると、以下、説明のために、引用します。
FPGAで実行する部分を含むモデルをサービスとして定義し、
FPGAで実行する部分を含むモデルをサービスとして定義し、
fromfrom amlrealtimeai.pipelineamlreal import ServiceDefinition, TensorflowStage, BrainWaveStage, KerasStage service_def = ServiceDefinition() service_def.pipeline.append(TensorflowStage(tf.Session(), in_images, image_tensors)) service_def.pipeline.append(BrainWaveStage(featurizer)) service_def.pipeline.append(KerasStage(model)) service_def_path = os.path.join(datadir, 'save', 'service_def') service_def.save(service_def_path) print(service_def_path)
モデルのDeployをします。
from amlrealtimeai import DeploymentClient model_name = "catsanddogs-model" service_name = "modelbuild-service" deployment_client = DeploymentClient(subscription_id, resource_group, model_management_account) service = deployment_client.get_service_by_name(service_name) model_id = deployment_client.register_model(model_name, service_def_path) if(service is None): service = deployment_client.create_service(service_name, model_id) else: service = deployment_client.update_service(service.id, model_id) print(service.ipAddress + ':' + str(service.port))これで、サービス側のIPアドレスとポート番号を獲得します。
クライアント側では、
from amlrealtimeai import PredictionClient client = PredictionClient(service.ipAddress, service.port) # Specify an image to classify# Speci print('CATS') for image_file in cat_files[:8]: results = client.score_image(image_file) result = 'CORRECT ' if results[0] > results[1] else 'WRONG ' print(result + str(results)) print('DOGS') for image_file in dog_files[:8]: results = client.score_image(image_file) result = 'CORRECT ' if results[1] > results[0] else 'WRONG ' print(result + str(results))のように、client.score_image にて、イマージファイルを指定して、結果を得ます。
後処理は、
ervices = deployment_client.list_services() for service in filter(lambda x: x.name == service_name, services): print(service.id) deployment_client.delete_service(service.id) models = deployment_client.list_models() for model in filter(lambda x: x.name == model_name, models): print(model.id) deployment_client.delete_model(model.id)です。
このブログのGenerate Model and Uploadに、
引用 Here each 3 models in pipeline are representing “Transform Input”, “Image Featurizer”, and “Image Classifier” in previous diagram, and these are executed in order.とある。
MicrosoftのBrainwaveのサービス側では、 モデルをシリアルに接続してパイプライン化しているんだけど、 これって、各モデルが終了してから、次のモデルを実行しているんだろうね。 何故なら、FPGA部では、大量のデータを順次処理しないと、性能がでないから。。。