This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
python -m transformers.onnx -m="microsoft/trocr-large-printed" --framework="pt" --feature="vision2seq-lm" . | |
Some weights of VisionEncoderDecoderModel were not initialized from the model checkpoint at microsoft/trocr-large-printed and are newly initialized: ['encoder.pooler.dense.weight', 'encoder.pooler.dense.bias'] | |
You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference. | |
Using framework PyTorch: 1.13.1 | |
/Users/mattc/Desktop/onnx/venv/lib/python3.10/site-packages/transformers/models/vit/modeling_vit.py:176: TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs! | |
if num_channels != self.num_channels: | |
/Users/mattc/Desktop/onnx/venv/lib/python3.10/site-packages/transformers/models/vit/modeling_vit.py:181: TracerWarning: Converting a tensor to a Python |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#read all files, concat | |
from pathlib import Path | |
import pandas as pd | |
pathlist = Path('./Reports_Base').glob('*.tsv') | |
df_array = [] | |
for path in pathlist: | |
df = pd.read_csv(path, sep='\t', encoding='iso-8859-1') | |
df_array.append(df) | |
df = pd.concat(df_array) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Launching lib/main.dart on iPhone 12 Pro Max in debug mode... | |
Xcode build done. 35.1s | |
Failed to build iOS app | |
Error output from Xcode build: | |
↳ | |
** BUILD FAILED ** | |
Xcode's output: | |
↳ | |
/Users/mattc/Development/tutorials/day18_todo/ios/Pods/SQLite.swift/Sources/SQLite/Core/Connection.swift:431:13: warning: 'sqlite3_trace' was deprecated in iOS 10.0: renamed to 'sqlite3_trace_v2(_:_:_:_:)' | |
sqlite3_trace(handle, nil /* xCallback */, nil /* pCtx */) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Mlp(nn.Module): | |
def __init__(self, in_features, hidden_features=None, out_features=None, act_layer=nn.GELU, drop=0.): | |
super().__init__() | |
out_features = out_features or in_features | |
hidden_features = hidden_features or in_features | |
self.fc1 = nn.Linear(in_features, hidden_features) | |
self.act = act_layer() | |
self.fc2 = nn.Linear(hidden_features, out_features) | |
self.drop = nn.Dropout(drop) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
embed_dim = 768 | |
num_heads = 8 | |
block = Block(embed_dim, 8) | |
batch_size = 1 | |
class_token = nn.Parameter(torch.zeros(1, 1, embed_dim)) | |
class_tokens = class_token.expand(batch_size, -1, -1) | |
pos_embed = nn.Parameter(torch.zeros(1, num_patches + 1, embed_dim)) | |
x = torch.cat((class_tokens, patch_output), dim=1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x = self.patch_embed(x) | |
cls_tokens = self.cls_token.expand(B, -1, -1) | |
x = torch.cat((cls_tokens, x), dim=1) | |
x = x + self.pos_embed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PIL import Image | |
loader = DataLoader(dataset = train_dataset, batch_size=1, shuffle=False ) | |
first_batch = next(iter(loader))[0] | |
model = PatchEmbed() | |
patch_output = model(first_batch) | |
batch_size, num_patches, embedding = patch_output.shape | |
num_patches, embedding | |
(196, 768) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import repeat | |
import pdb | |
class PatchEmbed(nn.Module): | |
def __init__(self, img_size=224, patch_size=16, in_chans=3, embed_dim=768): | |
super().__init__() | |
img_size = tuple(repeat(img_size, 2)) | |
patch_size = tuple(repeat(patch_size, 2)) | |
num_patches = (img_size[1] // patch_size[1]) * (img_size[0] // patch_size[0]) | |
self.img_size = img_size | |
self.patch_size = patch_size |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
self.blocks = nn.ModuleList([ | |
Block( | |
dim=embed_dim, num_heads=num_heads, mlp_ratio=mlp_ratio, qkv_bias=qkv_bias, qk_scale=qk_scale, | |
drop=drop_rate, attn_drop=attn_drop_rate, drop_path=dpr[i], norm_layer=norm_layer) | |
for i in range(depth)]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Block(nn.Module): | |
def __init__(self, dim, num_heads, mlp_ratio=4., qkv_bias=False, qk_scale=None, drop=0., attn_drop=0., drop_path=0., act_layer=nn.GELU, norm_layer=nn.LayerNorm): | |
super().__init__() | |
self.norm1 = nn.LayerNorm(dim) | |
self.attn = Attention(dim, num_heads=num_heads, qkv_bias=qkv_bias, qk_scale=qk_scale, attn_drop=attn_drop, proj_drop=drop) | |
self.norm2 = nn.LayerNorm(dim) | |
mlp_hidden_dim = int(dim * mlp_ratio) | |
self.mlp = Mlp(in_features=dim, hidden_features=mlp_hidden_dim, act_layer=act_layer, drop=drop) | |
def forward(self, x): | |
x = x + self.attn(self.norm1(x)) |
NewerOlder