Skip to main content

Posts

Pytorch parameters are not updating

This seems to be a common question for folks who start using pytorch and I guess this one is my version of it. Is it clear to a more experienced pytorch user why my params are not updating as my code loops? import torch import numpy as np np.random.seed(10) def optimize(final_shares: torch.Tensor, target_weight, prices, loss_func=None): final_shares = final_shares.clamp(0.) mv = torch.multiply(final_shares, prices) w = torch.div(mv, torch.sum(mv)) print(w) return loss_func(w, target_weight) def main(): position_count = 16 cash_buffer = .001 starting_shares = torch.tensor(np.random.uniform(low=1, high=50, size=position_count), dtype=torch.float64) prices = torch.tensor(np.random.uniform(low=1, high=100, size=position_count), dtype=torch.float64) prices[-1] = 1. x_param = torch.nn.Parameter(starting_shares, requires_grad=True) target_weights = ((1 - cash_buffer) / (position_count - 1)) target_weights_vec = [target_weights] * (p

How to Share a Leaflet Map Instance Across Multiple Vue 2 Components?

Background: I'm building a web application using Vue 2 and Leaflet. I'm trying to share a single Leaflet map instance across multiple components in my application. Issue: I'm looking for a way to create a Leaflet map instance in one place and access and use it across multiple components in the entire application. Code Example: This is a method I have tried, but I don't know if this way of writing is appropriate. Maybe there is a better way: App.vue provide() { return { parent: this }; }, mounted() { this.map = L.map('map',{}) } components inject: ["parent"] Is there a more appropriate way? Via Active questions tagged javascript - Stack Overflow https://ift.tt/aVhrA5x

How to do only page segmentation / layout detection with Tesseract (mode --psm 2)?

I would like to use page segmentation from Tesseract without running the OCR, as I have my own custom OCR model, and it takes to long to run page segmentation AND OCR. I tried using the --psm 2 mode in command line mode of Tesseract , and in pytesseract , and it didn't work as promised. I'm working in Linux, and am coding in Python 3.10. I currently use the tesseract-ocr-api from layoutparser Documentation . The code looks like the following: import layoutparser as lp ocr_agent = lp.TesseractAgent() res = ocr_agent.detect(img_path, return_response=True) layout_info = res['data'] The layout_info then is a pd.DataFrame and contains Layout information on the level of blocks, paragraph, lines and words and also the OCR output. The problem is that this is very slow; on my machine it takes 7s per image and I actually don't need the OCR. Hence, I want page segmentation (also sometimes called layout detection) only. According to the Tesseract ( Documentation ), th

error: tf.compat.v1.app.run() while running model_main_tf2.py object detection

I have a problem with running this command in Terminal: python model_main_tf2.py --model_dir=C:\\models\\my_ssd_resnet50_v1_fpn --pipeline_config_path=\\models\\my_ssd_resnet50_v1_fpn\\pipeline.config The first error I receive is tf.compat.v1.app.run() . tfrecord are generated, I created the label_map.pbtxt . Python 3.9.9 Tensorflow 2.10.1 source https://stackoverflow.com/questions/77706092/error-tf-compat-v1-app-run-while-running-model-main-tf2-py-object-detection

ttkbootstrap.tableview.Tableview rowheight doesn't work for data rows

Cannot set the row height of ttkbootstrap.tableview.Tablewview data rows. I can change the heading but not the data rows. import ttkbootstrap as ttk from ttkbootstrap.tableview import Tableview from ttkbootstrap.constants import * app = ttk.Window() style = app.style **style.configure('Treeview.Heading', rowheight=80, font=(None, 18)) style.configure('Treeview', rowheight=80, font=(None, 18))** coldata = [{"text": "LNum", "stretch": False}, "CompanyName", {"text": "UserCount", "stretch": False}, ] rowdata = [('A123', 'IzzyCo', 12), ('A136', 'Kimdee Inc.', 45), ('A158', 'Farmadding Co.', 36)] dt = Tableview( master=app, coldata=coldata, rowdata=rowdata, paginated=True, searchable=True ) dt.pack(fill=BOTH, expand=YES, padx=10, pady=10) dt.load_table_data() app.mainloop() I expect the data row height to increase in height but it doe

Anyone can help me on this discord bot command error

I'm doing a discord bot, at first it's just an XP bot, the problem is related with the output on the server, when i write the command in the chat commands. When i do a mencion for me or for another users, the bot do not response, ithis the same thing if i mention he or not mention anyone follow de code bellow import discord from discord.ext import commands import json import os intents = discord.Intents.default() intents.messages = True intents.guilds = True intents.guild_messages = True bot = commands.Bot(command_prefix=commands.when_mentioned_or("!"), intents=intents) xp_channel_id = 1186457318850838539 # Altere para o ID real do canal config_file = "config.json" # Verifica se o arquivo JSON já existe e carrega os dados if os.path.exists(config_file): with open(config_file, "r") as f: config = json.load(f) else: config = {"XP": {}} def save_config(): with open(config_file, "w") as f: json.dump(confi

csv to html table ( header mapping | django)

I'm currently working on a Django project where users can upload a CSV file with headers in different languages. My goal is to allow users to map these headers to the corresponding fields in my database model. For example : Fields in the database: (first name, last name, age, country) User CSV header : (pays, prenom, nom, age) In this scenario, the user has provided all the necessary fields but in French and in a different order. After the user clicks the upload button, my plan is to load the CSV file into a table or another format that allows them to easily map the fields in the CSV file to the columns in my database. Thank you in advance. Tried using Pandas, but it just shows the CSV file as a table. No idea how to make the table header editable. Via Active questions tagged javascript - Stack Overflow https://ift.tt/JzPBnYy