タグ

2022年4月25日のブックマーク (2件)

  • Binary search with confidence

    Consider the following binary search code, copied from Wikipedia. Is it correct? function binary_search(A, n, T): L := 0 R := n − 1 while L <= R: m := floor((L + R) / 2) if A[m] < T: L := m + 1 else if A[m] > T: R := m - 1 else: return m return unsuccessful How sure are you? When I see this code, I have to ask myself: What’s up with all of these ‘s? What happens on small arrays? What happens if th

    satojkovic
    satojkovic 2022/04/25
    分かりやすい
  • 画像データをサーバーにPOSTする

    機械学習を使ったサービス/アプリを開発しているとクライアントから画像をサーバーに送って推論して結果を返す,ということをよくやるのでメモ. 1枚しか送らない場合 今の所自分はこのパターンが多いです.いくつか実現方法はあると思いますが,リクエストボディに直接画像データのバイナリを入れて送る方法がシンプルで好きです.クライアント側のコードはこんな感じ. import json import urllib.parse import urllib.request # read image data f = open("example.jpg", "rb") reqbody = f.read() f.close() # create request with urllib url = "http://localhost:5000" req = urllib.request.Request( url,