Skip to content

Commit

Permalink
Adding a new example to README.:
Browse files Browse the repository at this point in the history
  • Loading branch information
kaanaksit committed Dec 1, 2023
1 parent 3894f2b commit d48e225
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,41 @@ ycrcb_image = odak.learn.perception.color_conversion.rgb_2_ycrcb(input_rgb_image
rgb_image = odak.learn.perception.color_conversion.ycrcb_2_rgb(ycrcb_image)
```

Here is a simple example on `deep learning` methods with odak:
```python
import odak
import torch

x0 = torch.rand(1, 8, 128, 128)
model_cbam = odak.learn.models.convolutional_block_attention(gate_channels = 8)
y0 = model_cbam(x0)


x1 = torch.arange(10).unsqueeze(-1) * 30.
pos_x1 = torch.arange(x1.shape[0]).unsqueeze(-1) * 1.
model_mlp = odak.learn.models.multi_layer_perceptron(
dimensions = [1, 5, 1],
bias = False,
model_type = 'conventional'
)
optimizer = torch.optim.AdamW(model_mlp.parameters(), lr = 1e-3)
loss_function = torch.nn.MSELoss()
for epoch in range(10000):
optimizer.zero_grad()
estimation = model_mlp(pos_x1)
ground_truth = x1
loss = loss_function(estimation, ground_truth)
loss.backward(retain_graph = True)
optimizer.step()
print('Training loss: {}'.format(loss.item()))

for item_id, item in enumerate(pos_x1):
torch.no_grad()
ground_truth = x1[item_id]
estimation = model_mlp(item)
print('Input: {}, Ground truth: {}, Estimation: {}'.format(item, ground_truth, estimation))
```

For more of these examples, you can either check our [course documentation](https://kaanaksit.com/odak/course) or visit our [unit tests](https://github.com/kaanaksit/odak/tree/master/test) to get inspired.

## Sample Projects that use Odak
Expand Down
1 change: 1 addition & 0 deletions test/test_learn_models_multi_layer_perceptron.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ def trial(output_values, input_values, loss_function, model):
estimated_image = torch.zeros_like(output_values)
for input_value in input_values:
torch.no_grad()
print(input_value.shape);import sys;sys.exit()
estimation = model(input_value)
ground_truth = output_values[input_value[:, 0].int(), input_value[:, 1].int(), :]
estimated_image[input_value[:, 0].int(), input_value[:, 1].int(), :] = estimation
Expand Down

0 comments on commit d48e225

Please sign in to comment.