I work with a dataset, I trained a model and want to get more data so I use my model on unlabeled data and then plot the data with the model-maded label to see if it’s a good label or no. I want to implement a slider in order to choose the opacity of the label to see if it’s a relevant label or no.
The problem is that the slider does show but I can’t interact with it.
Here is my code, I have the latest version of matplotlib,
def mise_a_jour_graphique(val):
global fig
alpha = slider_alpha.val
a_dessiner(alpha)
fig.canvas.draw_idle()
def a_dessiner(alpha):
global nb_label
global coor
global image_rgb
global ax
global fig
annotations = []
ax.clear()
ax.imshow(image_rgb) # Afficher l'image de fond
for i, el in coor:
annotation = dessin(i, el, image_rgb, alpha)
fig.canvas.draw_idle()
annotations.append(annotation)
nb_label = len(annotations)
adjust_text(annotations, arrowprops=dict(arrowstyle="->", color='black'))
ax.axis("off")
#fig.canvas.draw_idle()
def dessin(j, coor, img, alpha):
global ax
global fig
w, h, _ = img.shape
x_coor, y_coor = [], []
for i in range(0, len(coor)-1, 2):
x, y = float(coor[i]), float(coor[i+1])
x_coor.append(x * h)
y_coor.append(y * w)
ax.scatter(x_coor, y_coor, s=1, alpha=alpha)
ax.plot(x_coor, y_coor, color='black', zorder=1, alpha=alpha)
ax.fill(x_coor, y_coor, color="black", alpha=alpha)
annotation = ax.text(x_coor[0], y_coor[0], f'Label {j}', fontsize=9, ha='center', bbox=dict(boxstyle="round,pad=0.3", edgecolor="black", facecolor="white", alpha=alpha))
fig.canvas.draw_idle()
return annotation
def tracer_figure(path_files):
global nb_label
global coor
global image_rgb
global fig
global ax
global slider_alpha
if path_files.endswith('.txt'):
lbl_pt = path_files
img_pt = lbl_pt.replace('/labels', '/images').replace('txt', 'jpg')
elif path_files.endswith('.jpg'):
img_pt = path_files
lbl_pt = img_pt.replace('/images', '/labels').replace('jpg', 'txt')
else:
raise ValueError
coor = label_to_liste(lbl_pt)
image = cv2.imread(img_pt)
image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
fig, ax = plt.subplots()
fig.subplots_adjust(bottom=0.25)
alpha_init = 0.7
a_dessiner(alpha_init)
ax.imshow(image_rgb)
axfreq = fig.add_axes([0.25, 0.1, 0.65, 0.03])
slider_alpha = Slider(ax=axfreq,label='Oppacité', valmin=0.1, valmax=1.0, valinit=alpha_init, valstep=0.1)
slider_alpha.on_changed(mise_a_jour_graphique)
plt.show()
user26466036 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.