Why AP values decrease after k-means++? - object-detection

I used k-means++ to size the anchor boxes to give more AP.
As a result, the AP is lower than before applying k-means++.
Please let me know if there is any cause for this.
Thank you in advance.
before: anchor box (10,13, 16,30, 33,23, 30,61, 62,45, 59,119, 116,90, 156,198, 373,326)
detections_count = 13032, unique_truth_count = 2164
class_id = 0, name = Can, ap = 90.15% (TP = 240, FP = 25)
class_id = 1, name = Bottle, ap = 96.47% (TP = 898, FP = 60)
class_id = 2, name = Box, ap = 74.26% (TP = 50, FP = 21)
class_id = 3, name = Cigarette, ap = 59.19% (TP = 506, FP = 323) for conf_thresh = 0.25, precision = 0.80, recall = 0.78, F1-score = 0.79
for conf_thresh = 0.25, TP = 1694, FP = 429, FN = 470, average IoU = 66.07 % IoU threshold = 50 %, used Area-Under-Curve for each unique Recall
mean average precision (mAP#0.50) = 0.800176, or 80.02 %
after:anchor box (42, 68, 114, 80, 72,159, 187,149, 128,312, 277,330)
detections_count = 3695, unique_truth_count = 2164
class_id = 0, name = Can, ap = 91.05% (TP = 246, FP = 11)
class_id = 1, name = Bottle, ap = 93.78% (TP = 862, FP = 46)
class_id = 2, name = Box, ap = 76.94% (TP = 42, FP = 11)
class_id = 3, name = Cigarette, ap = 37.37% (TP = 184, FP = 57) for conf_thresh = 0.25, precision = 0.91, recall = 0.62, F1-score = 0.74
for conf_thresh = 0.25, TP = 1334, FP = 125, FN = 830, average IoU = 78.62 % IoU threshold = 50 %, used Area-Under-Curve for each unique Recall
mean average precision (mAP#0.50) = 0.747871, or 74.79 %

Related

Why are Y axis labels offset in ggplot?

The Y axis labels are offset
The Y axis labels from 100 to the top are aligned to the right, while from 90 to the bottom are aligned to the left. I've looked at many paramaters and I couldn't find one to be causing this. Also, I haven't found anyone else with this same issue.
Here's my code:
test <- ggplot(data,
aes(x=Month, y=Value, color=Name, group=Name, fill=Name))+
geom_line(size=3)+
geom_point(size=5)+
scale_color_manual(values=c("#FBE785","#0F5F00","#FFC300","#1BFFAA"))+
ylab ("")+
xlab ("")+
labs(caption = paste("Fonte: Fred e IBGE.")) +
scale_x_date(date_labels = "%b/%y", breaks = "6 month", expand=c(0,0))+
coord_cartesian(clip = "off")+
theme_minimal() +
guides(fill=guide_legend())+
theme(panel.background = element_rect(fill= "#122929",color = "#122929"),
plot.background = element_rect(fill = "#122929"),
panel.grid.major = element_line(color = "#4D4B55", size =0.1),
panel.grid.minor = element_line(color= "#4D4B55", size =0.1),
panel.grid = element_blank(),
axis.text.y = element_text(vjust = 1, hjust=-1),
axis.text.x = element_text(vjust = -1, hjust=0),
legend.title = element_blank(),
legend.position = "bottom",
legend.key.width = unit(1.5, "cm"),
plot.caption = element_text(family = "Abel",vjust = -1, hjust = 0,colour="#4D4B55", size= 30),
text = element_text(family = "Abel", color = "#4D4B55",size = 35),
plot.margin = margin(1,1,1.5,1.2, "cm"))
ggsave("./test.png", width = 21, height = 15, dpi = 300)
PS: Not sharing the data itself because I guess that's not where the problem is.
Thanks!
Your text is misaligned because of your axis.text.y argument. Change hjust to 1 and it will be properly aligned. I have provided a minimal reproducible example below.
library(tidyverse)
Month <- rep(x = month.abb, times = 10)
Value <- sample(x = 10:120, size = 120, replace = TRUE)
Name <- sample(x = LETTERS[1:4], size = 120, replace = TRUE)
data <- data.frame(Month, Value, Name)
ggplot(data, aes(x = Month, y = Value, color = Name, group = Name, fill = Name)) +
geom_line(size = 1) + geom_point(size = 2) +
theme(axis.text.y = element_text(vjust = 1, hjust = 1)) # <- problem here

face='bold' of axis.text do not work and axis.line only control left and bottom in ggplot

library(terra)
library(raster)
library(rasterVis)
f <- system.file("external/test.grd", package="raster")
r <- rast(f)
r
rr <- project(x=r,y='epsg:4326')
rr
gplot(rr)+
geom_raster(aes(fill = value),na.rm=T)+
scale_fill_distiller(na.value = NA)+
ggtitle(label = 'Test')+
coord_sf(crs=4326)+
theme(axis.title = element_blank(),
axis.line = element_line(colour='black', linewidth = 3,
linetype=1),
axis.line.x.top = element_line(colour='black', linewidth = 1,
linetype=1),
axis.line.y.right = element_line(colour='black', linewidth = 1,
linetype=1),
plot.title = element_text(hjust = 0.5,size = 20,
face = 'bold',family = 'serif'),
axis.text = element_text(size=20,face='bold',
family = 'serif',color = 'black'),
legend.title=element_text(face='bold',family = 'serif',
size = 15),
legend.text = element_text(size = 15,
face='bold',
family='serif'),
panel.background = element_rect(fill=NA,color = 'black')
)
I met this situation. I checked these codes many times, but the problem seemed still occured.
And I have tried tidyterra package as well. The same problem.
Ref:https://github.com/oscarperpinan/rastervis/issues/96

How can I repelicate this graphic with ggplot2? using R

Image-radarchart
help! this is my df, Im trying to replicate the spiderplot o radarchart in the attachment
result <- data.frame(row.names = c("T1", "T2", "T3"), N = c(2.5, 2.2, 2.6),
P = c(0.15, 0.16, 0.14),
K = c(0.7, 1, 0.8),
Mg = c(0.20, 0.30, 0.32),
Ca = c(0.5, 0.3, 0.56),
S = c(0.22, 0.27, 0.28),
Cl = c(0.5, 0.58, 0.69)
)
max_min <- data.frame(
N = c(2.8, 2.4), P = c(0.18, 0.15), K = c(1.2, 0.9),
Mg = c(0.4, 0.25), Ca = c(0.75, 0.5), S = c(0.35, 0.25),
Cl = c(0.7, 0.5)
)
rownames(max_min) <- c("Max", "Min")
df <- rbind(max_min, result)

Wrong coloring in ggplot line graphs

I have created a ggplot graph with three lines. Each line represents a different column in a data frame and colored in a different color. For some reason, the colors in the final graph are not coordinated to the code.
The data frame:
Scenario 1 Scenario 2 Scenario 3 Years
0.0260 0.0340 0.0366 1
0.0424 0.0562 0.0696 2
0.0638 0.0878 0.1150 3
0.0848 0.1280 0.1578 4
0.1096 0.1680 0.2074 5
0.1336 0.2106 0.2568 6
This is the code:
ggplot(ext2, aes(x = Years))+
geom_line(aes(y = `Scenario 1`, color = "darkblue"))+
geom_line(aes(y = `Scenario 2`, color = "darkred"))+
geom_line(aes(y = `Scenario 3`, color = "darkgreen"))+
xlab("Years")+
ylab("Quasi - extinction probability")+
ggtitle("2 mature individuals")+
geom_segment(aes(x = 45,y = 0.5, xend = 45, yend = 1.1),linetype = "longdash")+
geom_segment(aes(x = 75,y = 0.2, xend = 75, yend = 0.5),linetype = "longdash")+
geom_segment(aes(x = 0,y = 0.5, xend = 100, yend = 0.5),linetype = "longdash")+
geom_segment(aes(x = 0,y = 0.2, xend = 100, yend = 0.2),linetype = "longdash")+
geom_text(x = 20, y = 0.80, label = "CE")+
geom_text(x = 40, y = 0.35, label = "EN")+
scale_colour_manual(values = c("darkblue", "darkred","darkgreen"), labels = c("Scenario 1","Scenario 2","Scenario 3"))+
theme(legend.title = element_blank())+
theme_minimal()
and this is the graph:
Click here to see graph
The problem is that what I defined as 'scenario 3' in the code is actually a representation of 'scenario 2' in the data frame. You can see it according to the values under scenario 2 in the data frame.
For ggplot, the data needs to be in long format before you plot. Then, you can make "Scenarios" (i.e., name) the group, so that you can manually color the individual lines (i.e., with scale_colour_manual).
library(tidyverse)
ext_long <- ext2 %>%
pivot_longer(!Years)
ggplot(ext_long, aes(x = Years, color = name)) +
geom_line(aes(y = value)) +
xlab("Years") +
ylab("Quasi - extinction probability") +
ggtitle("2 mature individuals") +
geom_segment(aes(
x = 45,
y = 0.5,
xend = 45,
yend = 1.1
), linetype = "longdash") +
geom_segment(aes(
x = 75,
y = 0.2,
xend = 75,
yend = 0.5
), linetype = "longdash") +
geom_segment(aes(
x = 0,
y = 0.5,
xend = 100,
yend = 0.5
), linetype = "longdash") +
geom_segment(aes(
x = 0,
y = 0.2,
xend = 100,
yend = 0.2
), linetype = "longdash") +
geom_text(x = 20, y = 0.80, label = "CE") +
geom_text(x = 40, y = 0.35, label = "EN") +
scale_colour_manual(
values = c("darkblue", "darkred", "darkgreen"),
labels = c("Scenario 1", "Scenario 2", "Scenario 3")
) +
theme(legend.title = element_blank()) +
theme_minimal()
Output (only have a small part of the data, which is the reason the lines do not extend across the graph)
Data
ext2 <- structure(
list(
Scenario.1 = c(0.026, 0.0424, 0.0638, 0.0848,
0.1096, 0.1336),
Scenario.2 = c(0.034, 0.0562, 0.0878, 0.128,
0.168, 0.2106),
Scenario.3 = c(0.0366, 0.0696, 0.115, 0.1578,
0.2074, 0.2568),
Years = 1:6
),
class = "data.frame",
row.names = c(NA,-6L)
)

The second description of the x-axis in ggplot2?

I am wondering if there is a way to add the second description of x-axis in ggplot2 as follows: Here "the second description" refers "Sample A / Sample B / two arrows" colored in red (shown in the figure).
Please click for the figure!
Of course, I can just put the "second description" using PowerPoint as I did, but I just wonder if it is possible to add it using ggplot2.
Here is the code for the background plot.
library(ggplot2)
library(ggridges)
x <- data.frame(v1=rnorm(100, mean = -2, sd = 0.022),
v2=rnorm(100, mean = -1, sd = 0.022),
v3=rnorm(100, mean = 0, sd = 0.022),
v4=rnorm(100, mean = 1, sd = 0.022),
v5=rnorm(100, mean = 2, sd = 0.022),
v6=rnorm(100, mean = 3, sd = 0.022),
v7=rnorm(100, mean = 4, sd = 0.022))
colnames(x) <- c("A",
"B",
"C",
"D",
"E",
"F",
"G")
head(x)
# Manipulate the data
library(reshape2)
data <- melt(x)
head(data)
# Generating plot
colors <- rainbow(7)
ggplot(data, aes(x = value, y = variable)) +
geom_density_ridges(aes(fill = variable), alpha=0.6, bandwidth=0.1) +
scale_fill_manual(values = colors)+
theme(axis.title = element_text(size = 12),
axis.text = element_text(size = 10),
legend.text = element_text(size = 12),
plot.title = element_text(size = 17, face = "bold",
margin = margin(b=10), hjust = 0.5),
panel.spacing = unit(0.1, "lines"),
legend.position="none") +
geom_vline(xintercept = 0, linetype="dotted") +
geom_vline(xintercept = 2, linetype="dotted",
color = "red", size=1.2) +
xlab("") +
ylab("Groups") +
labs(title = 'Density plot of each group')
Thank you in advance!
I'm not 100% sure this is what you mean, but you can add text on the x-axis using the following in labs:
labs(x="← Sample A Sample B →")
I got the arrows from unicode here: http://xahlee.info/comp/unicode_arrows.html
There are bigger arrows in the link if needed.
EDIT:
Here's your code adapted with the new labels in red font:
ggplot(data, aes(x = value, y = variable)) +
geom_density_ridges(aes(fill = variable), alpha=0.6, bandwidth=0.1) +
scale_fill_manual(values = colors)+
theme(axis.title = element_text(size = 12),
axis.text = element_text(size = 10),
legend.text = element_text(size = 12),
plot.title = element_text(size = 17, face = "bold",
margin = margin(b=10), hjust = 0.5),
panel.spacing = unit(0.1, "lines"),
legend.position="none") +
geom_vline(xintercept = 0, linetype="dotted") +
geom_vline(xintercept = 2, linetype="dotted",
color = "red", size=1.2) +
xlab("🢀 Sample A Sample B 🢂") +
theme(axis.title.x = element_text(size=40,colour = "red")) +
ylab("Groups") +
labs(title = 'Density plot of each group')
You can also push the labels further apart by adding extra spaces. Bring them closer together with fewer spaces.