StackOverflow.com

VN:F [1.9.22_1171]
Rating: 8.5/10 (13 votes cast)

Random snippets of all sorts of code, mixed with a selection of help and advice.

PyTorch SRGAN Training Extremely Slow on CPU for Image Super-Resolution – How to Optimize?

20 April 2026 @ 5:55 pm

I am working on the Plant Leaves Super Resolution challenge using PyTorch. I built an SRGAN-based model with Generator and Discriminator networks for image super-resolution. The model takes low-resolution plant leaf images and generates high-resolution outputs. During training, the process is taking too much time because I am running it on CPU instead of GPU. Each epoch is very slow due to Generator, Discriminator, and perceptual loss computations. I am using mixed precision and optimization techniques, but CPU performance is still slow. I want to know how to reduce training time and optimize this code for CPU execution. Suggestions for improving speed, reducing epochs, or simplifying the model would be helpful. Code: best_loss = float('inf') for epoch in range(1, NUM_EPOCHS + 1): G.train(); D.train() g_losses, d_losses = [], [] for lr_img, hr_img in train_dl:

compiler_depend.make:4: *** multiple target patterns. Stop. (Windows Path issue while using cmake)

20 April 2026 @ 5:49 pm

I'm writing C code on a windows machine, this is my setup: MSYS with the UCRT64 environment. VSCode CMake to build with "Unix Makefiles" generator Project directory looks like this: .vscode build scripts src/lib CMakeLists.txt Variables.cmake root CMakeLists.txt # SPDX-License-Identifier: Unlicense # Author: Derrick Lyndon Pallas <[email protected]> cmake_minimum_required(VERSION 3.10) set(PROJECT hangman ) project(${PROJECT} LANGUAGES C VERSION 1.0.0 DESCRIPTION "Fun hangman game") # Get CFILES, HFILES, CFILES, HFILES, RCFILES variables include("${CMAKE_CURRENT_SOURCE_DIR}/Variables.cmake") #get internal library add_subdirectory(src/lib) add_executable(${PROJECT} ${CFILES} ${HFILES}) target_link_libraries(${PROJECT} PUBLIC libhangman) target_include_directories(${PROJECT} PRIVATE src/lib/include) //Vari

Trying to understand instruction cache (for repeated Jit compilation reusing memory pages)

20 April 2026 @ 5:44 pm

I am playing with jit compilation on a Raspberry Pi 5 (aarch64) using linux. My goal is to generate native code, execute it, then continue generating more native code and execute that (which might or might not called previously generated native code). My first approach is to append new code to a single memory-page: Allocate a memory page with mmap Copy the code to that page with memcpy Make it executable with mprotect Execute it Make it writable with mprotect Append new code to that page with memcpy Make it executable with mprotect Execute the newly copied instructions <-- Here the process crashes My educated[1] guess is, that the instruction cache of a CPU does not seem to get updated and the CPU tries to execute the old zero-filled content of that part of the cache. According

How to have one element always be right above a chosen other element

20 April 2026 @ 5:20 pm

