# Trying to save models (Assestion Error)

**URL:** <https://discourse.numenta.org/t/trying-to-save-models-assestion-error/1472>\
**Category:** NuPIC\
**Tags:** nupic\
**Created:** [October 6, 2016, 12:21am UTC](https://discourse.numenta.org/t/trying-to-save-models-assestion-error/1472 "2016-10-06T00:21:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sheiser1](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/sheiser1/32/766_2.png) [@sheiser1](https://discourse.numenta.org/u/sheiser1)\
**Post date:** [October 6, 2016, 12:21am UTC](https://discourse.numenta.org/t/trying-to-save-models-assestion-error/1472/1 "2016-10-06T00:21:15Z")

</div>

Hi all, so I’m receiving this Assertion error when trying to save models in NuPIC using the TemporalAnomaly model type, and wondered if anyone had any ideas:

> Traceback (most recent call last):  
> File “run.py”, line 190, in   
> runModel(only\_csv\_files, plot=plot) #runModel(GYM\_NAME, plot=plot)  
> File “run.py”, line 166, in runModel  
> model.save(path)  
> File “/home/sheiser1/.local/lib/python2.7/site-packages/nupic/frameworks/opf/model.py”, line 289, in save  
> self.\_\_makeDirectoryFromAbsolutePath(saveModelDir)  
> File “/home/sheiser1/.local/lib/python2.7/site-packages/nupic/frameworks/opf/model.py”, line 385, in \_\_makeDirectoryFromAbsolutePath  
> assert os.path.isabs(absDirPath)  
> AssertionError

Here are the modifications I made to the runModel function. First I set the new data directory, and create the list of csv files (‘only\_csv\_files’) that I’ll pass into the modified runModel function.

> mypath = ‘/home/sheiser1/Desktop/zaychik\_proj1-master/Dr\_Zaychik\_Data/selectedData’  
> only\_csv\_files = [f for f in listdir(mypath) if isfile(join(mypath,f)) and os.path.splitext(f)[1] == ‘.csv’]

> for file in only\_csv\_files:  
> print 'File: ',file

> GYM\_NAME = “rec-center-hourly”  
> DATA\_DIR = “/home/sheiser1/Desktop/zaychik\_proj1-master/Dr\_Zaychik\_Data/selectedData” #“.”  
> MODEL\_PARAMS\_DIR = “./model\_params”

Here I change runModel to take in a list of data files instead of just one, replacing ‘gymName’ with ‘only\_csv\_files’. I added an outer loop to the function, because the goal is to learn 20 separate models (1 for each of 20 separate data sets). The idea is to save each model, then run it on each data set (with learning turned off) to see which model best accounts for each given data set. To choose the model that best fits the given data set, I intend to take the model with lowest overall anomalyLikelihood as Matt suggested (if I understood right).

> def runModel(file\_list, plot=False): #def runModel(gymName, plot=False):  
> “”"  
> Assumes the gynName corresponds to both a like-named model\_params file in the  
> model\_params directory, and that the data exists in a like-named CSV file in  
> the current directory.  
> :param gymName: Important for finding model params and input CSV file  
> :param plot: Plot in matplotlib? Don’t use this unless matplotlib is  
> installed.  
> “”"  
> for file1 in file\_list:  
> save = False  
> file\_name = os.path.splitext(file1)[0]  
> path = ‘~/nupic/examples/opf/clients/hotgym/anomaly/one\_gym$’ + file\_name  
> model = None  
> if os.path.exists(path):  
> model = Model.load(path)  
> else:  
> model = createModel(getModelParamsFromName(GYM\_NAME))  
> save = True  
> print “Creating model from %s…” % file\_name  
> inputData = “%s/%s.csv” % (DATA\_DIR, file\_name.replace(" ", “_“))  
> runIoThroughNupic(inputData, model, file\_name, plot)  
> if save:  
> model.save(path)  
> for file2 in file\_list:  
> file2\_name = os.path.splitext(file2)[0]  
> model.disableLearning()  
> print “Running model” + file\_name + ‘on’ + file2\_name  
> inputData = “%s/%s.csv” % (DATA\_DIR, file2\_name.replace(” ", "_”))  
> runIoThroughNupic(inputData, model, file2\_name, plot)  
> os.rename(file2\_name + ‘_out.csv’, file\_name + '_’ + file2\_name + ‘\_out.csv’)

> #print “Creating model from %s…” % gymName  
> #model = createModel(getModelParamsFromName(gymName))  
> #inputData = “%s/%s.csv” % (DATA\_DIR, gymName.replace(" ", “\_”))  
> #runIoThroughNupic(inputData, model, gymName, plot)

> if **name** == “ **main** ”:  
> print DESCRIPTION  
> plot = False  
> new\_model = False  
> args = sys.argv[1:]  
> if “–plot” in args:  
> plot = True  
> runModel(only\_csv\_files, plot=plot) #runModel(GYM\_NAME, plot=plot)

Thanks again!!

---

<div class="post-metadata">

**Author:** ![sheiser1](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/sheiser1/32/766_2.png) [@sheiser1](https://discourse.numenta.org/u/sheiser1)\
**Post date:** [October 6, 2016, 2:34am UTC](https://discourse.numenta.org/t/trying-to-save-models-assestion-error/1472/2 "2016-10-06T02:34:17Z")

</div>

Eww I’m sorry for this mess! I made a gist as recommended and have the link here. Thanks

> <https://gist.github.com/gotham29/b17efc8ad1a26166fa5eec55abab1b0f>

---

<div class="post-metadata">

**Author:** ![sheiser1](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/sheiser1/32/766_2.png) [@sheiser1](https://discourse.numenta.org/u/sheiser1)\
**Post date:** [October 6, 2016, 3:14am UTC](https://discourse.numenta.org/t/trying-to-save-models-assestion-error/1472/3 "2016-10-06T03:14:28Z")

</div>

I think I’ve actually solved this, simply by assigning ‘mypath’ to the full path extension (beginning with /home/sheiser1/nuipic rather than ~/nupic, since an absolute path apparently has to start with a slash in Unix. I’m sure I’ll be along with another question soon but I think this one’s closed 🕶

---

<div class="post-metadata">

**Author:** ![rhyolight](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/rhyolight/32/3922_2.png) [@rhyolight](https://discourse.numenta.org/u/rhyolight)\
**Post date:** [October 6, 2016, 8:09pm UTC](https://discourse.numenta.org/t/trying-to-save-models-assestion-error/1472/4 "2016-10-06T20:09:26Z")

</div>

Good self-help! Sorry I didn’t get to this earlier. 🕶
