Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
139 commits
Select commit Hold shift + click to select a range
e1553ab
before huber loss
DerrickAppiahOsei Sep 26, 2024
3ee8cbc
Merge branch 'Final-Electron-Counting-Commits' of https://github.com/…
DerrickAppiahOsei Sep 26, 2024
67bb919
first commit for sept 27
DerrickAppiahOsei Sep 27, 2024
4cc4a41
new model for generalization
DerrickAppiahOsei Sep 27, 2024
4b4af8d
sept 28 commit
DerrickAppiahOsei Sep 28, 2024
69638da
underfitting model
DerrickAppiahOsei Sep 29, 2024
355a207
october 1st commit
DerrickAppiahOsei Oct 1, 2024
78db0d5
october 2 commit
DerrickAppiahOsei Oct 2, 2024
d4bf93b
october 3 first commit
DerrickAppiahOsei Oct 3, 2024
627df25
josh's idea
DerrickAppiahOsei Oct 3, 2024
a745d0a
first commit october 4
DerrickAppiahOsei Oct 4, 2024
c6ff419
reduce model depth
DerrickAppiahOsei Oct 4, 2024
0602a1a
perfect overfit for linear
DerrickAppiahOsei Oct 6, 2024
084b6bf
This is the commit for Sunday
DerrickAppiahOsei Oct 6, 2024
ebccb7a
fixed false positives
DerrickAppiahOsei Oct 7, 2024
7008136
trained longer october 8
DerrickAppiahOsei Oct 8, 2024
91ba95b
added a new layer
DerrickAppiahOsei Oct 8, 2024
c28a6bc
index84trainMSE
DerrickAppiahOsei Oct 9, 2024
7fa6639
fixing data generation
DerrickAppiahOsei Oct 9, 2024
61f3a1d
sparse spots
DerrickAppiahOsei Oct 10, 2024
dac2ae0
good results fromm sparse spots
DerrickAppiahOsei Oct 11, 2024
c8724a5
this is a one layer model
DerrickAppiahOsei Oct 20, 2024
662d11f
first good train for 32 by 32
DerrickAppiahOsei Oct 21, 2024
6ecaa7c
using yolo
DerrickAppiahOsei Oct 22, 2024
64584e1
using bottlenecks
DerrickAppiahOsei Oct 22, 2024
82d5459
Josh's idea is the copy
DerrickAppiahOsei Oct 22, 2024
58e2c42
perfect overfit predictions
DerrickAppiahOsei Oct 23, 2024
36fdd9f
dropout 5 specific hits
DerrickAppiahOsei Oct 23, 2024
48ff546
No noise for data
DerrickAppiahOsei Oct 23, 2024
f0b98b1
before debugging
DerrickAppiahOsei Oct 24, 2024
4d078de
new code from scratch
DerrickAppiahOsei Oct 24, 2024
d70285e
slow debugging with fixed pattern of spots
DerrickAppiahOsei Oct 24, 2024
ee79da1
october 25 first commit
DerrickAppiahOsei Oct 25, 2024
2a812ef
october 28 first commit
DerrickAppiahOsei Oct 28, 2024
bf5c3f8
this model works for 5 hits and 3 hits
DerrickAppiahOsei Oct 29, 2024
e5cdcce
16by16 spots
DerrickAppiahOsei Oct 30, 2024
e60fe83
16 by 16 40images
DerrickAppiahOsei Oct 30, 2024
10df7f3
before calling the sort function in my training
DerrickAppiahOsei Oct 30, 2024
2d90ba9
called sort function in loss calculation
DerrickAppiahOsei Oct 30, 2024
6ba6cb2
first commit for october 31
DerrickAppiahOsei Oct 31, 2024
e9b6cf4
fixing sorting
DerrickAppiahOsei Oct 31, 2024
1bdc20f
first commit on Nov 1
DerrickAppiahOsei Nov 1, 2024
0cfab66
my original model for 5 spots
DerrickAppiahOsei Nov 1, 2024
76430db
first commit Nov 2 bigger model
DerrickAppiahOsei Nov 2, 2024
5d51383
first commit Nov 4
DerrickAppiahOsei Nov 4, 2024
d7e3903
results from dropouts
DerrickAppiahOsei Nov 5, 2024
338bdf1
before using IOU
DerrickAppiahOsei Nov 6, 2024
928d452
first IOU
DerrickAppiahOsei Nov 7, 2024
081c53a
all 80K iou
DerrickAppiahOsei Nov 7, 2024
b0cf434
using attention blocks
DerrickAppiahOsei Nov 7, 2024
4bb7de7
low res 1 layer
DerrickAppiahOsei Nov 8, 2024
f8a0290
tiling code
DerrickAppiahOsei Nov 9, 2024
1d0104f
tiling for 64 by 64 Nov 9
DerrickAppiahOsei Nov 9, 2024
eea6c81
debugging tiling code
DerrickAppiahOsei Nov 10, 2024
9b6c37d
this is for the low resolution images
DerrickAppiahOsei Nov 10, 2024
c3fd72c
code for high res images
DerrickAppiahOsei Nov 10, 2024
6f3e0d9
before editing the high res code
DerrickAppiahOsei Nov 10, 2024
9e364c8
first commit Nov 11
DerrickAppiahOsei Nov 11, 2024
c6adf2e
working tiles code for 64 by 64
DerrickAppiahOsei Nov 11, 2024
69613b2
problem with additiona; spots after predictions
DerrickAppiahOsei Nov 11, 2024
2c79c39
new code for 32 by 32 images tiles
DerrickAppiahOsei Nov 11, 2024
d20db26
this code perfectly works for 32by32 images' tiles
DerrickAppiahOsei Nov 11, 2024
10d6dbd
this code works perfectly for 32 32 tiles
DerrickAppiahOsei Nov 12, 2024
6011e41
this works perfectly for visualising the 64 by 6t4 trained tiles
DerrickAppiahOsei Nov 12, 2024
35db6fa
working notebook for 64
DerrickAppiahOsei Nov 12, 2024
18867e0
working code for each kind of image
DerrickAppiahOsei Nov 12, 2024
d877f5c
final 64 by 64 code
DerrickAppiahOsei Nov 12, 2024
4e16b79
this code works for 64 64 tiles different hit types
DerrickAppiahOsei Nov 12, 2024
5c06778
this codeworks for 64 64 one index no noise 13 spots
DerrickAppiahOsei Nov 13, 2024
696daa6
working 64 but increase batch size and data size to combat overfitting
DerrickAppiahOsei Nov 14, 2024
e719253
working 64 tiles code before evaluation
DerrickAppiahOsei Nov 15, 2024
0aa16f1
this code works for the 256 tiles
DerrickAppiahOsei Nov 15, 2024
0755b52
256 by 256 tiles
DerrickAppiahOsei Nov 15, 2024
f49d1b4
FIRST MODEL USED FOR 256 IMAGES
DerrickAppiahOsei Nov 16, 2024
0dd9ffb
code for 256 by 256 images different spots
DerrickAppiahOsei Nov 16, 2024
f77faff
256 images random spot with noise
DerrickAppiahOsei Nov 17, 2024
afe2a07
ensemble method
DerrickAppiahOsei Nov 18, 2024
c34f485
working code for analysis of 256 by 256 images
DerrickAppiahOsei Nov 18, 2024
c3920ab
using iou as loss function
DerrickAppiahOsei Nov 19, 2024
943b07f
'buggy' code for iou computation as loss
DerrickAppiahOsei Nov 19, 2024
71f3e9b
before josh's suggestions about changing tile size to 19
DerrickAppiahOsei Nov 19, 2024
dfa65ff
using Josh's 32 by 32 tile idea
DerrickAppiahOsei Nov 20, 2024
6752c3f
code for a 32by32 tile but with 'wrong' loss calculation
DerrickAppiahOsei Nov 21, 2024
b5babc4
using sirted indices for loss
DerrickAppiahOsei Nov 21, 2024
5707b74
code before Julian's modifications
DerrickAppiahOsei Nov 22, 2024
b1c0aa6
using Julian's logic of masking and ignoring mask
DerrickAppiahOsei Nov 22, 2024
70ffa13
all code including Julian's suggestions
DerrickAppiahOsei Nov 23, 2024
3b6f74f
using MSE and 0.1 threshold gave perfec t predictions and no false po…
DerrickAppiahOsei Nov 23, 2024
11e3f11
this code somewhat works for finding the Precision and Recall
DerrickAppiahOsei Nov 23, 2024
ab2a364
perfect code for prediction,visualization and evaluation per image
DerrickAppiahOsei Nov 23, 2024
337e117
working code for random index no noise training
DerrickAppiahOsei Nov 24, 2024
1ebf3fa
tried working model with no sigmoid
DerrickAppiahOsei Nov 24, 2024
805ea97
working codes before cleaning up
DerrickAppiahOsei Nov 25, 2024
8fa0b50
near perfect results for 200 electron hits with sigmoid and mse
DerrickAppiahOsei Dec 2, 2024
370aed6
using hugging face's model
DerrickAppiahOsei Dec 18, 2024
23e5d12
my hugging face trials
DerrickAppiahOsei Dec 18, 2024
5f7065d
first commit fo rmy computer vision project
DerrickAppiahOsei Jan 8, 2025
111ab8c
new commit for my CV project
DerrickAppiahOsei Jan 9, 2025
daea0c0
cv work with step by step procedure
DerrickAppiahOsei Jan 9, 2025
1749153
computer vision project with noise images
DerrickAppiahOsei Jan 10, 2025
fa41938
using two heads model
DerrickAppiahOsei Jan 14, 2025
6d02990
using binary cross entropy and mse
DerrickAppiahOsei Jan 14, 2025
3a54af4
using custom Hungarian Loss
DerrickAppiahOsei Jan 14, 2025
57cdba5
using gpu acceleration for data generation
DerrickAppiahOsei Jan 15, 2025
092d0a2
using variable loss for custom Hungarian
DerrickAppiahOsei Jan 16, 2025
794acdf
kernel size of 5 and 16 tile size
DerrickAppiahOsei Jan 18, 2025
a0a60e9
using 2 heads and losses
DerrickAppiahOsei Jan 20, 2025
6fede5b
being biased i selecting tile type
DerrickAppiahOsei Jan 21, 2025
ce14d5e
using a class and prob for dataset
DerrickAppiahOsei Jan 23, 2025
a30de0d
converting to hls4ml
DerrickAppiahOsei Jan 27, 2025
e80c928
hls4ml conversion
DerrickAppiahOsei Jan 27, 2025
fb070b1
everything before April 16 2025
DerrickAppiahOsei Apr 16, 2025
1680ba1
8x8 receptive field increased architecture
DerrickAppiahOsei May 2, 2025
7770dd1
deeper architecture
DerrickAppiahOsei May 3, 2025
8cc6ba5
still working on missing preds using loss function
DerrickAppiahOsei May 3, 2025
3b68099
multiply xy by sigmoid p instead
DerrickAppiahOsei May 3, 2025
d652bc1
include cost for false positives
DerrickAppiahOsei May 4, 2025
438d08e
this is my result for using just simple mse
DerrickAppiahOsei May 14, 2025
ca9bb8e
just simple plain mse
DerrickAppiahOsei May 14, 2025
8886463
results for simple mse
DerrickAppiahOsei May 14, 2025
3b997d9
this is my results for mask out zeroes
DerrickAppiahOsei May 14, 2025
264d21d
better results but some FN
DerrickAppiahOsei May 14, 2025
e41494d
so this manual computation points to the preds being swapped
DerrickAppiahOsei May 14, 2025
206c2a2
more indepth analysis about mse
DerrickAppiahOsei May 14, 2025
a90472a
fixing my loss algorithm for analysis
DerrickAppiahOsei May 15, 2025
7e248a7
permed mse no perm bce
DerrickAppiahOsei May 15, 2025
8d0d191
now weighting loss
DerrickAppiahOsei May 15, 2025
d46a9c8
still investigating loss computation post training
DerrickAppiahOsei May 19, 2025
2b3aabe
good analysis as in solution for high mse found
DerrickAppiahOsei May 19, 2025
46b4b29
before fixing the averaging issue for the mse
DerrickAppiahOsei May 20, 2025
1ed10d3
average over only active cells
DerrickAppiahOsei May 20, 2025
c7d3c25
necessary tables and plots
DerrickAppiahOsei May 20, 2025
8413bdd
using a receptive field stride of 8
DerrickAppiahOsei May 22, 2025
6988b78
good idea using stride of 8
DerrickAppiahOsei May 22, 2025
ec138da
this looks good. I define FR as 8 but the math is 22 and the stride is 8
DerrickAppiahOsei May 22, 2025
084dbbe
changed architecture to have 8RF 8RFs
DerrickAppiahOsei May 22, 2025
dfa220f
good predictions for rf8 rfs8
DerrickAppiahOsei May 22, 2025
b1c3ba3
with equal weights on 2 and 1 hits, model is even 80% confident for a…
DerrickAppiahOsei May 22, 2025
22ef310
this is okay as far as weighting losses go
DerrickAppiahOsei May 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,288 changes: 1,288 additions & 0 deletions All notebooks for Tiles/Debugging Tiling images High Res .ipynb

