def main():
# Load the Inception model so it is ready for classifying images.
try:
model = inception.Inception()
except FileNotFoundError:
print ('###### warning ######')
print ('this script requires inception.maybe_download() executed at least once, running it now')
inception.maybe_download()
model = inception.Inception()
while True:
try:
start_time_camera = time.time()
# multiple times to empty the buffer
img = cam.get_image()
img = cam.get_image()
img = cam.get_image()
image = pygame.surfarray.array3d(img)
image = np.fliplr(np.rot90(image, 3))
if debug:
# Save the image that was just classified (for debug)
im = Image.fromarray(image)
im.save(image_path)
end_time_camera = time.time()
start_time = time.time()
#print ("Classifying image from camera...")
with warnings.catch_warnings():
warnings.simplefilter("ignore")
classify(model=model, image=image)
end_time = time.time()
time_dif_camera = end_time_camera - start_time_camera
time_dif = end_time - start_time
# Print the time-usage.
out_file.write('###### time usage camera ######\n')
out_file.write(str(timedelta(seconds=int(round(time_dif_camera))))+"\n")
out_file.write('###### time usage NN ######\n')
out_file.write(str(timedelta(seconds=int(round(time_dif))))+"\n")
out_file.flush()
os.fsync(out_file)
print('###### time usage camera ######')
print(str(timedelta(seconds=int(round(time_dif_camera)))))
print('###### time usage NN ######')
print(str(timedelta(seconds=int(round(time_dif)))))
except (KeyboardInterrupt, SystemExit, RuntimeError, SystemError):
cam.stop()
model.close()
out_file.close()
评论列表
文章目录