Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Consuming more time to pass object from .net to python #658

Closed
@48naveen

Description

@48naveen

Environment

  • Pythonnet version: master
  • Python version: 3.5
  • Operating System: Windows 7

Details

  • I am calling python function from my c# code . Initially I import python module using Py.Import function . After importing , will pass a List data type of size 299x299x3 to python function as argument . This passing of argument taking 1.5 seconds where as a block of python code takes only 90 msec .

Here is c# code

using(Py.GIL()){dynamicPython_predict=Py.Import("Prediction");Python_predict.__init__(modelpath);List<float>imagelist=GetNormalizedFloatBGRImage(image).Data.Cast<float>().ToList();DateTimet1=System.DateTime.Now;Predicted_Type=Python_predict.Findtype(imagelist);DateTimet2=System.DateTime.Now;Console.WriteLine("Predict timing from c# {0} seconds",(t2.Second+((float)t2.Millisecond/1000))-(t1.Second+((float)t1.Millisecond/1000)));}

Here is python code

def__init__(model_path):kr.model=kr.load_model(model_path)#Model is loaded only oncedefFindtype(ImageData):t1=time.time()N_array=np.array(ImageData,dtype=np.float64)#creates Numpy array from .net List<float> arrayN_array_reshaped=np.reshape(N_array,(299,299,3))#convert BGR to RGBtemp_array[:,:,0]=N_array_reshaped[:,:,2]#bgR -> Rgbtemp_array[:,:,2]=N_array_reshaped[:,:,0]#Bgr -> rgBtemp_array[:,:,1]=N_array_reshaped[:,:,1]#bGr -> rGbimg_list[0]=temp_array#prediction = kr.model.predict(img_list, batch_size=1, verbose=0) # Predictions can be made throughout the lifecycle of MakePrediction class's instance#predicted_class = np.argmax(prediction, axis=1)t2=time.time()print('time on python ',t2-t1)returnpredicted_class[0]+1

So c# code send image array of size 2992993 of float time to python , by which it gets converted into numpy array and makes the prediction on gpu .
if i run the standalone python code , it takes 90msec but if i call from .net 1.5 sec for passing an argument .

Kindly help me to reduce the timing since it is for real time application .

here is a attached screenshots
untitled

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp