from ._nnls import nnls ImportError: DLL load failed: The specified module could not be found
While running a UNet traning code I found DLL load failed error. Here is the code:
'''
     import torch
     import scipy
   import albumentations as A
  from ._nnls import nnls
  from albumentations.pytorch import ToTensorV2
  from tqdm import tqdm
  import torch.nn as nn
 import torch.optim as optim
 from unet_model import UNet
 from utilscar import (
load_checkpoint,
save_checkpoint,
get_loaders,
check_accuracy,
save_predictions_as_imgs,
)

  # Hyperparameters etc.
LEARNING_RATE = 1e-4
DEVICE = &quot;cuda&quot; if torch.cuda.is_available() else &quot;cpu&quot;
BATCH_SIZE = 16
NUM_EPOCHS = 3
NUM_WORKERS = 2
IMAGE_HEIGHT = 160  # 1280 originally
IMAGE_WIDTH = 240  # 1918 originally
PIN_MEMORY = True
LOAD_MODEL = False
TRAIN_IMG_DIR = &quot;Dataset/train_images/&quot;
TRAIN_MASK_DIR = &quot;Dataset/train_masks/&quot;
VAL_IMG_DIR = &quot;Dataset/val_images/&quot;
VAL_MASK_DIR = &quot;Dataset/val_masks/&quot;

def train_fn(loader, model, optimizer, loss_fn, scaler):
loop = tqdm(loader)

for batch_idx, (data, targets) in enumerate(loop):
    data = data.to(device=DEVICE)
    targets = targets.float().unsqueeze(1).to(device=DEVICE)

    # forward
    with torch.cuda.amp.autocast():
        predictions = model(data)
        loss = loss_fn(predictions, targets)

    # backward
    optimizer.zero_grad()
    scaler.scale(loss).backward()
    scaler.step(optimizer)
    scaler.update()

    # update tqdm loop
    loop.set_postfix(loss=loss.item())


def main():
   train_transform = A.Compose(
    [
        A.Resize(height=IMAGE_HEIGHT, width=IMAGE_WIDTH),
        A.Rotate(limit=35, p=1.0),
        A.HorizontalFlip(p=0.5),
        A.VerticalFlip(p=0.1),
        A.Normalize(
            mean=[0.0, 0.0, 0.0],
            std=[1.0, 1.0, 1.0],
            max_pixel_value=255.0,
        ),
        ToTensorV2(),
    ],
)

val_transform = A.Compose(
    [
        A.Resize(height=IMAGE_HEIGHT, width=IMAGE_WIDTH),
        A.Normalize(
            mean=[0.0, 0.0, 0.0],
            std=[1.0, 1.0, 1.0],
            max_pixel_value=255.0,
        ),
        ToTensorV2(),
    ],
)

model = UNet(in_channels=3, out_channels=1).to(DEVICE)
loss_fn = nn.BCEWithLogitsLoss()
optimizer = optim.Adam(model.parameters(), lr=LEARNING_RATE)

train_loader, val_loader = get_loaders(
    TRAIN_IMG_DIR,
    TRAIN_MASK_DIR,
    VAL_IMG_DIR,
    VAL_MASK_DIR,
    BATCH_SIZE,
    train_transform,
    val_transform,
    NUM_WORKERS,
    PIN_MEMORY,
)

if LOAD_MODEL:
    load_checkpoint(torch.load(&quot;my_checkpoint.pth.tar&quot;), model)


check_accuracy(val_loader, model, device=DEVICE)
scaler = torch.cuda.amp.GradScaler()

for epoch in range(NUM_EPOCHS):
    train_fn(train_loader, model, optimizer, loss_fn, scaler)

    # save model
    checkpoint = {
        &quot;state_dict&quot;: model.state_dict(),
        &quot;optimizer&quot;:optimizer.state_dict(),
    }
    save_checkpoint(checkpoint)

    # check accuracy
    check_accuracy(val_loader, model, device=DEVICE)

    # print some examples to a folder
    save_predictions_as_imgs(
        val_loader, model, folder=&quot;saved_images/&quot;, device=DEVICE
    )


   if __name__ == &quot;__main__&quot;:
   main()

'''
I found this error:
from ._nnls import nnls
ImportError: DLL load failed: The specified module could not be found.
Here I want to mention that, my python is 64 bit and all the libraries are also in 64 bit. I updated everything using conda update.

The below solution worked for me.

conda remove --force numpy, scipy


pip install -U numpy, scipy

Successfully installed numpy-1.19.5 scipy-1.5.4
Reference: https://github.com/conda/conda/issues/6396#issuecomment-350254762
