0

I'm a beginner with Python, but I'm at the final stages of a project I've been working on for the past year and I need help at the final step.

If needed I'll post my code though it's not really relevant.

Here is my problem:

I have a database of images, say for example a 100 images. On each one of those images, I run an algorithm called ICA. This algorithm is very heavy to compute and each picture individually usually takes 7-10 seconds, so 100 pictures can take 700-1000 seconds, and that's way too long to wait.

Thing is, my database of images never changes. I never add pictures or delete pictures, and so the output of the ICA algorithm is always the same. So in reality, every time I run my code, I wait forever and gain the same output every time.

Is there a way to save the data to the hard disk, and extract it at a later time?

Say, I compute the ICA of the 100 images, it takes forever, and I save it and close my computer. Now when I run the program, I don't want it to recompute ICA, I want it to use the values I stored previously.

Would such a thing be possible in Python? if so - how?

Oria Gruber
  • 1,513
  • 2
  • 22
  • 44
  • possible duplicate of [Saving an Object (Data persistence in Python)](http://stackoverflow.com/questions/4529815/saving-an-object-data-persistence-in-python). You can read about Pickling in the docs [here](https://docs.python.org/2/library/pickle.html). There's a whole section in there about data persistence you can check out. – SuperBiasedMan Jul 26 '15 at 19:09

1 Answers1

-1

Since you're running computation-heavy algorithms, I'm going to assume you're using Numpy. If not, you should be.

Numpy has a numpy.save() function that lets you save arrays in binary format. You can then load them using numpy.load().

EDIT: Docs for aforementioned functions can be found here under the "NPZ Files" section.

selimb
  • 360
  • 1
  • 4
  • 11