I'm working on a calendar for a project where, when a chosen event is clicked, a pop-up box is supposed to appear right above the clicked element. I originally tried to do it where it works based on the position of the physical element the user clicked, but it's inconsistent and unresponsive, so it is always off to one side (the attached image will give you an idea of what I mean. Also, ignore the weird formatting of the text in the popup; I got rid of some text for the sake of anonymity). What I'm wondering is if there is a way for me to have it just always be displayed above the yellow event relative to that event so that no matter the page size, it always pops up there. Here's the code I used to try and make it so the pop-up box with the text in it is just always above the yellow box that is on the calendar (the one over the 13 in the calendar itself, not the one at the bottom). const Cal = () => { const [popupBoxVis

unrelated element affected by another's hover

20 April 2026 @ 5:19 pm

When hovering over the nav links at the top, an underline effect is animated (through transition). During that brief 0.2s transition, the pink text "ABC" in the lower corner of the cards appear to momentarily reduce the font weight. If I remove the box-shadow from the card class, the visual glitch goes away. This happens in chrome and Edge, but not Firefox. So I'm thinking some kind of chromium rendering bug. While not game-breaking, it is an unwanted side-effect. Does anyone have any insight or solution? edit: The visual bug was apparent in the code preview on this page, but viewing it embedded it doesn't happen. So here's a fiddle just in case: https://jsfiddle.net/yjf80Lrv/

Python ast.literal_eval: raw strings recommended?

20 April 2026 @ 5:08 pm

If I do something like >>>import ast >>>testinput = "\S" >>>something = ast.literal_eval('"'+testinput+'"') Warning (from warnings module): File "<unknown>", line 1 SyntaxWarning: invalid escape sequence '\S' >>>something = ast.literal_eval('r"'+testinput+'"') >>>print(something) \S Is it therefore recommended or necessary (or safe?) always to use raw strings?

Would This be correct my Teacher said we could only use her solution but here is mine

20 April 2026 @ 4:40 pm

namespace ViewModel { public class VMMannschaft : INotifyPropertyChanged { private Mannschaft mannschaft; public VMMannschaft(string nation) { mannschaft = new Mannschaft(nation); } public string Nation { get =\\\> mannschaft.Nation; } public int Spiele { get =\\\> mannschaft.Spiele; } public int Punkte { get =\\\> mannschaft.Punkte; } public void Sieg() { mannschaft.Sieg(); OnPropertyChanged("Punkte"); OnPropertyChanged("Spiele"); } public void Niederlage() { mannschaft.Niederlage(); OnPropertyChanged("Punkte"); OnPropertyChanged("Spiele"); } public void Unentschieden() { mannschaft.Unentschieden(); OnPropertyChanged("Punkte"); OnPropertyChanged("Spiele");

Nested implicit lifetime type of implicit lifetime type not created: clang bug?

20 April 2026 @ 1:16 pm

This question is a follow up of Making the non-trivial creation of an array constexpr and Accessing objects of implicit lifetime type in the storage provided by std::allocator, before any explicit construction where I was looking for a way to create a constexpr array of not default-constructible types. The solution, hinted by the answer of the first question, is to use std::allocator::allocate, which is constexpr. The second question deals with the fact that this function does not create objects but arrays of objects. Yet I concluded when creating arrays of std::array, the latest were implicitly created as being implicit lifetime type subobjects of implicit lifetime type

Django Order by based on field in unrelated model

20 April 2026 @ 1:04 pm

I have two models in my Django Project. The first one is UserProfile and the second one is Interests: class UserProfile(models.Model): user_model_for_profile = models.ForeignKey(CustomUser, on_delete=models.CASCADE) first_name = models.CharField(max_length = 25) middle_name = models.CharField(max_length = 25) last_name = models.CharField(max_length= 50) gender = models.CharField(choices = gender_choices, max_length = 30) profile_created_by = models.CharField(choices = profile_creation_choices, max_length = 30) date_of_birth = models.DateField() time_of_birth = models.TimeField() Height = models.IntegerField() #Day of birth needed? Country_of_birth = models.CharField(choices = Countries_choices, max_length = 30) State_of_birth = models.CharField(choices = State_choices, max_length = 40) City_of_birth = models.CharField(max_length = 30) Mobile_number = models.CharField( max_length=10, # Adjust based on you

Discriminated Unions and converting types

20 April 2026 @ 12:56 pm

I have a function that is used to change the type of an API input (simple dummy example given): interface BaseInput { version: '3' | '4'; } interface InputA extends BaseInput{ version: '4'; foo: string; } interface InputB extends BaseInput{ version: '3'; bar: string; } const convert3to4 = (apiBodyInput: InputB) => { return { version: '4', foo: apiBodyInput.bar } as InputA; }; const convert4to3 = (apiBodyInput: InputA) => { return { version: '3', bar: apiBodyInput.foo } as InputB; }; // adapted from https://dev.to/maikelev/discriminated-unions-in-typescript-5fia#exhaustiveness-checking function assertNever(version: never): never { throw new Error(`Unrecognised api version: ${version}`); } export const changeApiVersion = (apiBodyInput: InputA | InputB, targetVersion: '3' | '4') => { if(apiBodyInput.version !== '3' && apiBodyInput.version !== '4'){ return assertNever(apiBodyInput) } sw