Skip to content

Commit

Permalink
Use tempfile in cbcl
Browse files Browse the repository at this point in the history
  • Loading branch information
lisitsyn committed May 26, 2024
1 parent f0c6b9b commit 11df3cc
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions examples/cbcl/cbcl.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import numpy, datetime, json, subprocess, sys, os, glob
from PIL import Image
import numpy
import datetime
import json
import subprocess
import sys
import os
import glob
import tempfile

import scipy.misc
from PIL import Image

def load(dir):
images = []
Expand All @@ -12,15 +20,15 @@ def load(dir):
return numpy.vstack(vecs), images

def embed(feature_matrix):
input_file = 'tmp_cbcl_input'
numpy.savetxt(input_file, feature_matrix, delimiter=',')
output_file = 'tmp_cbcl_output.dat'
runner_string = './bin/tapkee -i %s -o %s -m ltsa -k 80 --transpose-output --verbose --benchmark' % (input_file, output_file)
input_file = tempfile.NamedTemporaryFile(prefix='cbcl_input')
output_file = tempfile.NamedTemporaryFile(prefix='cbcl_output')
numpy.savetxt(input_file.name, feature_matrix, delimiter=',')
runner_string = './bin/tapkee -i %s -o %s -m ltsa -k 80 --transpose-output --verbose --benchmark' % (input_file.name, output_file.name)
process = subprocess.run(runner_string, shell=True, capture_output=True, text=True)
print(process.stderr)
if process.returncode != 0:
raise Exception('Failed to embed')
embedding = numpy.loadtxt(output_file, delimiter=',')
embedding = numpy.loadtxt(output_file.name, delimiter=',')
return embedding

def export_json(outfile, embedding, images):
Expand Down

0 comments on commit 11df3cc

Please sign in to comment.