Git Product home page Git Product logo

3dcnn-with-keras's People

Contributors

paolo626 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

3dcnn-with-keras's Issues

No Metrics For Model

Hi Liupeng678,

I got your model to run and now that it is successful I am trying to plug in the confusion matrix to attain the true metrics for the model's performance!

This is my final analysis to determine the efficiency of your works

Can you assist me, please?

Errors With The Model 2dcnn and 3dcnn

Hi Liupeng,

I tried reaching out to you via your email but no luck in catching your attention!!

I have been receiving these errors for which I cannot seem to evade as this is challenging my understanding!

I really would like to solve this as your code is very interesting! Can you help me solve this, please?

I googled and saw this response but when I tried implementing this, it is still futile!
https://stackoverflow.com/questions/45645276/negative-dimension-size-caused-by-subtracting-3-from-1-for-conv2d-2-convolution

WHAT I TRIED:
'''
expects the input to be in the format (samples, rows, cols, channels), which is "channels-last". Your data seems to be in the format (samples, channels, rows, cols). You should be able to fix this using the optional keyword data_format = 'channels_first' when declaring the Convolution2D layer

model.add(Convolution2D(32, (3, 3), activation='relu', input_shape=(1,28,28), data_format='channels_first'))

They also mention removing some of the convolution layers but I think in my limited knowledge that this will have an adverse effect on the accuracy and metrics!???!?! I could be wrong here! Please assist? Something seems off with the Max Pooling Layer
'''

My ERRORS:
ValueError: Negative dimension size caused by subtracting 3 from 1 for '{{node conv3d_2/Conv3D}} = Conv3D[T=DT_FLOAT, data_format="NDHWC", dilations=[1, 1, 1, 1, 1], padding="VALID", strides=[1, 1, 1, 1, 1]](Placeholder, conv3d_2/Conv3D/ReadVariableOp)' with input shapes: [?,9,9,1,32], [3,3,3,32,64].

pritning the output results

Hey @liupeng678,

thanx for the code pal and I gave you a well deserved star! i manipulated the code and was wondering how did you print out the results via the graph?

If the print configuration is located in the 3dccn.py file at the bottom, well I am not sure why I am experiencing an error!!
I see the configurations but for some odd reason the graph details is not being printed to demosntrate the output's results!

I ran this file configuration as well and I am certain the fault is mine own!??!!
Can you help me understand my errors so that I can understand the structure of the output, please?

