Overview
The Session class is used to manage the execution session of a graph.
Example of session execution:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | from ge.session import Session from ge.graph import Tensor from ge.ge_global import GeApi # Initialize the GE. config = { "ge.execDeviceId": "0", "ge.graphRunMode": "0" } GeApi.ge_initialize(config) # Create a session. session = Session() # Add a graph. session.add_graph(0, graph) # Prepare the input. input_tensor = Tensor(data=[1.0, 2.0, 3.0, 4.0], data_type=DataType.DT_FLOAT, format=Format.FORMAT_ND, shape=[2, 2]) # Execute the graph. outputs = session.run_graph(0, [input_tensor]) # Terminate GE. GeApi.ge_finalize() |
Parent topic: Session APIs