import cv2 import numpy as np from matplotlib import pyplot as plt img = cv2 . imread ( 'messi5.jpg' , 0 ) f = np . fft . fft2 ( img ) fshift = np . fft . fftshift ( f ) magnitude_spectrum = 20 * np . log ( np . abs ( fshift )) plt . subplot ( 121 ), plt . imshow ( img , cmap = 'gray' ) plt . title ( 'Input Image' ), plt . xticks ([]), plt . yticks ([]) plt . subplot ( 122 ), plt . imshow ( magnitude_spectrum , cmap = 'gray' ) plt . title ( 'Magnitude Spectrum' ), plt . xticks ([]), plt . yticks ([]) plt . show () rows , cols = img . shape crow , ccol = rows / 2 , cols / 2 fshift [ crow - 30 : crow + 30 , ccol - 30 : ccol + 30 ] = 0 f_ishift = np . fft . ifftshift ( fshift ) img_back = np . fft . ifft2 ( f_ishift ) img_back = np . abs ( img_back ) plt . subplot ( 131 ), plt . imshow ( img , cmap = 'gray' ) plt . title ( 'Input Image' ), plt . xticks ([]), ...
# load data
답글삭제X <- read.table("mydata.csv", sep = ",")
# create and plot RoC curve
library(ROCR)
roc <- ROCR::performance(ROCR::prediction(X[,2], X[,1]), "tpr", "fpr")
plot(roc)
#!/usr/bin/python
답글삭제import os
import re
from scipy import ndimage, misc
import torch
import torch.nn as nn
#from __future__ import print_function
import argparse
from PIL import Image
import torchvision.models as models
import skimage.io
from torch.autograd import Variable as V
from torch.nn import functional as f
from torchvision import transforms as trn
# define image transformation
centre_crop = trn.Compose([
trn.ToPILImage(),
trn.Scale(256),
trn.CenterCrop(224),
trn.ToTensor(),
trn.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
])
images = []
for root, dirnames, filenames in os.walk("/Users/dti/Desktop/test_png170906/benign/"):
for filename in filenames: # for all files
if re.search("\.(jpg|jpeg|png)$", filename):
filepath = os.path.join(root, filename) # path + filename
print(filepath)
#image = ndimage.imread(filepath, mode="L") # image read
img = skimage.io.imread(filepath)
#image_resized = misc.imresize(image, (256, 256)) #resize
x = V(centre_crop(img).unsqueeze(0), volatile=True).cuda()
model = models.__dict__['resnet34']()
model = torch.nn.DataParallel(model).cuda()
model = torch.load('modelFT_BM60.pth')
logit = model(x)
#print(logit)
h_x = f.softmax(logit).data.squeeze()
f1= open('rocdata.txt', 'a')
f1.write("1" + str(h_x[0]) + "\n")
f1.close()
images2 = []
for root, dirnames, filenames in os.walk("/Users/dti/Desktop/test_png170906/malware/"):
for filename in filenames: # for all files
if re.search("\.(jpg|jpeg|png)$", filename):
filepath = os.path.join(root, filename) # path + filename
print(filepath)
#image = ndimage.imread(filepath, mode="L") # image read
img = skimage.io.imread(filepath)
#image_resized = misc.imresize(image, (256, 256)) #resize
x = V(centre_crop(img).unsqueeze(0), volatile=True).cuda()
model = models.__dict__['resnet34']()
model = torch.nn.DataParallel(model).cuda()
model = torch.load('modelFT_BM60.pth')
logit = model(x)
#print(logit)
h_x = f.softmax(logit).data.squeeze()
f1= open('rocdata.txt', 'a')
f1.write("0" + str(h_x[1]) + "\n")
f1.close()
#filename=r'/home/kerb/Documents/data_bm_0913/test/benign/raw7697.exe3.png'
#img = skimage.io.imread(filename)