CODE
'''
import argparse
import os
import matplotlib
matplotlib.use('AGG')
import matplotlib.pyplot as plt
import numpy as np
from keras.datasets import cifar10
from keras.layers import (Activation, Conv3D, Dense, Dropout, Flatten, MaxPooling3D)
from keras.layers.advanced_activations import LeakyReLU
from keras.losses import categorical_crossentropy
from keras.models import Sequential
from keras.optimizers import Adam
from keras.utils import np_utils
from keras.utils.vis_utils import plot_model
from sklearn.model_selection import train_test_split

import videoto3d
from tqdm import tqdm

def plot_history(history, result_dir):
plt.plot(history.history['accuracy'], marker='.')
plt.plot(history.history['val_accuracy'], marker='.')
plt.title('model accuracy')
plt.xlabel('epoch')
plt.ylabel('accuracy')
plt.grid()
plt.legend(['acc', 'val_acc'], loc='lower right')
plt.savefig(os.path.join(result_dir, 'model_accuracy.png'))
plt.close()

plt.plot(history.history['loss'], marker='.')
plt.plot(history.history['val_loss'], marker='.')
plt.title('model loss')
plt.xlabel('epoch')
plt.ylabel('loss')
plt.grid()
plt.legend(['loss', 'val_loss'], loc='upper right')
plt.savefig(os.path.join(result_dir, 'model_loss.png'))
plt.close()

def save_history(history, result_dir):
loss = history.history['loss']
acc = history.history['accuracy']
val_loss = history.history['val_loss']
val_acc = history.history['val_accuracy']
nb_epoch = len(acc)

with open(os.path.join(result_dir, 'result.txt'), 'w') as fp:
    fp.write('epoch\tloss\tacc\tval_loss\tval_acc\n')
    for i in range(nb_epoch):
        fp.write('{}\t{}\t{}\t{}\t{}\n'.format(
            i, loss[i], acc[i], val_loss[i], val_acc[i]))

def loaddata(video_dir, vid3d, nclass, result_dir, color=False, skip=True):
files = os.listdir(video_dir)

X = []
labels = []
labellist = []

pbar = tqdm(total=len(files))

for filename in files:
    print(filename)
    pbar.update(1)
    if filename == '.DS_Store':
        continue
    namelist = os.path.join(video_dir, filename)
    files2 = os.listdir(namelist)
    for  files3 in  files2:
        name = os.path.join(namelist,files3)
        #print("ok")
        print("dir is ",name)
        label = vid3d.get_UCF_classname(filename)
        if label not in labellist:
            if len(labellist) >= nclass:
                continue
            labellist.append(label)
        labels.append(label)
    
        X.append(vid3d.video3d(name, color=color, skip=skip))

pbar.close()
with open(os.path.join(result_dir, 'classes.txt'), 'w') as fp:
    for i in range(len(labellist)):
        fp.write('{}\n'.format(labellist[i]))

for num, label in enumerate(labellist):
    for i in range(len(labels)):
        if label == labels[i]:
            labels[i] = num
if color:
    return np.array(X).transpose((0, 2, 3, 4, 1)), labels
else:
    return np.array(X).transpose((0, 2, 3, 1)), labels

def main():
parser = argparse.ArgumentParser(
description='simple 3D convolution for action recognition')
parser.add_argument('--batch', type=int, default=128)
parser.add_argument('--epoch', type=int, default=100)
parser.add_argument('--videos', type=str, default='UCF101',
help='directory where videos are stored')
parser.add_argument('--nclass', type=int, default=101)
parser.add_argument('--output', type=str, required=True)
parser.add_argument('--color', type=bool, default=False)
parser.add_argument('--skip', type=bool, default=True)
parser.add_argument('--depth', type=int, default=10)
args = parser.parse_args()

img_rows, img_cols, frames = 32, 32, args.depth
channel = 3 if args.color else 1
fname_npz = 'dataset_{}_{}_{}.npz'.format(
    args.nclass, args.depth, args.skip)

vid3d = videoto3d.Videoto3D(img_rows, img_cols, frames)
nb_classes = args.nclass
if os.path.exists(fname_npz):
    loadeddata = np.load(fname_npz)
    X, Y = loadeddata["X"], loadeddata["Y"]
else:
    x, y = loaddata(args.videos, vid3d, args.nclass,
                    args.output, args.color, args.skip)
    X = x.reshape((x.shape[0], img_rows, img_cols, frames, channel))
    Y = np_utils.to_categorical(y, nb_classes)

    X = X.astype('float32')
    np.savez(fname_npz, X=X, Y=Y)
    print('Saved dataset to dataset.npz.')
print('X_shape:{}\nY_shape:{}'.format(X.shape, Y.shape))

# Define model
model = Sequential()
model.add(Conv3D(32, kernel_size=(3, 3, 3), input_shape=(
    X.shape[1:]), padding='same'))
model.add(Activation('relu'))
model.add(Conv3D(32, kernel_size=(3, 3, 3), padding='same'))
model.add(Activation('softmax'))
model.add(MaxPooling3D(pool_size=(3, 3, 3), padding='same'))
model.add(Dropout(0.25))

model.add(Conv3D(64, kernel_size=(3, 3, 3), padding='same'))
model.add(Activation('relu'))
model.add(Conv3D(64, kernel_size=(3, 3, 3), padding='same'))
model.add(Activation('softmax'))
model.add(MaxPooling3D(pool_size=(3, 3, 3), padding='same'))
model.add(Dropout(0.25))

model.add(Flatten())
model.add(Dense(512, activation='sigmoid'))
model.add(Dropout(0.5))
model.add(Dense(nb_classes, activation='softmax'))

model.compile(loss=categorical_crossentropy,
              optimizer=Adam(), metrics=['accuracy'])
model.summary()
plot_model(model, show_shapes=True,
           to_file=os.path.join(args.output, 'model.png'))

X_train, X_test, Y_train, Y_test = train_test_split(
    X, Y, test_size=0.2, random_state=43)

history = model.fit(X_train, Y_train, validation_data=(X_test, Y_test), batch_size=args.batch,
                    epochs=args.epoch, verbose=1, shuffle=True)
model.evaluate(X_test, Y_test, verbose=0)
model_json = model.to_json()
if not os.path.isdir(args.output):
    os.makedirs(args.output)
with open(os.path.join(args.output, 'ucf101_3dcnnmodel.json'), 'w') as json_file:
    json_file.write(model_json)
model.save_weights(os.path.join(args.output, 'ucf101_3dcnnmodel.hd5'))

**loss, acc = model.evaluate(X_test, Y_test, verbose=1)
print('Test loss:', loss)
print('Test accuracy:', acc)
print(history.history.keys())
plot_history(history, args.output)
save_history(history, args.output)**

if name == 'main':
main()

'''
ERROR
'''
usage: 3dcnn.py [-h] [--batch BATCH] [--epoch EPOCH] [--videos VIDEOS]
[--nclass NCLASS] --output OUTPUT [--color COLOR]
[--skip SKIP] [--depth DEPTH]
3dcnn.py: error: the following arguments are required: --output
An exception has occurred, use %tb to see the full traceback.
'''

can you assist me, please?

Thanx in advance and great job on this code! it was very useful!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.