function res = IAS_driver_replace(num_trials,kernels,H)
%

rng('default');

for t = 1:num_trials
    [net,a,imdsValidation] = IAS_CNN_digits(H);
    res(t).net = net;
    res(t).a = a;
    W = IAS_extract_weights(net,2);
    Wr = 0*W;
    Wr = IAS_K2W(fliplr(kernels(3).kernel),Wr,1);
    Wr = IAS_K2W(flipud(fliplr(kernels(3).kernel)),Wr,2);
    Wr = IAS_K2W(kernels(1).kernel,Wr,3);
    Wr = IAS_K2W(flipud(kernels(1).kernel),Wr,4);
    % for k = 1:4
    %     K = IAS_W2K(W,k);
    %     [m,mW] = IAS_match_kernel(K,kernels);
    %     mK = IAS_map(K,m);
    %     res(t).match(k).K = K;
    %     res(t).match(k).m = mK;
    %     res(t).match(k).mW = mW;
    %     m1 = IAS_map(K,m);
    %     Wr = IAS_K2W(m1,Wr,k);
    % end
    res(t).W = W;
    res(t).Wr = Wr;
    netr = IAS_replace_weights(net,Wr);
    YPred = classify(netr,imdsValidation);
    YValidation = imdsValidation.Labels;
    ar = sum(YPred == YValidation)/numel(YValidation);
    res(t).netr = netr;
    res(t).ar = ar;
end

tch = 0;