Large diffs are not rendered by default.

8,109 changes: 8,109 additions & 0 deletions All notebooks for Tiles/Model Training(Fixed)Experimental 13.ipynb

Large diffs are not rendered by default.

2,265 changes: 2,265 additions & 0 deletions All notebooks for Tiles/Tiling images High Res copy.ipynb

Large diffs are not rendered by default.

3,588 changes: 3,588 additions & 0 deletions All notebooks for Tiles/Tiling images High Res .ipynb

Large diffs are not rendered by default.

1,826 changes: 1,826 additions & 0 deletions All notebooks for Tiles/Tiling images Low Res.ipynb

Large diffs are not rendered by default.

2,329 changes: 2,329 additions & 0 deletions All notebooks for Tiles/Tiling images.ipynb

Large diffs are not rendered by default.

5,384 changes: 5,384 additions & 0 deletions All notebooks for Tiles/Using HuggingFace Model.ipynb

Large diffs are not rendered by default.

1,281 changes: 1,281 additions & 0 deletions All notebooks for Tiles/Working Notebook for high Res Images.ipynb

Large diffs are not rendered by default.

902 changes: 902 additions & 0 deletions Analysis/Final Electron counting project Analysis copy.ipynb

Large diffs are not rendered by default.

1,206 changes: 1,206 additions & 0 deletions Analysis/Final Electron counting project Analysis.ipynb

