Skip to content

Commit

Permalink
📝 docs(CHANGELOG.md): update changelog with v0.4.2 release details
Browse files Browse the repository at this point in the history
🐛 fix(auth.rs): prevent redundant retrieval of pushPageId and ssid on verification code error
♻️ refactor(classifier.rs): simplify grayscale conversion and mean_std calculation for better readability and performance
  • Loading branch information
wenxuanjun committed May 16, 2024
1 parent 99c7c80 commit c2f60de
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 28 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [0.4.2] - 2024-05-16

- 验证码错误时不再重复获取 pushPageId 和 ssid

## [0.4.1] - 2024-05-12

-`image` 替换成 `resize``zune-jpeg` 以减小包体积
Expand Down Expand Up @@ -26,6 +30,7 @@
- Initial release
- 在 Windows 和 Linux 上通过测试

[0.4.2]: https://github.com/ShanghaitechGeekPie/net-loginer/releases/tag/v0.4.2
[0.4.1]: https://github.com/ShanghaitechGeekPie/net-loginer/releases/tag/v0.4.1
[0.4.0]: https://github.com/ShanghaitechGeekPie/net-loginer/releases/tag/v0.4.0
[0.3.1]: https://github.com/ShanghaitechGeekPie/net-loginer/releases/tag/v0.3.1
Expand Down
16 changes: 8 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,9 @@ impl Authenticator {
}

fn login_for_ip(&self, ip_address: &Ipv4Addr) -> Result<()> {
let (push_page_id, ssid) = self.get_page_params(*ip_address)?;

loop {
let (push_page_id, ssid) = self.get_page_params(*ip_address)?;
let verify_code = self.get_verify_code(*ip_address)?;

let json_value = self
Expand Down
36 changes: 17 additions & 19 deletions src/classifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,33 +78,31 @@ impl Classifier {
let (image, width, height) = self.resize_image(image)?;

let image_bytes = match self.channels {
ModelChannels::Gray => {
let mut gray_image = vec![0; image.len() / 3];
for (i, pixels) in image.chunks(3).enumerate() {
let gray = 0.2989 * pixels[0] as f32
ModelChannels::Gray => image
.chunks(3)
.map(|pixels| {
(0.2989 * pixels[0] as f32
+ 0.5870 * pixels[1] as f32
+ 0.1140 * pixels[2] as f32;
gray_image[i] = gray as u8;
}
gray_image
}
+ 0.1140 * pixels[2] as f32) as u8
})
.collect::<Vec<_>>(),
ModelChannels::RGB => image,
};

let mean_std = match self.channels {
ModelChannels::Gray => vec![(0.456f32, 0.224f32)],
ModelChannels::RGB => vec![
(0.485f32, 0.229f32),
(0.456f32, 0.224f32),
(0.406f32, 0.225f32),
],
};

let tensor = Array::from_shape_fn(
(1, self.channels as usize, height, width),
|(_, c, i, j)| {
let now = image_bytes[(i * width + j) * self.channels as usize + c] as f32;
let (mean, std) = if self.channels == ModelChannels::Gray {
(0.456f32, 0.224f32)
} else {
match c {
0 => (0.485f32, 0.229f32),
1 => (0.456f32, 0.224f32),
2 => (0.406f32, 0.225f32),
_ => unreachable!(),
}
};
let (mean, std) = mean_std[c];
((now / 255f32) - mean) / std
},
);
Expand Down

0 comments on commit c2f60de

Please sign in to comment.