def predict(self): try: m = models.get_model(self.model_name) except: msg("%s is not available for generating responses" % self.model_name) raise Exception # resps = self.load('resps') # if resps is None: # raise ValueError('no response file found for %s' % # self.model_name) else: m.load_image = load_image preds = m.predict(self.ims, topn=5) self.save(preds, "preds") return preds
def predict(self): try: m = models.get_model(self.model_name) except: msg('%s is not available for generating responses' % self.model_name) raise Exception # resps = self.load('resps') # if resps is None: # raise ValueError('no response file found for %s' % # self.model_name) else: m.load_image = load_image preds = m.predict(self.ims, topn=5) self.save(preds, 'preds') return preds
def classify(self): try: m = models.get_model(self.model_name) except: msg("%s is not available for generating responses" % self.model_name) resps = self.load("resps") if resps is None: raise ValueError("no response file found for %s" % self.model_name) else: m.load_image = load_image output = m.run(self.ims, layers=self.layers, return_dict=True) resps = OrderedDict() for layer, out in output.items(): resps[layer] = out.reshape((out.shape[0], -1)) if self.model_name in ["hmax_hmin", "hmax_pnas"]: self.save(resps, "resps") return resps
def classify(self): try: m = models.get_model(self.model_name) except: msg('%s is not available for generating responses' % self.model_name) resps = self.load('resps') if resps is None: raise ValueError('no response file found for %s' % self.model_name) else: m.load_image = load_image output = m.run(self.ims, layers=self.layers, return_dict=True) resps = OrderedDict() for layer, out in output.items(): resps[layer] = out.reshape((out.shape[0], -1)) if self.model_name in ['hmax_hmin', 'hmax_pnas']: self.save(resps, 'resps') return resps
def predict(self): _, sel = self.filter_synset_ids() try: m = models.get_model(self.model_name) except: base.msg('%s is not available for generating responses' %self.model_name) raise Exception else: m.load_image = base.load_image preds = m.predict(self.ims, topn=1000) # limit to top 5 guesses that are in Snodgrass top5 = [] for pred in preds: tmp = [] for p in pred: if p['synset'] in sel: tmp.append(p) if len(tmp) == 5: top5.append(tmp) break self.save(top5, 'preds') return preds
def predict(self): _, sel = self.filter_synset_ids() try: m = models.get_model(self.model_name) except: base.msg('%s is not available for generating responses' % self.model_name) raise Exception else: m.load_image = base.load_image preds = m.predict(self.ims, topn=1000) # limit to top 5 guesses that are in Snodgrass top5 = [] for pred in preds: tmp = [] for p in pred: if p['synset'] in sel: tmp.append(p) if len(tmp) == 5: top5.append(tmp) break self.save(top5, 'preds') return preds