def split_data(data: dict, test_ratio: float = 0.2) -> (dict, dict): dev = {} test = {} for label, pictures in data.items(): test_size = int(len(pictures) * test_ratio) test[label] = pictures[:test_size] dev[label] = pictures[test_size:] return dev, test
def plot_images(data, rows, cols, cmap='gray'): if (len(data) > 0): i = 0 for title, image in data.items(): #logging.debug(title) plt.subplot(rows, cols, i + 1), plt.imshow(image, cmap) plt.title(title) plt.xticks([]), plt.yticks([]) i += 1 plt.show()
def reshape(data: dict) -> (np.array, np.array): length = sum(len(lst) for lst in data.values()) # labels = np.empty(length, dtype='<U1') # y = np.ndarray(shape =(45, length), dtype='int32') y = [None] * length labels = [None] * length i = 0 for label, pictures in data.items(): for picture in pictures: labels[i] = label y[i] = picture.flatten() i += 1 return np.array(y), np.array(labels)
def showPrev20(self, class_name, img_number, panel_list, model_number): global currentpage, pagecount currentpage -= 1 if currentpage == 1: self.button4.config(state=tk.DISABLED) if self.button3["state"] != "normal": self.button3.config( state=tk.NORMAL) # button to page down is enabled if model_number.get() == 1: path = 'csv_and_dict_fiveCrop/dictionary/transform1_' else: path = 'csv_and_dict_rotation/dictionary/' #file_path = tk.filedialog.askopenfilename() #img = Image.open(file_path) #image = ImageTk.PhotoImage(img) ##### #path = 'csv_and_dict/dictionary/' class_dictionary_path = path + class_name.get() + '_dictionary.json' with open(class_dictionary_path) as f: data = json.load(f) class_name_pred_sigmoid = 'pred sigmoid ' + class_name.get() image_sorted_per_class = [] for key, value in data.items(): image_sorted_per_class.append( (value['Unnamed: 0'], value[class_name_pred_sigmoid])) image_path = 'JPEGImages/' pagecount = math.ceil(len(image_sorted_per_class) / 20) #image_dictionary = #image_list = list(image_dictionary) total_height = 0 for i in range(20): try: #print(str(((currentpage-1)*20)+i+1)) img = Image.open(image_path + str(image_sorted_per_class[ (currentpage - 1) * 20 + i][0])) image = ImageTk.PhotoImage(img) width, height_img = img.size total_height += height_img a = i * 2 panel_list[a].configure(image=image, height=height_img) panel_list[a].photo = image panel_list[a + 1].configure( text=str((currentpage - 1) * 20 + i + 1) + ') ' + class_name.get() + ': ' + str(image_sorted_per_class[(currentpage - 1) * 20 + i][1]), height=2) except: print("reached the end") break y_height = total_height + height_img * 3 + 2 * 20 #height_image is for buffer print(y_height) self.canvas.config(scrollregion=(0, 0, 0, y_height)) self.update() self.yscrollbar.config(command=self.canvas.yview) img_number.set(currentpage) pass
def showFirst20Results(self, class_name, img_number, panel_list, model_number): global currentpage, pagecount currentpage = 1 if model_number.get() == 1: path = 'csv_and_dict_fiveCrop/dictionary/transform1_' else: path = 'csv_and_dict_rotation/dictionary/' img_number.set(currentpage) if self.button3["state"] != 'normal': self.button3.config(state=tk.NORMAL) if self.button4["state"] != "disabled": self.button4.config(state=tk.DISABLED) total_height = 0 ################# class_dictionary_path = path + class_name.get() + '_dictionary.json' with open(class_dictionary_path) as f: data = json.load(f) class_name_pred_sigmoid = 'pred sigmoid ' + class_name.get() image_sorted_per_class = [] for key, value in data.items(): image_sorted_per_class.append( (value['Unnamed: 0'], value[class_name_pred_sigmoid])) image_path = 'JPEGImages/' pagecount = math.ceil(len(image_sorted_per_class) / 20) #image_dictionary = #image_list = list(image_dictionary) ################# ''' file_path = tk.filedialog.askopenfilename() img = Image.open(file_path) image = ImageTk.PhotoImage(img) width,height_img = img.size print(width,height_img) ''' for i in range(20): ########### try: img = Image.open(image_path + str(image_sorted_per_class[i][0])) image = ImageTk.PhotoImage(img) width, height_img = img.size total_height += height_img ############ a = i * 2 panel_list[a].configure(image=image, height=height_img) panel_list[a].photo = image panel_list[a + 1].configure( text=str(i + 1) + ') ' + class_name.get() + ': ' + str(image_sorted_per_class[(i)][1]), height=2) except: print("reached the end") break y_height = total_height + height_img * 3 + 2 * 20 #height_image is for buffer #print(y_height) self.canvas.config(scrollregion=(0, 0, 0, y_height)) self.update() self.yscrollbar.config(command=self.canvas.yview) ''' for panel in panel_list: panel.configure(image = image) panel.photo = image ''' #imagecanvas.configure.create_image(0,0, anchor=tk.NW,image=img) #self. ''' panel.configure(image = image) panel.photo = image ''' pass