Large diffs are not rendered by default.

5,038 changes: 5,038 additions & 0 deletions Computer Vision_Object Detection/256 by 256 Training MSE BCE.ipynb

Large diffs are not rendered by default.

4,895 changes: 4,895 additions & 0 deletions Computer Vision_Object Detection/256 by 256 Training copy.ipynb

Large diffs are not rendered by default.

5,149 changes: 5,149 additions & 0 deletions Computer Vision_Object Detection/256 by 256 Training.ipynb

Large diffs are not rendered by default.

5,179 changes: 5,179 additions & 0 deletions Computer Vision_Object Detection/Adapting YoloFrameGrabber.ipynb

Large diffs are not rendered by default.

545 changes: 545 additions & 0 deletions Computer Vision_Object Detection/Data Generator.ipynb

Large diffs are not rendered by default.

4,618 changes: 4,618 additions & 0 deletions Computer Vision_Object Detection/Hungarian Algorithm.ipynb

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions Computer Vision_Object Detection/Object_Detection.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "plaintext"
}
},
"outputs": [],
"source": []
}
],
"metadata": {
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
154 changes: 154 additions & 0 deletions Computer Vision_Object Detection/ReadME.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
For Data Generation
**1.1**
Create a blank canvas (2D array of zeros) with a predefined size, I used 256 by 256. The canvas acts as the background for placing the hits so it will be filled with zeroes initially.


**1.2**
Use a collection of preloaded small images(the frames containing the electron hits) representing "electron hits."
From here on out, I will use frames to represent these small images.
Extract the dimensions (height, width) of these images. Assume all hits have uniform dimensions. For the frames in the 200kV_98000electron.tif file, they are 19 by 19 pixels each.


**1.3.1**
Randomly generate a top-left coordinate (x, y) for the placement on the canvas:
I created a fictitious canvas which overlays the original canvas I want to put the frames on. I will later explain why the fictitious canvas shouldn’t perfectly align with the original canvas.

The goal is to find random top-left corner coordinates (x,y) on the canvas where the frame can be placed. This placement must ensure that the entire frame fits within the canvas without going outside the boundaries. I define the random (x,y) with the lines below.

x = random.randint(1 - width//2, max_x - width//2 - 1), y = random.randint(1 - height//2, max_y - height//2 - 1)
Width and Height will be that for the frame so 19 in this case. Max_x and Max_y will be that for the original canvas.

So the range for the fictitious canvas will be
1 - 19//2 to 256 - 19//2 - 1
1 - 9 to 256 - 9 - 1
-8 to 246 for the x and I repeat the same for y.

I then randomly select a frame from the 200kV_98000electron.tif file and randomly(according to the range calculated) place them on the fictitious canvas and an ‘image’ will be created. Now this ‘image’ will have the fictitious canvas and the original canvas.


**1.3.2**
Ensure coordinates account for potential cropping at the edges:
The center of the frame is calculated based on its top-left corner (x, y) and its dimensions (width, height). I just offset the top-left corner by approximately half of the width and height.
x_center = x + width // 2 —// is floor division.
y_center = y + height // 2

Suppose x = 10 and y = 20 from my edge case(I mean the top-left corner random picking),
x_center = 10 + 19 // 2 = 10 + 9 = 19.
y_center = 20 + 19 // 2 = 20 + 9 = 29.
So the exact position will be the (19,29) on the original canvas. The ‘image’ is then clipped to retain the original canvas size.

The coordinates for each image are stored with the image as tuples.


**1.4**
Create a function to generate multiple images and store the images and centers as h5 datasets.






For Training
2. --Data Preparation
__Initialize Data Loader:__
Use the DataLoader class to load data from an HDF5 file containing:
images: A collection of 2D arrays representing electron hit images.
centers_training: The hit coordinates in each image.
__Load Data:__
Use the load_data method to extract the images and centers arrays from the file.

__Tile Images:__
Divide each image into smaller square tiles of size tile_size using the tile_image method.
Ensure tiles are non-overlapping and of uniform size.

__Map Hits to Tiles:__
Let’s say I pick one 256x256 image

Tile size: 8x8 pixels. This divides the image into 1024 tiles (32 rows × 32 columns) with each tile having a unique index.
Hit centers: Assume there are only 3 hits with the following coordinates: centers = [(1, 2), (10, 5), (14, 14)]
For each hit (x1, y1), we determine the tile it belongs to and its local coordinates within the tile.

Hit 1: (1, 2)

Tile Row and Column:

Tile row = y // tile_size = 2 // 8 = 0.
Tile column = x // tile_size = 1 // 8 = 0.
tile_index = tile_row * (image_width // tile_size) + tile_col = 0 * (256 // 8) + 0 = 0


Local Coordinates:

Local x = x % tile_size = 1 % 8 = 1.
Local y = y % tile_size = 2 % 8 = 2.

The local coordinates are for the tiles and the ‘global’ coordinates are for the giant(256x256) original image.
I repeat the same for all the other hits and store that in a dictionary for each tile index.

Tile Indices: Calculated based on the hit's position relative to the overall image.
Local Coordinates: Allow precise positioning within a specific tile.
Empty Tiles: If no hits fall in a tile, its list of hits will be empty.

__Process Data__
Pad tiles with dummy hits (0, 0) to ensure uniformity up to max_hits_per_tile(I used 2 in my case).

__Normalize Data__
Scale pixel intensities to the range [0, 1].
Normalize hit coordinates to be relative to the tile dimensions (range [0, 1]).

__Create Datasets__
Split normalized data into training and validation sets using train_test_split.
Use TensorFlow’s Dataset API to create batched datasets for:
Training (train_dataset) and Validation (val_dataset).

NB: Tiles may get mixed up if shuffled across images and reconstruction becomes complex if not difficult.



3. Call class to load data
"""

file_path = '/path/to/h5/file'

data_loader = DataLoader(file_path, tile_size=8, max_hits_per_tile=2)
images, centers = data_loader.load_data()

train_dataset, val_dataset, train_images, val_images, train_centers, val_centers = create_datasets(data_loader)"""

4. Define a function to visualise the tiles and their corresponding centers/labels for verification.

5. Neural Network input shape should be (tile_size,tile_size,number of channels) and the classes should be max_number_of_hits_per_tile as the tiles are treated as individual images for the Neural Network.
Model hyperparameters include:
batch size = 500
optimizer = Adam
loss function = Mean Squared Error. if the number of hits per tile are more than 2, it is recommended to use a matching algorithm.
learning rate = 0.001 (use lr scheduler with the following arguments:- monitor='val_loss', factor=0.9, patience=10, verbose=1, mode='min', min_lr=5e-6)


6. Training was done on 2 gpus(A100) which took appoximately 37 mins for 50 epochs.

7.
8.

9. __Model Performance Assessment__
For each tile in the predictions:
compare the predictions to the top left corner of the tile and if it the prediction is not equal to the top left corner, it is a valid prediction.This is done to ignore the padding.Next this coordinate should be greater or .1 pixel relative to the top left corner of the tile.This is a valid predicted hit. Valid doesn't mean True or accurate.This is also done to ignore predictions for paddings that were not neccessarily (0,0) but were close to (0,0).
For each tile in the groundtruth:
compare the coordinates to the top left corner of the tile and if the coordinate is greater than the top left corner, it is a valid groundtruth.

For the filtered predictions:
find the euclidean distance between the groundtruth and the prediction and compare that to a preset pixel distance. If the eucliean distance within the preset pixel distance(denormalize with tile size or how coordinates were normalized), the prediction is a True Positive. If all the groundtruths in the tile have a matched hit and a prediction is without a matched truth, the unmatched prediction is considered a False Positive.

10. __For reconstruction of original image:__
Create a an empty canvas.
since the images used were square images, the number of tiles per row is just the squareroot of the total number of tiles per image.
Pick an index in the tiles for an image:
for the row on which the tile goes, do a floor division of the index with the number of tiles per row.
for the column on which the tile goes, do a modulo computation of the index with the number of tiles per row.
On the empty canvas,place these tiles according to the row and column numbers and use a stride of the tile size.






Loading